Skip to content

Commit

Permalink
replace PXRMP_CONSTEXPR_IF with if constexpr (we are moving to C++17)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucafedeli88 committed Oct 23, 2024
1 parent 8d90f97 commit e02016e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
16 changes: 8 additions & 8 deletions multi_physics/QED/include/picsar_qed/math/quadrature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,41 +74,41 @@ namespace picsar::multi_physics::math
inline constexpr RealType generic_quad_a_b(
const std::function<RealType(RealType)>& f, RealType a, RealType b)
{
PXRMP_CONSTEXPR_IF (
if constexpr (
QuadAlgo == quadrature_algorithm::trapezoidal){
return boost::math::quadrature::trapezoidal(f, a, b);
}
else PXRMP_CONSTEXPR_IF (
else if constexpr (
QuadAlgo == quadrature_algorithm::tanh_sinh){
boost::math::quadrature::tanh_sinh<RealType> integrator;
return integrator.integrate(f, a, b);
}
else PXRMP_CONSTEXPR_IF (
else if constexpr (
QuadAlgo == quadrature_algorithm::exp_sinh){
boost::math::quadrature::exp_sinh<RealType> integrator;
return integrator.integrate(f, a, b);
}
else PXRMP_CONSTEXPR_IF (
else if constexpr (
QuadAlgo == quadrature_algorithm::gauss_kronrod15){
return boost::math::quadrature::gauss_kronrod<RealType, 15>
::integrate(f, a, b);
}
else PXRMP_CONSTEXPR_IF (
else if constexpr (
QuadAlgo == quadrature_algorithm::gauss_kronrod31){
return boost::math::quadrature::gauss_kronrod<RealType, 31>
::integrate(f, a, b);
}
else PXRMP_CONSTEXPR_IF (
else if constexpr (
QuadAlgo == quadrature_algorithm::gauss_kronrod41){
return boost::math::quadrature::gauss_kronrod<RealType, 41>
::integrate(f, a, b);
}
else PXRMP_CONSTEXPR_IF (
else if constexpr (
QuadAlgo == quadrature_algorithm::gauss_kronrod51){
return boost::math::quadrature::gauss_kronrod<RealType, 51>
::integrate(f, a, b);
}
else PXRMP_CONSTEXPR_IF (
else if constexpr (
QuadAlgo == quadrature_algorithm::gauss_kronrod61){
return boost::math::quadrature::gauss_kronrod<RealType, 61>
::integrate(f, a, b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ namespace picsar::multi_physics::phys::breit_wheeler
#pragma omp parallel for
#endif
for (int i = 0; i < static_cast<int>(all_coords.size()); ++i){
PXRMP_CONSTEXPR_IF (use_internal_double){
if constexpr (use_internal_double){
all_vals[i] = aux_generate_double(all_coords[i]);
}
else {
Expand Down Expand Up @@ -199,7 +199,7 @@ namespace picsar::multi_physics::phys::breit_wheeler
);

std::vector<RealType> vals = std::vector<RealType>(frac_size);
PXRMP_CONSTEXPR_IF (use_internal_double){
if constexpr (use_internal_double){
vals = aux_generate_double(
chi_phot, chi_parts);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ namespace picsar::multi_physics::phys::quantum_sync::detail
#pragma omp parallel for
#endif
for (int i = 0; i < static_cast<int>(all_coords.size()); ++i){
PXRMP_CONSTEXPR_IF (ForceInternalDouble && !std::is_same<RealType,double>()){
if constexpr (ForceInternalDouble && !std::is_same<RealType,double>()){
all_vals[i] = static_cast<RealType>(
compute_G_function<double>(all_coords[i]));
}
else {
all_vals[i] = compute_G_function(all_coords[i]);
}

PXRMP_CONSTEXPR_IF (ShowProgress){
if constexpr (ShowProgress){
#pragma omp critical
{
count++;
Expand Down Expand Up @@ -136,7 +136,7 @@ namespace picsar::multi_physics::phys::quantum_sync::detail

auto vals = std::vector<RealType>(all_frac_size);

PXRMP_CONSTEXPR_IF (ForceInternalDouble && !std::is_same<RealType,double>()){
if constexpr (ForceInternalDouble && !std::is_same<RealType,double>()){
const auto d_chi_part = static_cast<double>(chi_part);
auto d_chi_phots = std::vector<double>(all_frac_size);
std::transform(
Expand All @@ -160,7 +160,7 @@ namespace picsar::multi_physics::phys::quantum_sync::detail

std::copy(vals.begin(), vals.end(), all_vals.begin() + i*all_frac_size);

PXRMP_CONSTEXPR_IF (ShowProgress){
if constexpr (ShowProgress){
#ifdef PXRMP_HAS_OPENMP
#pragma omp critical
#endif
Expand Down
11 changes: 0 additions & 11 deletions multi_physics/QED/include/picsar_qed/qed_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@
#endif


/**
* If possible (i.e. if C++17 or more recent is used)
* picsar makes use of "if constexpr". Otherwise, the
* expression falls back to a regular "if".
*/
#if __cplusplus >= 201703L
#define PXRMP_CONSTEXPR_IF if constexpr
#else
#define PXRMP_CONSTEXPR_IF if
#endif

/**
* Unless PXRMP_PREVENT_USE_STD_FOR_MATH is defined by the
* user std::sqrt, std::cbrt... mathematical functions
Expand Down

0 comments on commit e02016e

Please sign in to comment.