Skip to content

Commit

Permalink
fix: workarounds for not-working CWG2387
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Sep 5, 2024
1 parent 45013f6 commit 7eb9b76
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion example/include/ranged_representation.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import mp_units.core;

template<std::movable T, MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Min,
MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Max>
constexpr auto is_in_range = [](const auto& v) { return std::clamp(v, T{Min}, T{Max}) == v; };
MP_UNITS_INLINE constexpr auto is_in_range = [](const auto& v) { return std::clamp(v, T{Min}, T{Max}) == v; };

template<std::movable T, MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Min,
MP_UNITS_CONSTRAINED_NTTP_WORKAROUND(std::convertible_to<T>) auto Max>
Expand Down
3 changes: 3 additions & 0 deletions src/core/include/mp-units/bits/hacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
#define MP_UNITS_HOSTED __STDC_HOSTED__
#endif

// workarounds for https://cplusplus.github.io/CWG/issues/2387.html
#define MP_UNITS_INLINE inline

#if MP_UNITS_COMP_MSVC

#define MP_UNITS_TYPENAME typename
Expand Down
20 changes: 10 additions & 10 deletions src/core/include/mp-units/bits/text_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ template<std::intmax_t Value>
constexpr basic_fixed_string superscript_number = u8"";

template<>
constexpr basic_fixed_string superscript_number<0> = u8"\u2070";
MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<0> = u8"\u2070";
template<>
constexpr basic_fixed_string superscript_number<1> = u8"\u00b9";
MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<1> = u8"\u00b9";
template<>
constexpr basic_fixed_string superscript_number<2> = u8"\u00b2";
MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<2> = u8"\u00b2";
template<>
constexpr basic_fixed_string superscript_number<3> = u8"\u00b3";
MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<3> = u8"\u00b3";
template<>
constexpr basic_fixed_string superscript_number<4> = u8"\u2074";
MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<4> = u8"\u2074";
template<>
constexpr basic_fixed_string superscript_number<5> = u8"\u2075";
MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<5> = u8"\u2075";
template<>
constexpr basic_fixed_string superscript_number<6> = u8"\u2076";
MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<6> = u8"\u2076";
template<>
constexpr basic_fixed_string superscript_number<7> = u8"\u2077";
MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<7> = u8"\u2077";
template<>
constexpr basic_fixed_string superscript_number<8> = u8"\u2078";
MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<8> = u8"\u2078";
template<>
constexpr basic_fixed_string superscript_number<9> = u8"\u2079";
MP_UNITS_INLINE constexpr basic_fixed_string superscript_number<9> = u8"\u2079";

inline constexpr symbol_text superscript_minus(u8"\u207b", "-");

Expand Down
4 changes: 2 additions & 2 deletions src/core/include/mp-units/framework/expression_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ template<int Num>
constexpr bool valid_ratio<Num, 0> = false;

template<>
constexpr bool valid_ratio<0, 0> = false;
MP_UNITS_INLINE constexpr bool valid_ratio<0, 0> = false;

template<int Num, int... Den>
constexpr bool positive_ratio = gt_zero<Num>;
Expand All @@ -84,7 +84,7 @@ template<int Num, int... Den>
constexpr bool ratio_one = false;

template<>
constexpr bool ratio_one<1> = true;
MP_UNITS_INLINE constexpr bool ratio_one<1> = true;

template<int N>
constexpr bool ratio_one<N, N> = true;
Expand Down
6 changes: 3 additions & 3 deletions src/core/include/mp-units/framework/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,11 @@ template<Unit auto U>
constexpr bool space_before_unit_symbol = true;

template<>
constexpr bool space_before_unit_symbol<one> = false;
MP_UNITS_INLINE constexpr bool space_before_unit_symbol<one> = false;
template<>
constexpr bool space_before_unit_symbol<percent> = false;
MP_UNITS_INLINE constexpr bool space_before_unit_symbol<percent> = false;
template<>
constexpr bool space_before_unit_symbol<per_mille> = false;
MP_UNITS_INLINE constexpr bool space_before_unit_symbol<per_mille> = false;

// get_unit_symbol

Expand Down
4 changes: 2 additions & 2 deletions src/systems/include/mp-units/systems/angular/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ inline constexpr auto deg2 = square(degree);
} // namespace angular

template<>
constexpr bool space_before_unit_symbol<angular::degree> = false;
MP_UNITS_INLINE constexpr bool space_before_unit_symbol<angular::degree> = false;
template<>
constexpr bool space_before_unit_symbol<angular::gradian> = false;
MP_UNITS_INLINE constexpr bool space_before_unit_symbol<angular::gradian> = false;

} // namespace mp_units
6 changes: 3 additions & 3 deletions src/systems/include/mp-units/systems/si/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ using namespace non_si;
} // namespace si

template<>
constexpr bool space_before_unit_symbol<non_si::degree> = false;
MP_UNITS_INLINE constexpr bool space_before_unit_symbol<non_si::degree> = false;
template<>
constexpr bool space_before_unit_symbol<non_si::arcminute> = false;
MP_UNITS_INLINE constexpr bool space_before_unit_symbol<non_si::arcminute> = false;
template<>
constexpr bool space_before_unit_symbol<non_si::arcsecond> = false;
MP_UNITS_INLINE constexpr bool space_before_unit_symbol<non_si::arcsecond> = false;

} // namespace mp_units

0 comments on commit 7eb9b76

Please sign in to comment.