mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 13:14:29 +02:00
WrappedUnit support added
This commit is contained in:
@@ -881,11 +881,16 @@ concept basic-arithmetic = // exposition only
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Scalar =
|
concept Scalar =
|
||||||
(!Quantity<T>) &&
|
(!Quantity<T>) &&
|
||||||
|
(!WrappedQuantity<T>) &&
|
||||||
std::regular<T> &&
|
std::regular<T> &&
|
||||||
std::totally_ordered<T> &&
|
std::totally_ordered<T> &&
|
||||||
basic-arithmetic<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:
|
The above implies that the `Rep` type should provide at least:
|
||||||
- default constructor, destructor, copy-constructor, and copy-assignment operator
|
- default constructor, destructor, copy-constructor, and copy-assignment operator
|
||||||
- `operator==(Rep, Rep)`, `operator!=(Rep, Rep)`
|
- `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)`
|
||||||
- `operator+(Rep, Rep)`, `operator-(Rep, Rep)`, `operator*(Rep, Rep)`, `operator*(Rep, 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
|
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
|
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>
|
template<typename T>
|
||||||
concept Quantity = detail::is_quantity<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
|
// Scalar
|
||||||
template<typename T>
|
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
|
} // namespace units
|
||||||
|
Reference in New Issue
Block a user