emlabcpp
modern opinionated embedded C++ library
emlabcpp::quantity< Derived, ValueType > Class Template Reference

Class representing generic quantity. More...

#include <quantity.h>

Public Types

using value_type = ValueType
 

Public Member Functions

constexpr quantity () noexcept
 
template<typename Value >
constexpr quantity (Value val) noexcept
 Default constructor used to create a physical quantity from value. More...
 
constexpr ValueType operator* () const noexcept
 Const reference to the internal value. More...
 
constexpr Derived & operator+= (quantity const other) noexcept
 Add other quantity of same Derived and value_type. More...
 
constexpr Derived & operator-= (quantity const other) noexcept
 Subtract other quantity of same Derived and value_type. More...
 
constexpr Derived & operator/= (arithmetic auto const val) noexcept
 Divides quantity by it's value type. More...
 
constexpr Derived & operator*= (arithmetic auto const val) noexcept
 Multiplies quantity by it's value type. More...
 
template<typename U >
constexpr operator U () const noexcept
 Provides explicit conversion of internal value to type U. More...
 

Static Public Member Functions

static std::string get_unit ()
 

Friends

constexpr friend auto operator<=> (quantity const &, quantity const &)=default
 

Detailed Description

template<typename Derived, typename ValueType = float>
class emlabcpp::quantity< Derived, ValueType >

Class representing generic quantity.

Quantities are types which simply overlay basic numeric type (ValueType) and give you abillity to create custom types via CRTP. The C++ type system prevents you from passing values of quantites of different implementation type.

The overlay implements: +=,-= +,- ==, != <,>,>=,<= abs, max, min Quantity can be multiplied or divided by it's ValueType - /,*,/=,*= Additionally, we support these operations over quantity: cos, sin

Credits should go to https://github.com/joboccara/NamedType as I inspired by project by this blogger!

Member Typedef Documentation

◆ value_type

template<typename Derived , typename ValueType = float>
using emlabcpp::quantity< Derived, ValueType >::value_type = ValueType

Constructor & Destructor Documentation

◆ quantity() [1/2]

template<typename Derived , typename ValueType = float>
constexpr emlabcpp::quantity< Derived, ValueType >::quantity ( )
inlineconstexprnoexcept

◆ quantity() [2/2]

template<typename Derived , typename ValueType = float>
template<typename Value >
constexpr emlabcpp::quantity< Derived, ValueType >::quantity ( Value  val)
inlineexplicitconstexprnoexcept

Default constructor used to create a physical quantity from value.

Member Function Documentation

◆ get_unit()

template<typename Derived , typename ValueType = float>
static std::string emlabcpp::quantity< Derived, ValueType >::get_unit ( )
inlinestatic

◆ operator U()

template<typename Derived , typename ValueType = float>
template<typename U >
constexpr emlabcpp::quantity< Derived, ValueType >::operator U ( ) const
inlineexplicitconstexprnoexcept

Provides explicit conversion of internal value to type U.

◆ operator*()

template<typename Derived , typename ValueType = float>
constexpr ValueType emlabcpp::quantity< Derived, ValueType >::operator* ( ) const
inlineconstexprnoexcept

Const reference to the internal value.

◆ operator*=()

template<typename Derived , typename ValueType = float>
constexpr Derived& emlabcpp::quantity< Derived, ValueType >::operator*= ( arithmetic auto const  val)
inlineconstexprnoexcept

Multiplies quantity by it's value type.

◆ operator+=()

template<typename Derived , typename ValueType = float>
constexpr Derived& emlabcpp::quantity< Derived, ValueType >::operator+= ( quantity< Derived, ValueType > const  other)
inlineconstexprnoexcept

Add other quantity of same Derived and value_type.

◆ operator-=()

template<typename Derived , typename ValueType = float>
constexpr Derived& emlabcpp::quantity< Derived, ValueType >::operator-= ( quantity< Derived, ValueType > const  other)
inlineconstexprnoexcept

Subtract other quantity of same Derived and value_type.

◆ operator/=()

template<typename Derived , typename ValueType = float>
constexpr Derived& emlabcpp::quantity< Derived, ValueType >::operator/= ( arithmetic auto const  val)
inlineconstexprnoexcept

Divides quantity by it's value type.

Friends And Related Function Documentation

◆ operator<=>

template<typename Derived , typename ValueType = float>
constexpr friend auto operator<=> ( quantity< Derived, ValueType > const &  ,
quantity< Derived, ValueType > const &   
)
friend

The documentation for this class was generated from the following file: