From 770b9ab6ee7bd815f58acff06d6b609bfafa7676 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 23 Dec 2022 19:21:35 +0100 Subject: [PATCH] refactor: `basic_concepts` removed --- src/core/include/units/bits/basic_concepts.h | 485 ------------------- 1 file changed, 485 deletions(-) delete mode 100644 src/core/include/units/bits/basic_concepts.h diff --git a/src/core/include/units/bits/basic_concepts.h b/src/core/include/units/bits/basic_concepts.h deleted file mode 100644 index f00763ad..00000000 --- a/src/core/include/units/bits/basic_concepts.h +++ /dev/null @@ -1,485 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2018 Mateusz Pusz -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#pragma once - -#include - -// IWYU pragma: begin_exports -#include -#include -#include -#include -#include -// IWYU pragma: end_exports - -#include -#include -#include - -namespace units { - -// Prefix -namespace detail { - -template -struct prefix_base; - -template -void to_prefix_base(const volatile prefix_base*); - -} // namespace detail - -/** - * @brief A concept matching a symbol prefix - * - * Satisfied by all specializations of `prefix`. - */ -template -concept Prefix = requires(T* t) { detail::to_prefix_base(t); }; - -// Unit -template -struct scaled_unit; - -// TODO: Remove when P1985 accepted -namespace detail { - -template -void to_base_scaled_unit(const volatile scaled_unit*); - -} // namespace detail - -/** - * @brief A concept matching all unit types in the library - * - * Satisfied by all unit types derived from an specialization of :class:`scaled_unit`. - */ -template -concept Unit = requires(T* t) { detail::to_base_scaled_unit(t); }; - -namespace detail { - -template -inline constexpr bool is_named = false; - -} - -template -concept NamedUnit = Unit && detail::is_named; - -template -struct alias_unit; - -// TODO: Remove when P1985 accepted -namespace detail { - -template -void to_base_alias_unit(const volatile alias_unit*); - -} // namespace detail - -template -concept AliasUnit = requires(T* t) { detail::to_base_alias_unit(t); }; - -// BaseDimension -#ifdef __cpp_explicit_this_parameter -template -#else -template -#endif -struct base_dimension; - -namespace detail { - -template -void to_base_base_dimension(const volatile base_dimension*); - -} // namespace detail - -/** - * @brief A concept matching all base dimensions in the library. - * - * Satisfied by all dimension types derived from an specialization of `base_dimension`. - */ -template -concept BaseDimension = requires(T* t) { detail::to_base_base_dimension(t); }; - -// Exponent -namespace detail { - -template -inline constexpr bool is_exponent = false; - -} // namespace detail - -/** - * @brief A concept matching dimension's exponents. - * - * Satisfied by all specializations of :class:`exponent`. - */ -template -concept Exponent = detail::is_exponent; - -// DerivedDimension -namespace detail { - -template - requires(BaseDimension && ...) -struct derived_dimension_base; - -} // namespace detail - -/** - * @brief A concept matching all derived dimensions in the library. - * - * Satisfied by all dimension types derived from an specialization of `detail::derived_dimension_base`. - */ -template -concept DerivedDimension = is_derived_from_specialization_of; - -// Dimension -/** - * @brief A concept matching all dimensions in the library. - * - * Satisfied by all dimension types for which either `BaseDimension` or `DerivedDimension` is `true`. - */ -template -concept Dimension = BaseDimension || DerivedDimension; - -// UnitOf -namespace detail { - -template -auto default_unit() -{ - if constexpr (BaseDimension) - return typename D::base_unit{}; - else - return typename D::coherent_unit{}; -} - -} // namespace detail - -/** - * @brief Returns a 'default' unit of the dimension - * - * Depending on the dimension type it returns a base unit (for base dimensions) - * or a coherent unit (in case of derived dimensions). - * - * @tparam D Dimension type to get the unit from. - */ -template -using dimension_unit = decltype(detail::default_unit()); -// TODO: replace with the below code when VS catches up -// decltype([]{ -// if constexpr (BaseDimension) -// return TYPENAME D::base_unit{}; -// else -// return TYPENAME D::coherent_unit{}; -// }()); - -/** - * @brief A concept matching only units of a specified dimension. - * - * Satisfied by all unit types that satisfy `Unit`, `Dimension`, and for which - * `U::reference` and @c dimension_unit::reference denote the same unit type. - * - * @tparam U Type to verify. - * @tparam D Dimension type to use for verification. - */ -template -concept UnitOf = Unit && Dimension && std::same_as::reference>; - -// PointOrigin - -template -struct point_origin; - -/** - * @brief A concept matching a point origin - * - * Satisfied by types derived from an specialization of @c point_origin. - */ -template -concept PointOrigin = is_derived_from_specialization_of && - requires { - typename T::dimension; - requires Dimension; - typename T::point_origin; - requires std::same_as>; - requires !std::same_as>; - }; - -// RebindablePointOriginFor - -namespace detail { - -template -struct rebind_point_origin_dimension_impl { - using type = typename O::template rebind; -}; - -} // namespace detail - -template -using rebind_point_origin_dimension = typename conditional, std::type_identity, - detail::rebind_point_origin_dimension_impl>::type; - -/** - * @brief A concept predicating the possibility of changing an origin's dimension - * - * Satisfied by point origins whose dimension can be made to be `D`. - */ -template -concept RebindablePointOriginFor = - requires { typename rebind_point_origin_dimension; } && PointOrigin> && - std::same_as::dimension>; - -// Kind -namespace detail { - -template -struct _kind_base; - -} // namespace detail - -template typename Base> -concept kind_impl_ = is_derived_from_specialization_of && requires { - typename T::base_kind; - typename T::dimension; - requires Dimension; - }; - -/** - * @brief A concept matching all kind types - * - * Satisfied by all kind types derived from an specialization of @c kind. - */ -template -concept Kind = kind_impl_ && kind_impl_ && - std::same_as; - -// PointKind -namespace detail { - -template -struct _point_kind_base; - -} // namespace detail - -/** - * @brief A concept matching all point kind types - * - * Satisfied by all point kind types derived from an specialization of @c point_kind. - */ -template -concept PointKind = - kind_impl_ && requires { typename T::origin; } && PointOrigin && - std::same_as && - std::same_as; - -// Reference -namespace detail { - -template -inline constexpr bool is_reference = false; - -} // namespace detail - -/** - * @brief A concept matching all references in the library. - * - * Satisfied by all specializations of @c reference. - */ -template -concept Reference = detail::is_reference; - -// Quantity, QuantityPoint, QuantityKind, QuantityPointKind -namespace detail { - -template -inline constexpr bool is_quantity = false; - -template -inline constexpr bool is_quantity_point = false; - -template -inline constexpr bool is_quantity_kind = false; - -template -inline constexpr bool is_quantity_point_kind = false; - -template -inline constexpr bool is_quantity_like = false; - -template -inline constexpr bool is_quantity_point_like = false; - -} // namespace detail - -/** - * @brief A concept matching all quantities in the library. - * - * Satisfied by all specializations of @c quantity. - */ -template -concept Quantity = detail::is_quantity; - -/** - * @brief A concept matching all quantity points in the library. - * - * Satisfied by all specializations of @c quantity_point. - */ -template -concept QuantityPoint = detail::is_quantity_point; - -/** - * @brief A concept matching all quantity kinds in the library. - * - * Satisfied by all specializations of @c quantity_kind. - */ -template -concept QuantityKind = detail::is_quantity_kind; - -/** - * @brief A concept matching all quantity point kinds in the library. - * - * Satisfied by all specializations of @c quantity_point_kind. - */ -template -concept QuantityPointKind = detail::is_quantity_point_kind; - -// QuantityLike, QuantityPointLike - -/** - * @brief A concept matching all quantity-like types (other than specialization of @c quantity) - * - * Satisfied by all types for which a correct specialization of `quantity_like_traits` - * type trait is provided. - */ -template -concept QuantityLike = detail::is_quantity_like; - -/** - * @brief A concept matching all quantity point-like types (other than specialization of @c quantity_point) - * - * Satisfied by all types for which a correct specialization of `quantity_point_like_traits` - * type trait is provided. - */ -template -concept QuantityPointLike = detail::is_quantity_point_like; - -// Representation - -template -concept common_type_with_ = // exposition only - (std::same_as, std::common_type_t>) && - (std::constructible_from, T>) && (std::constructible_from, U>); - -template -concept scalable_number_ = // exposition only - (std::regular_invocable, T, U>) && (std::regular_invocable, T, U>); - -template -concept castable_number_ = // exposition only - common_type_with_ && scalable_number_>; - -template -concept scalable_ = // exposition only - castable_number_ || (requires { typename T::value_type; } && castable_number_ && - scalable_number_>); - -template -concept scalable_with_ = // exposition only - common_type_with_ && scalable_>; - -// WrappedQuantity -namespace detail { - -template -inline constexpr bool is_wrapped_quantity = false; - -template - requires requires { typename T::value_type; } -inline constexpr bool is_wrapped_quantity = - Quantity || QuantityLike || - is_wrapped_quantity; - -template - requires requires { typename T::quantity_type; } -inline constexpr bool is_wrapped_quantity = Quantity; - -} // namespace detail - -/** - * @brief A concept matching types that wrap quantity objects. - * - * Satisfied by all wrapper types that satisfy `Quantity` - * recursively (i.e. `std::optional>`). - */ -template -concept wrapped_quantity_ = // exposition only - detail::is_wrapped_quantity; - -/** - * @brief A concept matching non-Quantity types. - * - * Satisfied by types that satisfy `(!Quantity) && (!WrappedQuantity) && std::regular`. - */ -template -concept Representation = (!Quantity) && (!QuantityLike) && - (!wrapped_quantity_) && std::regular && scalable_; - -namespace detail { - -template - requires requires(T q) { - typename quantity_like_traits::dimension; - typename quantity_like_traits::unit; - typename quantity_like_traits::rep; - requires Dimension::dimension>; - requires Unit::unit>; - requires Representation::rep>; - { - quantity_like_traits::number(q) - } -> std::convertible_to::rep>; - } -inline constexpr bool is_quantity_like = true; - -template - requires requires(T q) { - typename quantity_point_like_traits::dimension; - typename quantity_point_like_traits::unit; - typename quantity_point_like_traits::rep; - requires Dimension::dimension>; - requires Unit::unit>; - requires Representation::rep>; - { - quantity_point_like_traits::relative(q) - } -> QuantityLike; - } -inline constexpr bool is_quantity_point_like = true; - -} // namespace detail - -} // namespace units