Template Struct T8Type

Inheritance Relationships

Base Type

  • public competence< T8Type< T, Parameter, competence... > >

Struct Documentation

template<typename T, typename Parameter, template<typename> class ...competence>
struct T8Type : public competence<T8Type<T, Parameter, competence...>>

An implementation of strong type with additional competences.

This class template allows the creation of a type that can be extended with multiple competences. Each competence is a template class that takes the main type as a template parameter.

This is heavily inspired by (and taken from) https://www.fluentcpp.com/2016/12/08/strong-types-for-strong-interfaces/

Template Parameters:
  • T – The type of the value to be stored.

  • Parameter – An additional parameter for the type.

  • competence – Variadic template parameter for the competences.

Public Types

using value_type = T

The type of the value stored in this strong type.

using tag = Parameter

The tag of the value stored in this strong type.

Public Functions

explicit constexpr T8Type() = default

Default constructor.

inline explicit constexpr T8Type(const T &value)

Constructor with value.

inline explicit constexpr T8Type (T &&value) requires(!std

Construct a new T8Type object.

Note

This constructor is only enabled if T is not a reference value.

Parameters:

value

inline constexpr T8Type &operator=(const T &value)

Copy constructor.

inline constexpr T &get() noexcept

Get a reference to the stored value.

Returns:

A reference to the stored value.

inline constexpr T const &get() const noexcept

Get a const reference to the stored value.

Returns:

A const reference to the stored value.

inline constexpr operator value_type() const

Implicit conversion to value type to cast a variable instance of this class into its value_type for example for printing.

Note

to future devs: If this causes trouble in the future when we create a type that is not easily (or should not be) convertible to its base type, we can wrap this inside an enable_if condition and only allow the conversion if explicitly stated.