Template Class Numeric

Class Documentation

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

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:
  • T – Underlying type, i.e. ‘double’.

  • PhantomType – empty type to use as phantom type.

Public Functions

constexpr Numeric() noexcept = default

Default constructor.

inline constexpr Numeric(const T t) noexcept

Constructs a new Numeric object.

Parameters:

t – built-in arithmetic type value.

inline constexpr operator T&() noexcept

Implicit conversion to the underlying type.

inline 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.