Public Member Functions | Private Attributes | List of all members
beluga::Numeric< T, PhantomType, typename > Class Template Referencefinal

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

value_ {0}
 

Detailed Description

template<typename T, typename PhantomType, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
class beluga::Numeric< T, PhantomType, typename >

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.

Template Parameters
TUnderlying type, i.e. 'double'.
PhantomTypeempty type to use as phantom type.

Definition at line 38 of file strongly_typed_numeric.hpp.

Constructor & Destructor Documentation

◆ Numeric() [1/2]

template<typename T , typename PhantomType , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr beluga::Numeric< T, PhantomType, typename >::Numeric ( )
constexprdefaultnoexcept

Default constructor.

◆ Numeric() [2/2]

template<typename T , typename PhantomType , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr beluga::Numeric< T, PhantomType, typename >::Numeric ( const T  t)
inlineconstexprnoexcept

Constructs a new Numeric object.

Parameters
tbuilt-in arithmetic type value.

Definition at line 46 of file strongly_typed_numeric.hpp.

Member Function Documentation

◆ operator const T &()

template<typename T , typename PhantomType , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr beluga::Numeric< T, PhantomType, typename >::operator const T & ( ) const
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.

◆ operator T&()

template<typename T , typename PhantomType , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr beluga::Numeric< T, PhantomType, typename >::operator T& ( )
inlineconstexprnoexcept

Implicit conversion to the underlying type.

Definition at line 48 of file strongly_typed_numeric.hpp.

Member Data Documentation

◆ value_

template<typename T , typename PhantomType , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
T beluga::Numeric< T, PhantomType, typename >::value_ {0}
private

Definition at line 53 of file strongly_typed_numeric.hpp.


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


beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:54