gw  1.0.0
A bunch of small C++ utilities
Loading...
Searching...
No Matches
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.
 
using reference = value_type &
 The type of the reference to the contained value.
 
using const_reference = const value_type &
 The type of the const reference to the contained value.
 
using pointer = value_type *
 The type of the pointer to the contained value.
 
using const_pointer = const value_type *
 The type of the const pointer to the contained value.
 

Public Member Functions

template<typename... Args>
requires std::constructible_from<value_type, Args...>
constexpr named_type (Args &&... args) noexcept(std::is_nothrow_constructible_v< value_type, Args... >)
 Construct the gw::named_type object.
 
template<typename U , typename... Args>
requires std::constructible_from<value_type, std::initializer_list<U>&, Args...>
constexpr named_type (std::initializer_list< U > ilist, Args &&... args) noexcept(std::is_nothrow_constructible_v< value_type, std::initializer_list< U > &, Args... >)
 Construct the gw::named_type object.
 
 ~named_type () noexcept(std::is_nothrow_destructible_v< value_type >)=default
 Destroy the contained value.
 
constexpr auto operator-> () const noexcept -> const_pointer
 Access the contained value.
 
constexpr auto operator-> () noexcept -> pointer
 Access the contained value.
 
constexpr auto operator* () const &noexcept -> const_reference
 Access the contained value.
 
constexpr auto operator* () &noexcept -> reference
 Access the contained value.
 
constexpr auto operator* () const &&noexcept -> const value_type &&
 Access the contained value.
 
constexpr auto operator* () &&noexcept -> value_type &&
 Access the contained value.
 
constexpr auto value () const &noexcept -> const_reference
 Return the contained value.
 
constexpr auto value () &noexcept -> reference
 Return the contained value.
 
constexpr auto value () const &&noexcept -> const value_type &&
 Return the contained value.
 
constexpr auto value () &&noexcept -> value_type &&
 Return the contained value.
 
template<typename F >
requires std::invocable<F, const_reference>
constexpr auto transform (F &&func) const &noexcept(noexcept(func(m_value))) -> named_type
 Return a gw::named_type containing the transformed contained value.
 
template<typename F >
requires std::invocable<F, reference>
constexpr auto transform (F &&func) &noexcept(noexcept(func(m_value))) -> named_type
 Return a gw::named_type containing the transformed contained value.
 
template<typename F >
requires std::invocable<F, const value_type&&>
constexpr auto transform (F &&func) const &&noexcept(noexcept(func(m_value))) -> named_type
 Return a gw::named_type containing the transformed contained value.
 
template<typename F >
requires std::invocable<F, value_type&&>
constexpr auto transform (F &&func) &&noexcept(noexcept(func(m_value))) -> named_type
 Return a gw::named_type containing the transformed contained value.
 
constexpr void swap (named_type &rhs) noexcept(std::is_nothrow_swappable_v< value_type >)
 Specialize the std::swap algorithm.
 
constexpr void reset () noexcept(std::is_nothrow_default_constructible_v< value_type >)
 Destroy any contained value.
 
template<typename... Args>
requires std::constructible_from<value_type, Args...>
constexpr auto emplace (Args &&... args) noexcept(std::is_nothrow_constructible_v< value_type, Args... >) -> reference
 Construct the contained value in-place.
 
constexpr auto operator== (const named_type &rhs) const &noexcept(noexcept(m_value==rhs.m_value)) -> bool
 Compare gw::named_type objects.
 
constexpr auto operator< (const named_type &rhs) const &noexcept(noexcept(m_value< rhs.m_value)) -> bool
 Compare gw::named_type objects.
 
constexpr auto operator> (const named_type &rhs) const &noexcept(noexcept(m_value > rhs.m_value)) -> bool
 Compare gw::named_type objects.
 
constexpr operator const_reference () const &noexcept
 Convert the gw::named_type to its underlying type.
 
constexpr operator reference () &noexcept
 Convert the gw::named_type to its underlying type.
 
constexpr operator const value_type && () const &&noexcept
 Convert the gw::named_type to its underlying type.
 
constexpr operator value_type && () &&noexcept
 Convert the gw::named_type to its underlying type.
 
constexpr auto operator++ () &noexcept(noexcept(++m_value)) -> named_type &
 increments the contained value
 
constexpr auto operator++ () &&noexcept(noexcept(++m_value)) -> named_type &&
 increments the contained value
 
