33 #include <type_traits>
35 #ifdef EMLABCPP_USE_NLOHMANN_JSON
36 #include <nlohmann/json.hpp>
61 template <
typename Derived,
typename ValueType =
float >
66 [[nodiscard]] Derived& impl()
68 return static_cast< Derived&
>( *this );
71 [[nodiscard]] Derived
const& impl()
const
73 return static_cast< Derived const&
>( *this );
85 template <
typename Value >
86 constexpr
explicit quantity( Value val ) noexcept
87 : value_(
static_cast< ValueType
>( val ) )
126 template <
typename U >
127 constexpr
explicit operator U() const noexcept
142 template <
typename Derived,
typename ValueType >
150 template <
typename T >
159 template <
typename Tag,
typename ValueType =
float >
168 template <
typename Derived,
typename ValueType >
176 template <
typename Derived,
typename ValueType >
184 template <
typename Derived,
typename ValueType >
187 return Derived{ -*val };
191 template <
typename Derived,
typename ValueType, arithmetic_like RhValueType >
198 template <
typename Derived,
typename ValueType, arithmetic_like LhValueType >
205 template <
typename Derived,
typename ValueType >
212 template <
typename Derived,
typename ValueType >
219 template <
typename Derived,
typename ValueType >
226 template <
typename Derived,
typename ValueType >
233 template <
typename Derived,
typename ValueType >
240 template <
typename Derived,
typename ValueType >
244 return Derived(
std::max( *lh, *rh ) );
248 template <
typename Derived,
typename ValueType >
252 return Derived(
std::min( *lh, *rh ) );
258 template <
typename Derived,
typename ValueType >
265 template <
typename Derived,
typename ValueType >
271 #ifdef EMLABCPP_USE_OSTREAM
272 template <
typename T,
typename ValueType >
273 std::ostream&
operator<<( std::ostream& os, quantity< T, ValueType >
const& q )
275 return os << *q << T::get_unit();
283 template < emlabcpp::quantity_derived T >
284 struct std::numeric_limits< T >
290 return T{ std::numeric_limits< value_type >::lowest() };
305 template < emlabcpp::quantity_derived T >
306 struct std::hash< T >
312 std::string
const unit = T::get_unit();
313 return std::hash< typename T::value_type >()( *q ) ^
314 std::hash< std::string >()( unit );
318 #ifdef EMLABCPP_USE_NLOHMANN_JSON
320 template < emlabcpp::quantity_derived T >
321 struct nlohmann::adl_serializer< T >
323 static void to_json( nlohmann::json& j, T
const q )
325 if ( T::get_unit().empty() )
328 j[T::get_unit()] = *q;
331 static T from_json( nlohmann::json
const& j )
335 if ( T::get_unit().empty() )
337 return T{ j[T::get_unit()].template get< value_type >() };
Class representing generic quantity.
Definition: quantity.h:63
constexpr friend auto operator<=>(quantity const &, quantity const &)=default
constexpr ValueType operator*() const noexcept
Const reference to the internal value.
Definition: quantity.h:92
constexpr Derived & operator/=(arithmetic auto const val) noexcept
Divides quantity by it's value type.
Definition: quantity.h:112
constexpr Derived & operator-=(quantity const other) noexcept
Subtract other quantity of same Derived and value_type.
Definition: quantity.h:105
constexpr quantity() noexcept
Definition: quantity.h:79
constexpr Derived & operator*=(arithmetic auto const val) noexcept
Multiplies quantity by it's value type.
Definition: quantity.h:119
constexpr quantity(Value val) noexcept
Default constructor used to create a physical quantity from value.
Definition: quantity.h:86
ValueType value_type
Definition: quantity.h:77
constexpr Derived & operator+=(quantity const other) noexcept
Add other quantity of same Derived and value_type.
Definition: quantity.h:98
static std::string get_unit()
Definition: quantity.h:132
Class represents a quantity that uses tags to distinguish quantities instead of inheritance.
Definition: quantity.h:161
Tag tag
Definition: quantity.h:163
constexpr bool quantity_derived_test(quantity< Derived, ValueType > const &)
Definition: quantity.h:143
std::variant< int64_t, float, bool, string_buffer > value_type
Definition: base.h:51
MIT License.
Definition: impl.h:31
constexpr point< N > operator+(point< N > a, vector< N > const &b)
Returns a result of addition a to b, viz += operator.
Definition: point.h:93
constexpr Derived abs(quantity< Derived, ValueType > const q)
Quantity with absolute value of internal value.
Definition: quantity.h:220
constexpr auto sin(quantity< Derived, ValueType > const u)
Returns sinus of the quantity as scalar.
Definition: quantity.h:234
constexpr point< N > operator*(point< N > a, point< N > const &b)
Multiplication of points multiplies each coordinate of A by coordinate of B on same dimension.
Definition: point.h:74
constexpr Derived max(quantity< Derived, ValueType > const lh, quantity< Derived, ValueType > const rh)
Quantity with maximum value of one of the quantities.
Definition: quantity.h:242
concept arithmetic
Definition: concepts.h:65
constexpr Derived abs(vec_point_base< Derived, N > const &a)
Creates absolute version of A - removing signs on all dimensions.
Definition: vec_point_base.h:219
constexpr Derived min(quantity< Derived, ValueType > const lh, quantity< Derived, ValueType > const rh)
Quantity with minimum value of one of the quantities.
Definition: quantity.h:250
concept quantity_derived
Concept satisfies any type T that inherits from any form of quantity<U>.
Definition: quantity.h:151
constexpr auto cos(quantity< Derived, ValueType > const u)
Returns cosinus of the quantity as scalar.
Definition: quantity.h:227
requires(!range_container< Container >) const expr std
Returns index of an element in tuple 't', for which call to predicate f(x) holds true,...
Definition: algorithm.h:127
constexpr bool operator<(pose const &x, pose const &y)
Definition: pose.h:85
constexpr Derived max(vec_point_base< Derived, N > const &a, vec_point_base< Derived, N > const &b)
Definition: vec_point_base.h:229
constexpr vector< N > operator-(point< N > a, point< N > const &b)
Returns a result of subtraction of A from B, viz -= operator.
Definition: point.h:84
constexpr Derived const & min(vec_point_base< Derived, N > const &a, vec_point_base< Derived, N > const &b)
Definition: vec_point_base.h:236
constexpr Derived operator/(vec_point_base< Derived, N > const &a, T s)
Divides each coordinate of A by item 's' of type T, if T satifies std::is_arithmetic.
Definition: vec_point_base.h:170
std::ostream & operator<<(std::ostream &os, string_buffer< N > const &sb)
Definition: string_buffer.h:112
std::size_t operator()(T q) const
Definition: quantity.h:308
constexpr static T max()
Definition: quantity.h:298
constexpr static T min()
Definition: quantity.h:293
constexpr static T lowest()
Definition: quantity.h:288
typename T::value_type value_type
Definition: quantity.h:286