From 0c9f6c6a272b23277124d8e5995086a7a70c5380 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 4 May 2020 10:20:45 -0400 Subject: [PATCH] Make std_cxx20::ranges::iota_view compatible with std::ranges::iota_view --- examples/step-69/step-69.cc | 58 ++++++++++++++-------- include/deal.II/base/geometry_info.h | 12 ++--- include/deal.II/base/std_cxx20/iota_view.h | 14 ++++-- include/deal.II/fe/fe_values.h | 6 +-- 4 files changed, 57 insertions(+), 33 deletions(-) diff --git a/examples/step-69/step-69.cc b/examples/step-69/step-69.cc index 5bf418310f..b2ebd869d2 100644 --- a/examples/step-69/step-69.cc +++ b/examples/step-69/step-69.cc @@ -1254,14 +1254,17 @@ namespace Step69 TimerOutput::Scope scope(computing_timer, "offline_data - compute |c_ij|, and n_ij"); - const std_cxx20::ranges::iota_view indices( + const std_cxx20::ranges::iota_view indices( 0, n_locally_relevant); const auto on_subranges = // - [&](std_cxx20::ranges::iota_view::iterator i1, - const std_cxx20::ranges::iota_view::iterator i2) { + [&]( + std_cxx20::ranges::iota_view::iterator i1, + const std_cxx20::ranges::iota_view::iterator i2) { for (const auto row_index : - std_cxx20::ranges::iota_view(*i1, *i2)) + std_cxx20::ranges::iota_view(*i1, + *i2)) { // First column-loop: we compute and store the entries of the // matrix norm_matrix and write normalized entries into the @@ -1863,10 +1866,10 @@ namespace Step69 const auto &n_locally_owned = offline_data->n_locally_owned; const auto &n_locally_relevant = offline_data->n_locally_relevant; - const std_cxx20::ranges::iota_view indices_owned( - 0, n_locally_owned); - const std_cxx20::ranges::iota_view indices_relevant( - 0, n_locally_relevant); + const std_cxx20::ranges::iota_view + indices_owned(0, n_locally_owned); + const std_cxx20::ranges::iota_view + indices_relevant(0, n_locally_relevant); const auto &sparsity = offline_data->sparsity_pattern; @@ -1920,10 +1923,13 @@ namespace Step69 "time_stepping - 1 compute d_ij"); const auto on_subranges = // - [&](std_cxx20::ranges::iota_view::iterator i1, - const std_cxx20::ranges::iota_view::iterator i2) { + [&]( + std_cxx20::ranges::iota_view::iterator i1, + const std_cxx20::ranges::iota_view::iterator i2) { for (const auto i : - std_cxx20::ranges::iota_view(*i1, *i2)) + std_cxx20::ranges::iota_view(*i1, + *i2)) { const auto U_i = gather(U, i); @@ -2016,12 +2022,15 @@ namespace Step69 // locally. const auto on_subranges = // - [&](std_cxx20::ranges::iota_view::iterator i1, - const std_cxx20::ranges::iota_view::iterator i2) { + [&]( + std_cxx20::ranges::iota_view::iterator i1, + const std_cxx20::ranges::iota_view::iterator i2) { double tau_max_on_subrange = std::numeric_limits::infinity(); for (const auto i : - std_cxx20::ranges::iota_view(*i1, *i2)) + std_cxx20::ranges::iota_view(*i1, + *i2)) { double d_sum = 0.; @@ -2102,8 +2111,10 @@ namespace Step69 "time_stepping - 3 perform update"); const auto on_subranges = - [&](std_cxx20::ranges::iota_view::iterator i1, - const std_cxx20::ranges::iota_view::iterator i2) { + [&]( + std_cxx20::ranges::iota_view::iterator i1, + const std_cxx20::ranges::iota_view::iterator i2) { for (const auto i : boost::make_iterator_range(i1, i2)) { Assert(i < n_locally_owned, ExcInternalError()); @@ -2341,7 +2352,8 @@ namespace Step69 const auto &n_locally_owned = offline_data->n_locally_owned; const auto indices = - std_cxx20::ranges::iota_view(0, n_locally_owned); + std_cxx20::ranges::iota_view(0, + n_locally_owned); // We define the r_i_max and r_i_min in the current MPI process as // atomic doubles in order to avoid race conditions between threads: @@ -2352,8 +2364,10 @@ namespace Step69 // global maxima and minima of the gradients. { const auto on_subranges = // - [&](std_cxx20::ranges::iota_view::iterator i1, - const std_cxx20::ranges::iota_view::iterator i2) { + [&]( + std_cxx20::ranges::iota_view::iterator i1, + const std_cxx20::ranges::iota_view::iterator i2) { double r_i_max_on_subrange = 0.; double r_i_min_on_subrange = std::numeric_limits::infinity(); @@ -2437,8 +2451,10 @@ namespace Step69 { const auto on_subranges = // - [&](std_cxx20::ranges::iota_view::iterator i1, - const std_cxx20::ranges::iota_view::iterator i2) { + [&]( + std_cxx20::ranges::iota_view::iterator i1, + const std_cxx20::ranges::iota_view::iterator i2) { for (const auto i : boost::make_iterator_range(i1, i2)) { Assert(i < n_locally_owned, ExcInternalError()); diff --git a/include/deal.II/base/geometry_info.h b/include/deal.II/base/geometry_info.h index d8ea7c5e4e..04f6646c5e 100644 --- a/include/deal.II/base/geometry_info.h +++ b/include/deal.II/base/geometry_info.h @@ -1946,7 +1946,7 @@ struct GeometryInfo * taking on all valid indices for faces (zero and one in 1d, zero * through three in 2d, and zero through 5 in 3d). */ - static std_cxx20::ranges::iota_view + static std_cxx20::ranges::iota_view face_indices(); /** @@ -1977,7 +1977,7 @@ struct GeometryInfo * Here, we are looping over all vertices of all cells, with `vertex_index` * taking on all valid indices. */ - static std_cxx20::ranges::iota_view + static std_cxx20::ranges::iota_view vertex_indices(); /** @@ -2832,19 +2832,19 @@ GeometryInfo<0>::vertex_indices() template -inline std_cxx20::ranges::iota_view +inline std_cxx20::ranges::iota_view GeometryInfo::face_indices() { - return std_cxx20::ranges::iota_view(0U, faces_per_cell); + return {0U, faces_per_cell}; } template -inline std_cxx20::ranges::iota_view +inline std_cxx20::ranges::iota_view GeometryInfo::vertex_indices() { - return std_cxx20::ranges::iota_view(0U, vertices_per_cell); + return {0U, vertices_per_cell}; } diff --git a/include/deal.II/base/std_cxx20/iota_view.h b/include/deal.II/base/std_cxx20/iota_view.h index 8c2b34606b..8c1e471943 100644 --- a/include/deal.II/base/std_cxx20/iota_view.h +++ b/include/deal.II/base/std_cxx20/iota_view.h @@ -17,8 +17,11 @@ #include -#include - +#if defined __cpp_lib_ranges && __cpp_lib_ranges >= 201911 +# include +#else +# include +#endif DEAL_II_NAMESPACE_OPEN @@ -26,6 +29,10 @@ namespace std_cxx20 { namespace ranges { +#if defined __cpp_lib_ranges && __cpp_lib_ranges >= 201911 + template + using iota_view = std::ranges::iota_view; +#else /** * A poor-man's implementation of std::ranges::iota_view using * boost's integer_range class. The two classes are not completely @@ -38,8 +45,9 @@ namespace std_cxx20 * class can be found at * https://en.cppreference.com/w/cpp/ranges/iota_view . */ - template + template using iota_view = boost::integer_range; +#endif } // namespace ranges } // namespace std_cxx20 diff --git a/include/deal.II/fe/fe_values.h b/include/deal.II/fe/fe_values.h index 59aa92b46c..109a2c036a 100644 --- a/include/deal.II/fe/fe_values.h +++ b/include/deal.II/fe/fe_values.h @@ -3030,7 +3030,7 @@ public: * `q_point` taking on all valid indices for quadrature points, as defined * by the quadrature rule passed to `fe_values`. */ - std_cxx20::ranges::iota_view + std_cxx20::ranges::iota_view quadrature_point_indices() const; /** @@ -5561,10 +5561,10 @@ FEValuesBase::dof_indices_ending_at( template -inline std_cxx20::ranges::iota_view +inline std_cxx20::ranges::iota_view FEValuesBase::quadrature_point_indices() const { - return std_cxx20::ranges::iota_view(0U, n_quadrature_points); + return {0U, n_quadrature_points}; } -- 2.39.5