From: Daniel Arndt Date: Sat, 1 Jul 2023 18:10:13 +0000 (-0400) Subject: Clean up DEAL_II_CONSTEXPR_IN_CONDITIONAL X-Git-Tag: relicensing~797^2~6 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cec97e7c66c1c63434473259506c171f574423b;p=dealii.git Clean up DEAL_II_CONSTEXPR_IN_CONDITIONAL --- diff --git a/include/deal.II/base/config.h.in b/include/deal.II/base/config.h.in index 98ab0768ab..b5da2f1856 100644 --- a/include/deal.II/base/config.h.in +++ b/include/deal.II/base/config.h.in @@ -564,19 +564,6 @@ _Pragma("GCC diagnostic pop") #define DEAL_II_WARNING(desc) DEAL_II_DO_PRAGMA(message(#desc)) #endif -/*********************************************************************** - * Some places in deal.II require or benefit from using "if constexpr". - * However, this feature is only available in C++17 and above. - * The macro defined here can be used so that - * "if DEAL_II_CONSTEXPR_IN_CONDITIONAL (...)" expands to "if constexpr(...)" - * when C++17 is supported and to "if (...)" otherwise. - */ -#ifdef DEAL_II_HAVE_CXX17 - #define DEAL_II_CONSTEXPR_IN_CONDITIONAL constexpr -#else - #define DEAL_II_CONSTEXPR_IN_CONDITIONAL -#endif - /*********************************************************************** * Final inclusions: diff --git a/include/deal.II/base/partitioner.templates.h b/include/deal.II/base/partitioner.templates.h index a048d75ba0..1edc4b2b3a 100644 --- a/include/deal.II/base/partitioner.templates.h +++ b/include/deal.II/base/partitioner.templates.h @@ -119,9 +119,8 @@ namespace Utilities for (unsigned int i = 0; i < n_import_targets; ++i) { # if defined(DEAL_II_MPI_WITH_DEVICE_SUPPORT) - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (std::is_same< - MemorySpaceType, - MemorySpace::Default>::value) + if constexpr (std::is_same::value) { const auto chunk_size = import_indices_plain_dev[i].size(); using IndexType = decltype(chunk_size); @@ -219,8 +218,8 @@ namespace Utilities { const unsigned int chunk_size = ghost_range.second - ghost_range.first; - if DEAL_II_CONSTEXPR_IN_CONDITIONAL ( - std::is_same::value) + if constexpr (std::is_same::value) { // If source and destination are overlapping, we must be // careful to use an appropriate copy function. @@ -391,8 +390,8 @@ namespace Utilities if (ghost_array_ptr + offset != ghost_array.data() + my_ghosts->first) { - if DEAL_II_CONSTEXPR_IN_CONDITIONAL ( - std::is_same::value) + if constexpr (std::is_same::value) { if (offset > my_ghosts->first) std::copy_backward(ghost_array.data() + @@ -597,9 +596,8 @@ namespace Utilities const Number *read_position = temporary_storage.data(); # if defined(DEAL_II_MPI_WITH_DEVICE_SUPPORT) - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (std::is_same< - MemorySpaceType, - MemorySpace::Default>::value) + if constexpr (std::is_same::value) { if (vector_operation == VectorOperation::add) { @@ -777,9 +775,8 @@ namespace Utilities Assert(ghost_array.begin() != nullptr, ExcInternalError()); # if defined(DEAL_II_MPI_WITH_DEVICE_SUPPORT) - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (std::is_same< - MemorySpaceType, - MemorySpace::Default>::value) + if constexpr (std::is_same::value) { Kokkos::deep_copy( Kokkos::View( @@ -789,8 +786,7 @@ namespace Utilities else # endif { - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (std::is_trivial< - Number>::value) + if constexpr (std::is_trivial::value) { std::memset(ghost_array.data(), 0, diff --git a/include/deal.II/base/utilities.h b/include/deal.II/base/utilities.h index 6f2f1ae2a6..35a7ea24f6 100644 --- a/include/deal.II/base/utilities.h +++ b/include/deal.II/base/utilities.h @@ -1358,8 +1358,7 @@ namespace Utilities // see if the object is small and copyable via memcpy. if so, use // this fast path. otherwise, we have to go through the BOOST // serialization machinery - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (std::is_trivially_copyable() && - sizeof(T) < 256) + if constexpr (std::is_trivially_copyable() && sizeof(T) < 256) { // Determine the size. There are places where we would like to use a // truly empty type, for which we use std::tuple<> (i.e., a tuple @@ -1442,8 +1441,7 @@ namespace Utilities // see if the object is small and copyable via memcpy. if so, use // this fast path. otherwise, we have to go through the BOOST // serialization machinery - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (std::is_trivially_copyable() && - sizeof(T) < 256) + if constexpr (std::is_trivially_copyable() && sizeof(T) < 256) { // Determine the size. There are places where we would like to use a // truly empty type, for which we use std::tuple<> (i.e., a tuple @@ -1523,8 +1521,7 @@ namespace Utilities // see if the object is small and copyable via memcpy. if so, use // this fast path. otherwise, we have to go through the BOOST // serialization machinery - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (std::is_trivially_copyable() && - sizeof(T) * N < 256) + if constexpr (std::is_trivially_copyable() && sizeof(T) * N < 256) { Assert(std::distance(cbegin, cend) == sizeof(T) * N, ExcInternalError()); diff --git a/include/deal.II/lac/sparse_matrix.templates.h b/include/deal.II/lac/sparse_matrix.templates.h index a58d4667f5..60662d2b59 100644 --- a/include/deal.II/lac/sparse_matrix.templates.h +++ b/include/deal.II/lac/sparse_matrix.templates.h @@ -219,7 +219,7 @@ SparseMatrix::operator=(const double d) grain_size); else if (matrix_size > 0) { - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (std::is_trivial::value) + if constexpr (std::is_trivial::value) std::memset(val.get(), 0, matrix_size * sizeof(number)); else std::fill(val.get(), val.get() + matrix_size, 0); diff --git a/include/deal.II/lac/vector_operations_internal.h b/include/deal.II/lac/vector_operations_internal.h index e9788674b9..47c90bde0a 100644 --- a/include/deal.II/lac/vector_operations_internal.h +++ b/include/deal.II/lac/vector_operations_internal.h @@ -212,7 +212,7 @@ namespace internal if (value == Number()) { - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (std::is_trivial::value) + if constexpr (std::is_trivial::value) { std::memset(dst + begin, 0, sizeof(Number) * (end - begin)); return; @@ -241,10 +241,8 @@ namespace internal { Assert(end >= begin, ExcInternalError()); - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (std::is_trivially_copyable< - Number>() && - std::is_same::value) + if constexpr (std::is_trivially_copyable() && + std::is_same::value) std::memcpy(dst + begin, src + begin, (end - begin) * sizeof(Number)); else { diff --git a/source/base/geometric_utilities.cc b/source/base/geometric_utilities.cc index 5455f32d9c..ee041f2581 100644 --- a/source/base/geometric_utilities.cc +++ b/source/base/geometric_utilities.cc @@ -50,7 +50,7 @@ namespace GeometricUtilities Assert(dim > 1, ExcNotImplemented()); // radius - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (dim > 1) + if constexpr (dim > 1) { scoord[0] = position.norm(); // azimuth angle \theta: @@ -61,7 +61,7 @@ namespace GeometricUtilities } // polar angle \phi: - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (dim == 3) + if constexpr (dim == 3) { // acos returns the angle in the range [0,\pi] if (scoord[0] > std::numeric_limits::min()) diff --git a/source/base/polynomials_rt_bubbles.cc b/source/base/polynomials_rt_bubbles.cc index 104b380a09..367040222c 100644 --- a/source/base/polynomials_rt_bubbles.cc +++ b/source/base/polynomials_rt_bubbles.cc @@ -109,14 +109,14 @@ PolynomialsRT_Bubbles::evaluate( double monoval_i[dim][n_derivatives + 1]; - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (dim <= 1) + if constexpr (dim <= 1) { (void)monoval_plus; (void)monoval_i; } unsigned int start = n_sub; - if DEAL_II_CONSTEXPR_IN_CONDITIONAL (dim == 2) + if constexpr (dim == 2) { // In 2d the curl part of the space is spanned by the vectors // of two types. The first one is @@ -199,7 +199,7 @@ PolynomialsRT_Bubbles::evaluate( } Assert(start == this->n() - my_degree - 1, ExcInternalError()); } - else if DEAL_II_CONSTEXPR_IN_CONDITIONAL (dim == 3) + else if constexpr (dim == 3) { double monoval[dim][n_derivatives + 1]; double monoval_j[dim][n_derivatives + 1];