WrappedUnit support added

This commit is contained in:
Mateusz Pusz
2020-02-14 21:58:50 +01:00
parent a34730cf8c
commit 395a98c055
2 changed files with 24 additions and 2 deletions

View File

@@ -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

View File

@@ -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