Helper for creating strongly typed numeric types. More...
#include <strongly_typed_numeric.hpp>
Public Member Functions | |
constexpr | Numeric () noexcept=default |
Default constructor. More... | |
constexpr | Numeric (const T t) noexcept |
Constructs a new Numeric object. More... | |
constexpr | operator const T & () const noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
constexpr | operator T& () noexcept |
Implicit conversion to the underlying type. More... | |
Private Attributes | |
T | value_ {0} |
Helper for creating strongly typed numeric types.
Usage: using YOUR_TYPE = Numeric< UNDERLYING_TYPE , struct UNDERLYING_TYPETag >;
Types resulting from this pattern will allow for implicit conversions in both ways (from underlying type, and to underlying type). This results in a more convenient usage, but not type safety strictly speaking. std::numeric_limits
and std::hash
will be specialized for this new type.
T | Underlying type, i.e. 'double'. |
PhantomType | empty type to use as phantom type. |
Definition at line 38 of file strongly_typed_numeric.hpp.
|
constexprdefaultnoexcept |
Default constructor.
|
inlineconstexprnoexcept |
Constructs a new Numeric object.
t | built-in arithmetic type value. |
Definition at line 46 of file strongly_typed_numeric.hpp.
|
inlineconstexprnoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 50 of file strongly_typed_numeric.hpp.
|
inlineconstexprnoexcept |
Implicit conversion to the underlying type.
Definition at line 48 of file strongly_typed_numeric.hpp.
|
private |
Definition at line 53 of file strongly_typed_numeric.hpp.