gw  1.0.0
A bunch of small C++ utilities
gw::named_type< T, Name > Class Template Referencefinal

Named type wrapper. More...

#include <named_type.hpp>

Inheritance diagram for gw::named_type< T, Name >:
[legend]
Collaboration diagram for gw::named_type< T, Name >:
[legend]

Public Types

using value_type = T
 the type of the contained value
 

Public Member Functions

template<typename... Args>
constexpr named_type (Args &&... args) noexcept(std::is_nothrow_constructible_v< T, Args... >) requires std
 constructs the gw::named_type object
 
template<typename U , typename... Args>
constexpr named_type (std::initializer_list< U > ilist, Args &&... args) noexcept(std::is_nothrow_constructible_v< T, std::initializer_list< U > &, Args... >) requires std
 constructs the gw::named_type object
 
 ~named_type () noexcept(std::is_nothrow_destructible_v< T >)=default
 destroys the contained value
 
constexpr auto operator-> () const noexcept -> const T *
 accesses the contained value
 
constexpr auto operator-> () noexcept -> T *
 accesses the contained value
 
constexpr auto operator* () const &noexcept -> const T &
 accesses the contained value
 
constexpr auto operator* () &noexcept -> T &
 accesses the contained value
 
constexpr auto operator* () const &&noexcept -> const T &&
 accesses the contained value
 
constexpr auto operator* () &&noexcept -> T &&
 accesses the contained value
 
constexpr auto value () const &noexcept -> const T &
 returns the contained value
 
constexpr auto value () &noexcept -> T &
 returns the contained value
 
constexpr auto value () const &&noexcept -> const T &&
 returns the contained value
 
constexpr auto value () &&noexcept -> T &&
 returns the contained value
 

Static Public Member Functions

static constexpr auto name () noexcept -> std::string_view
 returns the name of the gw::named_type
 

Static Public Attributes

template<typename F >
constexpr auto static constexpr transform(F &&func) const &noexcept(noexcept(func(m_value))) requires std auto k_name = Name.value
 returns a gw::named_type containing the transformed contained value
 

Detailed Description

template<typename T, detail::fixed_string Name>
class gw::named_type< T, Name >

Named type wrapper.

The class template gw::named_type is a simple wrapper around a value of some type T. It is intended to be used to create a new type that is distinct from T, but which has the same representation and semantics as T. This is useful to distinguish between values that are conceptually different, but which have the same underlying type. For example, a std::string can be used to represent a person's name, but it can also be used to represent a person's address. Using gw::named_type to create a name_t and an address_t allows the compiler to catch errors where a name_t is used where an address_t is expected, and vice versa.

Examples
named_type.cpp.

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