constexpr auto operator++ (int) &noexcept(noexcept(m_value++)) -> named_type
 increments the contained value
 
constexpr auto operator++ (int) &&noexcept(noexcept(m_value++)) -> named_type
 increments the contained value
 
constexpr auto operator-- () &noexcept(noexcept(--m_value)) -> named_type &
 decrements the contained value
 
constexpr auto operator-- () &&noexcept(noexcept(--m_value)) -> named_type &&
 decrements the contained value
 
constexpr auto operator-- (int) &noexcept(noexcept(m_value--)) -> named_type
 decrements the contained value
 
constexpr auto operator-- (int) &&noexcept(noexcept(m_value--)) -> named_type
 decrements the contained value
 
constexpr auto operator+ () const &noexcept(noexcept(+m_value)) -> named_type
 affirms the contained value
 
constexpr auto operator+ () &&noexcept(noexcept(+m_value)) -> named_type
 affirms the contained value
 
constexpr auto operator- () const &noexcept(noexcept(-m_value)) -> named_type
 negates the contained value
 
constexpr auto operator- () &&noexcept(noexcept(-m_value)) -> named_type
 negates the contained value
 
constexpr auto operator+ (const named_type &rhs) const &noexcept(noexcept(m_value+rhs.m_value)) -> named_type
 adds the contained values
 
constexpr auto operator+ (named_type &&rhs) const &noexcept(noexcept(m_value+rhs.m_value)) -> named_type
 adds the contained values
 
constexpr auto operator+ (const named_type &rhs) &&noexcept(noexcept(m_value+rhs.m_value)) -> named_type
 adds the contained values
 
constexpr auto operator+ (named_type &&rhs) &&noexcept(noexcept(m_value+rhs.m_value)) -> named_type
 adds the contained values
 
constexpr auto operator- (const named_type &rhs) const &noexcept(noexcept(m_value - rhs.m_value)) -> named_type
 subtracts the contained values
 
constexpr auto operator- (named_type &&rhs) const &noexcept(noexcept(m_value - rhs.m_value)) -> named_type
 subtracts the contained values
 
constexpr auto operator- (const named_type &rhs) &&noexcept(noexcept(m_value - rhs.m_value)) -> named_type
 subtracts the contained values
 
constexpr auto operator- (named_type &&rhs) &&noexcept(noexcept(m_value - rhs.m_value)) -> named_type
 subtracts the contained values
 
constexpr auto operator* (const named_type &rhs) const &noexcept(noexcept(m_value *rhs.m_value)) -> named_type
 multiplies the contained values
 
constexpr auto operator* (named_type &&rhs) const &noexcept(noexcept(m_value *rhs.m_value)) -> named_type
 multiplies the contained values
 
constexpr auto operator* (const named_type &rhs) &&noexcept(noexcept(m_value *rhs.m_value)) -> named_type
 multiplies the contained values
 
constexpr auto operator* (named_type &&rhs) &&noexcept(noexcept(m_value *rhs.m_value)) -> named_type
 multiplies the contained values
 
constexpr auto operator/ (const named_type &rhs) const &noexcept(noexcept(m_value/rhs.m_value)) -> named_type
 devides the contained values
 
constexpr auto operator/ (named_type &&rhs) const &noexcept(noexcept(m_value/rhs.m_value)) -> named_type
 devides the contained values
 
constexpr auto operator/ (const named_type &rhs) &&noexcept(noexcept(m_value/rhs.m_value)) -> named_type
 devides the contained values
 
constexpr auto operator/ (named_type &&rhs) &&noexcept(noexcept(m_value/rhs.m_value)) -> named_type
 devides the contained values
 
constexpr auto operator% (const named_type &rhs) const &noexcept(noexcept(m_value % rhs.m_value)) -> named_type
 calculates the remainder of the contained values
 
constexpr auto operator% (named_type &&rhs) const &noexcept(noexcept(m_value % rhs.m_value)) -> named_type
 calculates the remainder of the contained values
 
constexpr auto operator% (const named_type &rhs) &&noexcept(noexcept(m_value % rhs.m_value)) -> named_type
 calculates the remainder of the contained values
 
constexpr auto operator% (named_type &&rhs) &&noexcept(noexcept(m_value % rhs.m_value)) -> named_type
 calculates the remainder of the contained values
 
constexpr auto operator~ () const &noexcept(noexcept(~m_value)) -> named_type
 inverts the contained value
 
