forked from mpusz/mp-units
WrappedUnit support added
This commit is contained in:
@@ -881,11 +881,16 @@ concept basic-arithmetic = // exposition only
|
||||
template<typename T>
|
||||
concept Scalar =
|
||||
(!Quantity<T>) &&
|
||||
(!WrappedQuantity<T>) &&
|
||||
std::regular<T> &&
|
||||
std::totally_ordered<T> &&
|
||||
basic-arithmetic<T>;
|
||||
```
|
||||
|
||||
Where `WrappedQuantity` is a concept that applies `Quantity<typename T::value_type>` recursively
|
||||
on all nested types to check if `T` is not actually a wrapped quantity type (i.e. a vector or
|
||||
matrix of quantities).
|
||||
|
||||
The above implies that the `Rep` type should provide at least:
|
||||
- default constructor, destructor, copy-constructor, and copy-assignment operator
|
||||
- `operator==(Rep, Rep)`, `operator!=(Rep, Rep)`
|
||||
@@ -893,7 +898,8 @@ The above implies that the `Rep` type should provide at least:
|
||||
- `operator-(Rep)`
|
||||
- `operator+(Rep, Rep)`, `operator-(Rep, Rep)`, `operator*(Rep, Rep)`, `operator*(Rep, Rep)`
|
||||
|
||||
Above also requires that the `Rep` should be implicitly convertible from integral types (i.e. `int`) so a proper implicit converting constructor should be provided.
|
||||
Above also requires that the `Rep` should be implicitly convertible from integral types
|
||||
(i.e. `int`) so a proper implicit converting constructor should be provided.
|
||||
|
||||
Moreover, in most cases to observe expected behavior `Rep` will have to be registered as a
|
||||
floating-point representation type by specializing `units::treat_as_floating_point` type
|
||||
|
@@ -180,8 +180,24 @@ inline constexpr bool is_quantity = false;
|
||||
template<typename T>
|
||||
concept Quantity = detail::is_quantity<T>;
|
||||
|
||||
|
||||
// WrappedQuantity
|
||||
namespace detail {
|
||||
|
||||
template<typename T>
|
||||
inline constexpr bool is_wrapped_quantity = false;
|
||||
|
||||
template<typename T>
|
||||
requires requires { typename T::value_type; }
|
||||
inline constexpr bool is_wrapped_quantity<T> = Quantity<typename T::value_type> || is_wrapped_quantity<typename T::value_type>;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<typename T>
|
||||
concept WrappedQuantity = detail::is_wrapped_quantity<T>;
|
||||
|
||||
// Scalar
|
||||
template<typename T>
|
||||
concept Scalar = (!Quantity<T>) && std::regular<T> && std::totally_ordered<T> && detail::basic_arithmetic<T>;
|
||||
concept Scalar = (!Quantity<T>) && (!WrappedQuantity<T>) && std::regular<T>; // && std::totally_ordered<T>;// && detail::basic_arithmetic<T>;
|
||||
|
||||
} // namespace units
|
||||
|
Reference in New Issue
Block a user