OGS
BaseLib::StrongType< T, Tag > Struct Template Reference

Detailed Description

template<typename T, typename Tag>
struct BaseLib::StrongType< T, Tag >

A "strong" version of the underlying type T.

Strong types with same T but different tag are not implicitly convertible to each other, and are not implicitly convertible to/from T. Based on these properties strong types can serve as an ingredient for safer APIs.

Definition at line 24 of file StrongType.h.

#include <StrongType.h>

Public Member Functions

constexpr StrongType () noexcept(std::is_nothrow_default_constructible_v< T >)
 
constexpr StrongType (T const &value) noexcept(std::is_nothrow_copy_constructible_v< T >)
 
constexpr StrongType (T &&value) noexcept(std::is_nothrow_move_constructible_v< T >)
 
constexpr T & operator() () noexcept
 
constexpr T const & operator() () const noexcept
 
constexpr T & operator* () noexcept
 
constexpr T const & operator* () const noexcept
 
constexpr T * operator-> () noexcept
 Value access.
 
constexpr T const * operator-> () const noexcept
 

Private Attributes

value_
 

Constructor & Destructor Documentation

◆ StrongType() [1/3]

template<typename T , typename Tag >
BaseLib::StrongType< T, Tag >::StrongType ( )
inlineconstexprnoexcept

Definition at line 47 of file StrongType.h.

48 : value_{} // "zero initialization"
49 {
50 }

◆ StrongType() [2/3]

template<typename T , typename Tag >
BaseLib::StrongType< T, Tag >::StrongType ( T const & value)
inlineexplicitconstexprnoexcept

Definition at line 52 of file StrongType.h.

54 : value_{value}
55 {
56 }

◆ StrongType() [3/3]

template<typename T , typename Tag >
BaseLib::StrongType< T, Tag >::StrongType ( T && value)
inlineexplicitconstexprnoexcept

Definition at line 58 of file StrongType.h.

60 : value_{std::move(value)}
61 {
62 }

Member Function Documentation

◆ operator()() [1/2]

template<typename T , typename Tag >
T const & BaseLib::StrongType< T, Tag >::operator() ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 67 of file StrongType.h.

68 {
69 return value_;
70 }

References BaseLib::StrongType< T, Tag >::value_.

◆ operator()() [2/2]

template<typename T , typename Tag >
T & BaseLib::StrongType< T, Tag >::operator() ( )
inlinenodiscardconstexprnoexcept

Value access. Alternative to operator*, operator() might look clearer in mathematical expressions.

Definition at line 66 of file StrongType.h.

66{ return this->value_; }

References BaseLib::StrongType< T, Tag >::value_.

◆ operator*() [1/2]

template<typename T , typename Tag >
T const & BaseLib::StrongType< T, Tag >::operator* ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 75 of file StrongType.h.

76 {
77 return value_;
78 }

References BaseLib::StrongType< T, Tag >::value_.

◆ operator*() [2/2]

template<typename T , typename Tag >
T & BaseLib::StrongType< T, Tag >::operator* ( )
inlinenodiscardconstexprnoexcept

Value access. Alternative to operator(). Introduced for symmetry reasons as a companion to operator->.

Definition at line 74 of file StrongType.h.

74{ return this->value_; }

References BaseLib::StrongType< T, Tag >::value_.

◆ operator->() [1/2]

template<typename T , typename Tag >
T const * BaseLib::StrongType< T, Tag >::operator-> ( ) const
inlinenodiscardconstexprnoexcept

Definition at line 82 of file StrongType.h.

83 {
84 return &value_;
85 }

References BaseLib::StrongType< T, Tag >::value_.

◆ operator->() [2/2]

template<typename T , typename Tag >
T * BaseLib::StrongType< T, Tag >::operator-> ( )
inlinenodiscardconstexprnoexcept

Value access.

Definition at line 81 of file StrongType.h.

81{ return &this->value_; }

References BaseLib::StrongType< T, Tag >::value_.

Member Data Documentation

◆ value_


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