constexpr auto operator& (const named_type &rhs) const &noexcept(noexcept(m_value &rhs.m_value)) -> named_type
 performs binary AND on the contained values
 
constexpr auto operator& (named_type &&rhs) const &noexcept(noexcept(m_value &rhs.m_value)) -> named_type
 performs binary AND on the contained values
 
constexpr auto operator& (const named_type &rhs) &&noexcept(noexcept(m_value &rhs.m_value)) -> named_type
 performs binary AND on the contained values
 
constexpr auto operator& (named_type &&rhs) &&noexcept(noexcept(m_value &rhs.m_value)) -> named_type
 performs binary AND on the contained values
 
constexpr auto operator| (const named_type &rhs) const &noexcept(noexcept(m_value|rhs.m_value)) -> named_type
 performs binary OR on the contained values
 
constexpr auto operator| (named_type &&rhs) const &noexcept(noexcept(m_value|rhs.m_value)) -> named_type
 performs binary OR on the contained values
 
constexpr auto operator| (const named_type &rhs) &&noexcept(noexcept(m_value|rhs.m_value)) -> named_type
 performs binary OR on the contained values
 
constexpr auto operator| (named_type &&rhs) &&noexcept(noexcept(m_value|rhs.m_value)) -> named_type
 performs binary OR on the contained values
 
constexpr auto operator^ (const named_type &rhs) const &noexcept(noexcept(m_value ^ rhs.m_value)) -> named_type
 performs binary XOR on the contained values
 
constexpr auto operator^ (named_type &&rhs) const &noexcept(noexcept(m_value ^ rhs.m_value)) -> named_type
 performs binary XOR on the contained values
 
constexpr auto operator^ (const named_type &rhs) &&noexcept(noexcept(m_value ^ rhs.m_value)) -> named_type
 performs binary XOR on the contained values
 
constexpr auto operator^ (named_type &&rhs) &&noexcept(noexcept(m_value ^ rhs.m_value)) -> named_type
 performs binary XOR on the contained values
 
constexpr auto operator<< (const named_type &rhs) const &noexcept(noexcept(m_value<< rhs.m_value)) -> named_type
 performs binary left shift on the contained values
 
constexpr auto operator<< (named_type &&rhs) const &noexcept(noexcept(m_value<< rhs.m_value)) -> named_type
 performs binary left shift on the contained values
 
constexpr auto operator<< (const named_type &rhs) &&noexcept(noexcept(m_value<< rhs.m_value)) -> named_type
 performs binary left shift on the contained values
 
constexpr auto operator<< (named_type &&rhs) &&noexcept(noexcept(m_value<< rhs.m_value)) -> named_type
 performs binary left shift on the contained values
 
constexpr auto operator>> (const named_type &rhs) const &noexcept(noexcept(m_value > > rhs.m_value)) -> named_type
 performs binary right shift on the contained values
 
constexpr auto operator>> (named_type &&rhs) const &noexcept(noexcept(m_value > > rhs.m_value)) -> named_type
 performs binary right shift on the contained values
 
constexpr auto operator>> (const named_type &rhs) &&noexcept(noexcept(m_value > > rhs.m_value)) -> named_type
 performs binary right shift on the contained values
 
constexpr auto operator>> (named_type &&rhs) &&noexcept(noexcept(m_value > > rhs.m_value)) -> named_type
 performs binary right shift on the contained values
 
constexpr auto begin () const noexcept(noexcept(std::ranges::begin(m_value)))
 returns an iterator to the beginning of the contained value
 
constexpr auto begin () noexcept(noexcept(std::ranges::begin(m_value)))
 returns an iterator to the beginning of the contained value
 
constexpr auto end () const noexcept(noexcept(std::ranges::end(m_value)))
 returns an iterator to the end of the contained value
 
constexpr auto end () noexcept(noexcept(std::ranges::end(m_value)))
 returns an iterator to the end of the contained value
 

Static Public Member Functions

static constexpr auto name () noexcept
 Return the name of the gw::named_type.
 

Friends

auto operator<< (std::ostream &ostream, const named_type &rhs) noexcept(noexcept(ostream<< rhs.m_value)) -> std::ostream &
 inserts formatted data
 
auto operator>> (std::istream &istream, named_type &rhs) noexcept(noexcept(istream > > rhs.m_value)) -> std::istream &
 extracts formatted data
 

Detailed Description

template<typename T, basic_inplace_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_example.cpp.

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