Skip to content

Add structured binding to quadrature points

I would like to save a few keystrokes when getting the position and weight out of the quadrature points by using structured bindings. With this MR we can write

auto f = [](auto x) -> double {/*...*/}; // function to integrate

auto quadrature = Dune::QuadratureRules</*...*/>::rule(/*...*/);
double integral{0};

// before this MR
for(auto point : quadrature)
  integral += f(point.position()) * point.weight();

// after this MR
for(auto [position, weight] : quadrature)
  integral += f(position) * weight;

Notice that this implementation specializes std::tuple_size and std::tuple_element. One may argue that is easier to make the fields local and weight_ public to get automatic structured binding, but the names are a bit ugly to be in a public interface and they cannot be modified because they are protected rather than private.

  • Add Changelog
Edited by Santiago Ospina De Los Ríos

Merge request reports