refactor: workarounds to make gcc-11 compile

This commit is contained in:
Mateusz Pusz
2023-08-25 22:47:32 +02:00
parent 05a307564a
commit 27ec678314
6 changed files with 14 additions and 12 deletions

View File

@@ -107,7 +107,7 @@
#endif
#if MP_UNITS_COMP_CLANG < 17
#if (defined MP_UNITS_COMP_CLANG && MP_UNITS_COMP_CLANG < 17) || (defined MP_UNITS_COMP_GCC && MP_UNITS_COMP_GCC < 12)
#define MP_UNITS_CONSTEVAL constexpr

View File

@@ -32,11 +32,12 @@ struct reference;
namespace detail {
// do not refactor below to a variable template - GCC-11 does not like it
template<typename T>
inline constexpr bool is_specialization_of_reference = false;
struct is_specialization_of_reference : std::false_type {};
template<auto Q, auto U>
inline constexpr bool is_specialization_of_reference<reference<Q, U>> = true;
struct is_specialization_of_reference<reference<Q, U>> : std::true_type {};
} // namespace detail
@@ -46,7 +47,7 @@ inline constexpr bool is_specialization_of_reference<reference<Q, U>> = true;
* Satisfied by all specializations of @c reference.
*/
template<typename T>
concept Reference = AssociatedUnit<T> || detail::is_specialization_of_reference<T>;
concept Reference = AssociatedUnit<T> || detail::is_specialization_of_reference<T>::value;
[[nodiscard]] consteval QuantitySpec auto get_quantity_spec(AssociatedUnit auto u);

View File

@@ -31,8 +31,9 @@ namespace mp_units {
namespace detail {
// do not refactor below to a variable template - GCC-11 does not like it
template<typename T>
inline constexpr bool is_unit = false;
struct is_unit : std::false_type {};
} // namespace detail
@@ -42,7 +43,7 @@ inline constexpr bool is_unit = false;
* Satisfied by all unit types provided by the library.
*/
template<typename T>
concept Unit = detail::is_unit<T>;
concept Unit = detail::is_unit<T>::value;
template<Magnitude auto M, Unit U>
struct scaled_unit;
@@ -140,8 +141,8 @@ template<basic_symbol_text Symbol, Magnitude auto M, PrefixableUnit auto U>
inline constexpr bool is_specialization_of_prefixed_unit<prefixed_unit<Symbol, M, U>> = true;
template<typename T>
requires requires(T* t) { is_unit_impl(t); }
inline constexpr bool is_unit<T> = !is_specialization_of_named_unit<T> && !is_specialization_of_prefixed_unit<T>;
requires requires(T* t) { is_unit_impl(t); } && (!is_specialization_of_named_unit<T>) && (!is_specialization_of_prefixed_unit<T>)
struct is_unit<T> : std::true_type {};
template<Unit U>
[[nodiscard]] consteval bool has_associated_quantity(U);

View File

@@ -46,7 +46,7 @@ template<Unit auto ToU, typename Q>
{
using q_type = std::remove_reference_t<Q>;
constexpr auto r = [] {
if constexpr (detail::is_specialization_of_reference<std::remove_const_t<decltype(q_type::reference)>> ||
if constexpr (detail::is_specialization_of_reference<std::remove_const_t<decltype(q_type::reference)>>::value ||
!AssociatedUnit<std::remove_const_t<decltype(ToU)>>)
return reference<q_type::quantity_spec, ToU>{};
else

View File

@@ -115,7 +115,7 @@ struct quantity_spec_interface {
}
#else
template<typename Self_ = Self, UnitOf<Self_{}> U>
[[nodiscard]] consteval Reference auto operator[](U u) const
[[nodiscard]] MP_UNITS_CONSTEVAL Reference auto operator[](U u) const
{
if constexpr (detail::QuantityKindSpec<Self_>)
return u;
@@ -294,7 +294,7 @@ struct quantity_spec<Self, QS, Args...> : std::remove_const_t<decltype(QS)> {
#ifndef __cpp_explicit_this_parameter
template<typename Self_ = Self, UnitOf<Self_{}> U>
[[nodiscard]] consteval Reference auto operator[](U u) const
[[nodiscard]] MP_UNITS_CONSTEVAL Reference auto operator[](U u) const
{
if constexpr (detail::QuantityKindSpec<Self>)
return u;

View File

@@ -30,7 +30,7 @@ using namespace mp_units;
using namespace mp_units::si;
using namespace mp_units::iec80000;
#ifdef __cpp_lib_constexpr_string
#if __cpp_lib_constexpr_string && (!defined MP_UNITS_COMP_GCC || MP_UNITS_COMP_GCC > 11)
using enum text_encoding;
using enum unit_symbol_solidus;