Skip to content

Commit

Permalink
refactor: one_of concept removed and replaced with QSProperty in …
Browse files Browse the repository at this point in the history
…`quantity_spec`
  • Loading branch information
mpusz committed Nov 21, 2024
1 parent f84ed8f commit d622ac9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
3 changes: 0 additions & 3 deletions src/core/include/mp-units/ext/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ template<typename T>
requires std::is_object_v<T>
using value_type_t = detail::value_type_impl<T>::type;

template<typename T, typename... Ts>
concept one_of = (false || ... || std::same_as<T, Ts>);

template<typename T, auto... Vs>
[[nodiscard]] consteval bool contains()
{
Expand Down
30 changes: 13 additions & 17 deletions src/core/include/mp-units/framework/quantity_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ struct quantity_spec_interface : quantity_spec_interface_base {
#endif
};

template<typename T>
concept QSProperty = (!QuantitySpec<T>);

} // namespace detail

MP_UNITS_EXPORT_BEGIN
Expand Down Expand Up @@ -248,12 +251,10 @@ MP_UNITS_EXPORT_END
* @tparam Args optionally a value of a `quantity_character` in case the base quantity should not be scalar
*/
#if MP_UNITS_API_NO_CRTP
template<detail::BaseDimension auto Dim, one_of<quantity_character> auto... Args>
requires(... && !QuantitySpec<decltype(Args)>)
template<detail::BaseDimension auto Dim, detail::QSProperty auto... Args>
struct quantity_spec<Dim, Args...> : detail::quantity_spec_interface {
#else
template<typename Self, detail::BaseDimension auto Dim, one_of<quantity_character> auto... Args>
requires(... && !QuantitySpec<decltype(Args)>)
template<typename Self, detail::BaseDimension auto Dim, detail::QSProperty auto... Args>
struct quantity_spec<Self, Dim, Args...> : detail::quantity_spec_interface<Self> {
#endif
using _base_type_ = quantity_spec;
Expand Down Expand Up @@ -292,12 +293,10 @@ struct quantity_spec<Self, Dim, Args...> : detail::quantity_spec_interface<Self>
* @tparam Args optionally a value of a `quantity_character` in case the base quantity should not be scalar
*/
#if MP_UNITS_API_NO_CRTP
template<detail::DerivedQuantitySpec auto Eq, one_of<quantity_character> auto... Args>
requires(... && !QuantitySpec<decltype(Args)>)
template<detail::DerivedQuantitySpec auto Eq, detail::QSProperty auto... Args>
struct quantity_spec<Eq, Args...> : detail::quantity_spec_interface {
#else
template<typename Self, detail::DerivedQuantitySpec auto Eq, one_of<quantity_character> auto... Args>
requires(... && !QuantitySpec<decltype(Args)>)
template<typename Self, detail::DerivedQuantitySpec auto Eq, detail::QSProperty auto... Args>
struct quantity_spec<Self, Eq, Args...> : detail::quantity_spec_interface<Self> {
#endif
using _base_type_ = quantity_spec;
Expand Down Expand Up @@ -346,12 +345,10 @@ struct propagate_equation<Q, true> {
* or `is_kind` in case the quantity starts a new hierarchy tree of a kind
*/
#if MP_UNITS_API_NO_CRTP
template<detail::NamedQuantitySpec auto QS, one_of<quantity_character, struct is_kind> auto... Args>
requires(... && !QuantitySpec<decltype(Args)>)
template<detail::NamedQuantitySpec auto QS, detail::QSProperty auto... Args>
struct quantity_spec<QS, Args...> : detail::propagate_equation<QS>, detail::quantity_spec_interface {
#else
template<typename Self, detail::NamedQuantitySpec auto QS, one_of<quantity_character, struct is_kind> auto... Args>
requires(... && !QuantitySpec<decltype(Args)>)
template<typename Self, detail::NamedQuantitySpec auto QS, detail::QSProperty auto... Args>
struct quantity_spec<Self, QS, Args...> : detail::propagate_equation<QS>, detail::quantity_spec_interface<Self> {
#endif
using _base_type_ = quantity_spec;
Expand Down Expand Up @@ -407,14 +404,13 @@ struct quantity_spec<Self, QS, Args...> : detail::propagate_equation<QS>, detail
*/
// clang-format on
#if MP_UNITS_API_NO_CRTP
template<detail::NamedQuantitySpec auto QS, detail::DerivedQuantitySpec auto Eq,
one_of<quantity_character, struct is_kind> auto... Args>
requires(detail::QuantitySpecExplicitlyConvertibleTo<Eq, QS>) && (... && !QuantitySpec<decltype(Args)>)
template<detail::NamedQuantitySpec auto QS, detail::DerivedQuantitySpec auto Eq, detail::QSProperty auto... Args>
requires(detail::QuantitySpecExplicitlyConvertibleTo<Eq, QS>)
struct quantity_spec<QS, Eq, Args...> : detail::quantity_spec_interface {
#else
template<typename Self, detail::NamedQuantitySpec auto QS, detail::DerivedQuantitySpec auto Eq,
one_of<quantity_character, struct is_kind> auto... Args>
requires(detail::QuantitySpecExplicitlyConvertibleTo<Eq, QS>) && (... && !QuantitySpec<decltype(Args)>)
detail::QSProperty auto... Args>
requires(detail::QuantitySpecExplicitlyConvertibleTo<Eq, QS>)
struct quantity_spec<Self, QS, Eq, Args...> : detail::quantity_spec_interface<Self> {
#endif
using _base_type_ = quantity_spec;
Expand Down

0 comments on commit d622ac9

Please sign in to comment.