header_utils
Loading...
Searching...
No Matches
ghassanpl::named< T, PARAMETER, TRAITS > Struct Template Reference

Used to create a strong typedef of T. More...

#include <named.h>

Public Types

using base_type
 The internally stored type.
using self_type
using displacement_type
 If this type is marked as a location of a displacement type, this will be the type; if not, this will be void.

Public Member Functions

template<typename... ARGS>
constexpr named (ARGS &&... args) noexcept(std::is_nothrow_constructible_v< T, ARGS... >)
template<typename U>
constexpr named (U &&arg) noexcept(std::is_nothrow_move_constructible_v< T >)
template<typename U>
constexpr named (U &&arg) noexcept(std::is_nothrow_move_constructible_v< T >)
template<typename U>
constexpr named (U &&arg) noexcept(std::is_nothrow_move_constructible_v< T >)
constexpr named (named const &) noexcept(std::is_nothrow_copy_constructible_v< T >)=default
constexpr named (named &&) noexcept(std::is_nothrow_move_constructible_v< T >)=default
constexpr named & operator= (named const &) noexcept(std::is_nothrow_copy_assignable_v< T >)=default
constexpr named & operator= (named &&) noexcept(std::is_nothrow_move_assignable_v< T >)=default
template<typename U>
constexpr named (U &&arg)
constexpr T & operator* () &noexcept
constexpr T const & operator* () const &noexcept
constexpr T operator* () &&noexcept
constexpr T * operator-> () noexcept
constexpr T const * operator-> () const noexcept
constexpr T & get () &noexcept
constexpr T const & get () const &noexcept
constexpr T get () &&noexcept
template<typename U>
constexpr U as () noexcept
constexpr auto drop () noexcept(std::is_nothrow_move_constructible_v< T >)
template<typename U, detail::FixedString OTHER_PARAMETER, typename... OTHER_CAPABILITIES>
constexpr operator named< U, OTHER_PARAMETER, OTHER_CAPABILITIES... > () const
template<typename U>
constexpr operator U () const
constexpr operator bool () const noexcept
constexpr operator base_type () const noexcept
constexpr auto operator<=> (named const &) const =default
template<typename U>
constexpr auto operator<=> (U const &b) const
template<typename U>
constexpr bool operator== (U const &b) const
constexpr named & operator++ ()
constexpr auto operator+ (self_type const &val) const
constexpr auto operator- () const
constexpr auto operator+ () const
constexpr auto & operator+= (self_type const &val)
constexpr auto operator- (self_type const &val) const
template<typename LOCATION_TYPE>
requires (has_trait<displacement>) && (traits::applies_to<LOCATION_TYPE, location>) && (traits::named_is_displacement_of<self_type, LOCATION_TYPE>) && (addable::applies_to<self_type, LOCATION_TYPE>)
constexpr auto operator+ (LOCATION_TYPE &&val) const
 If we're a displacement, we can be added to a location.
template<typename DISPLACEMENT_TYPE>
requires (has_trait<location>) && (traits::applies_to<DISPLACEMENT_TYPE, displacement>) && (traits::named_is_displacement_of<DISPLACEMENT_TYPE, self_type>) && (addable::applies_to<self_type, DISPLACEMENT_TYPE>)
constexpr auto operator+ (DISPLACEMENT_TYPE &&val) const
 If we're a location, we can be added to a displacement.
template<typename U>
requires has_trait<displacement> && std::constructible_from<T, decltype(std::declval<T>() * std::declval<U>())>
constexpr auto operator* (U &&val) const
template<typename U>
requires has_trait<displacement> && std::constructible_from<T, decltype(std::declval<T>() / std::declval<U>())>
constexpr auto operator/ (U &&val) const
constexpr auto operator/ (self_type const &val) const

Public Attributes

T value

Static Public Attributes

static constexpr detail::FixedString name
template<typename TRAIT, typename... OTHER>
static constexpr bool has_trait

Friends

constexpr auto operator- (self_type const &other, self_type const &self)
template<typename U>
requires has_trait<displacement> && std::constructible_from<T, decltype(std::declval<T>() * std::declval<U>())>
constexpr auto operator* (U &&val, named self)
using subtractable
using location
using displacement

Detailed Description

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
struct ghassanpl::named< T, PARAMETER, TRAITS >

Used to create a strong typedef of T.

By default, it needs to be explicitly constructed from its base type, and is not implicitly convertible to its base type. Most other operations need to be explicitly enabled via the TRAITS template parameter pack.

Usage:

using length = named<double, "length", traits::displacement>;
using position = named<double, "position", traits::location, traits::is_location_of<length>>;
length n = length{10} + length{20}; // OK, lengths are addable
position n2 = position{100} + length{10}; // OK, you can add a position to a length, resulting in a new position
auto nope = position{100} + position{200}; // Will not compile; doesn't make sense to sum positions
length yes = position{200} - position{100}; // OK; subtracting positions will return in a length
This trait implies the named type is an linear type, that is, a type that has the addition operator d...
Definition named.h:62
Used in conjuction with traits::location, specifies which displacement type this is a location of.
Definition named.h:84
This trait implies the named type is an affine type, that is, a type that does not have the addition ...
Definition named.h:57
Note
Using this class involves a trade-off between creating a new type in a declarative style (specifying a base type for storage, and any operations you want this new type to have) and just writing a new struct by hand with all its necessary operators.

Definition at line 132 of file named.h.

Member Typedef Documentation

◆ base_type

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
using ghassanpl::named< T, PARAMETER, TRAITS >::base_type

The internally stored type.

Definition at line 143 of file named.h.

◆ displacement

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
using ghassanpl::named< T, PARAMETER, TRAITS >::displacement

Definition at line 139 of file named.h.

◆ displacement_type

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
using ghassanpl::named< T, PARAMETER, TRAITS >::displacement_type

If this type is marked as a location of a displacement type, this will be the type; if not, this will be void.

Definition at line 211 of file named.h.

◆ location

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
using ghassanpl::named< T, PARAMETER, TRAITS >::location

Definition at line 138 of file named.h.

◆ self_type

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
using ghassanpl::named< T, PARAMETER, TRAITS >::self_type

Definition at line 145 of file named.h.

◆ subtractable

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
using ghassanpl::named< T, PARAMETER, TRAITS >::subtractable

Definition at line 137 of file named.h.

Constructor & Destructor Documentation

◆ named() [1/5]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename... ARGS>
ghassanpl::named< T, PARAMETER, TRAITS >::named ( ARGS &&... args)
inlineexplicitconstexprnoexcept

Definition at line 217 of file named.h.

◆ named() [2/5]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
ghassanpl::named< T, PARAMETER, TRAITS >::named ( U && arg)
inlineconstexprnoexcept

Definition at line 221 of file named.h.

◆ named() [3/5]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
ghassanpl::named< T, PARAMETER, TRAITS >::named ( U && arg)
inlineconstexprnoexcept

Definition at line 228 of file named.h.

◆ named() [4/5]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
ghassanpl::named< T, PARAMETER, TRAITS >::named ( U && arg)
inlineconstexprnoexcept

Definition at line 235 of file named.h.

◆ named() [5/5]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
ghassanpl::named< T, PARAMETER, TRAITS >::named ( U && arg)
inlineconstexpr

Definition at line 248 of file named.h.

Member Function Documentation

◆ as()

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
U ghassanpl::named< T, PARAMETER, TRAITS >::as ( )
inlineconstexprnoexcept

Definition at line 266 of file named.h.

◆ drop()

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
auto ghassanpl::named< T, PARAMETER, TRAITS >::drop ( )
inlineconstexprnoexcept

Definition at line 268 of file named.h.

◆ get() [1/3]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
T ghassanpl::named< T, PARAMETER, TRAITS >::get ( ) &&
inlineconstexprnoexcept

Definition at line 263 of file named.h.

◆ get() [2/3]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
T & ghassanpl::named< T, PARAMETER, TRAITS >::get ( ) &
inlineconstexprnoexcept

Definition at line 261 of file named.h.

◆ get() [3/3]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
T const & ghassanpl::named< T, PARAMETER, TRAITS >::get ( ) const &
inlineconstexprnoexcept

Definition at line 262 of file named.h.

◆ operator base_type()

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
ghassanpl::named< T, PARAMETER, TRAITS >::operator base_type ( ) const
inlineconstexprnoexcept

Definition at line 285 of file named.h.

◆ operator bool()

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
ghassanpl::named< T, PARAMETER, TRAITS >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Definition at line 284 of file named.h.

◆ operator named< U, OTHER_PARAMETER, OTHER_CAPABILITIES... >()

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U, detail::FixedString OTHER_PARAMETER, typename... OTHER_CAPABILITIES>
ghassanpl::named< T, PARAMETER, TRAITS >::operator named< U, OTHER_PARAMETER, OTHER_CAPABILITIES... > ( ) const
inlineconstexpr

Definition at line 272 of file named.h.

◆ operator U()

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
ghassanpl::named< T, PARAMETER, TRAITS >::operator U ( ) const
inlineexplicitconstexpr

Definition at line 279 of file named.h.

◆ operator*() [1/4]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
T ghassanpl::named< T, PARAMETER, TRAITS >::operator* ( ) &&
inlineconstexprnoexcept

Definition at line 256 of file named.h.

◆ operator*() [2/4]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
T & ghassanpl::named< T, PARAMETER, TRAITS >::operator* ( ) &
inlineconstexprnoexcept

Definition at line 254 of file named.h.

◆ operator*() [3/4]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
T const & ghassanpl::named< T, PARAMETER, TRAITS >::operator* ( ) const &
inlineconstexprnoexcept

Definition at line 255 of file named.h.

◆ operator*() [4/4]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
requires has_trait<displacement> && std::constructible_from<T, decltype(std::declval<T>() * std::declval<U>())>
auto ghassanpl::named< T, PARAMETER, TRAITS >::operator* ( U && val) const
inlineconstexpr

Definition at line 365 of file named.h.

◆ operator+() [1/4]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
auto ghassanpl::named< T, PARAMETER, TRAITS >::operator+ ( ) const
inlineconstexpr

Definition at line 314 of file named.h.

◆ operator+() [2/4]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename DISPLACEMENT_TYPE>
requires (has_trait<location>) && (traits::applies_to<DISPLACEMENT_TYPE, displacement>) && (traits::named_is_displacement_of<DISPLACEMENT_TYPE, self_type>) && (addable::applies_to<self_type, DISPLACEMENT_TYPE>)
auto ghassanpl::named< T, PARAMETER, TRAITS >::operator+ ( DISPLACEMENT_TYPE && val) const
inlineconstexpr

If we're a location, we can be added to a displacement.

Definition at line 354 of file named.h.

◆ operator+() [3/4]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename LOCATION_TYPE>
requires (has_trait<displacement>) && (traits::applies_to<LOCATION_TYPE, location>) && (traits::named_is_displacement_of<self_type, LOCATION_TYPE>) && (addable::applies_to<self_type, LOCATION_TYPE>)
auto ghassanpl::named< T, PARAMETER, TRAITS >::operator+ ( LOCATION_TYPE && val) const
inlineconstexpr

If we're a displacement, we can be added to a location.

Definition at line 342 of file named.h.

◆ operator+() [4/4]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
auto ghassanpl::named< T, PARAMETER, TRAITS >::operator+ ( self_type const & val) const
inlineconstexpr

Definition at line 302 of file named.h.

◆ operator++()

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
named & ghassanpl::named< T, PARAMETER, TRAITS >::operator++ ( )
inlineconstexpr

Definition at line 295 of file named.h.

◆ operator+=()

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
auto & ghassanpl::named< T, PARAMETER, TRAITS >::operator+= ( self_type const & val)
inlineconstexpr

Definition at line 320 of file named.h.

◆ operator-() [1/2]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
auto ghassanpl::named< T, PARAMETER, TRAITS >::operator- ( ) const
inlineconstexpr

Definition at line 308 of file named.h.

◆ operator-() [2/2]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
auto ghassanpl::named< T, PARAMETER, TRAITS >::operator- ( self_type const & val) const
inlineconstexpr

Definition at line 334 of file named.h.

◆ operator->() [1/2]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
T const * ghassanpl::named< T, PARAMETER, TRAITS >::operator-> ( ) const
inlineconstexprnoexcept

Definition at line 259 of file named.h.

◆ operator->() [2/2]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
T * ghassanpl::named< T, PARAMETER, TRAITS >::operator-> ( )
inlineconstexprnoexcept

Definition at line 258 of file named.h.

◆ operator/() [1/2]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
auto ghassanpl::named< T, PARAMETER, TRAITS >::operator/ ( self_type const & val) const
inlineconstexpr

Definition at line 385 of file named.h.

◆ operator/() [2/2]

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
requires has_trait<displacement> && std::constructible_from<T, decltype(std::declval<T>() / std::declval<U>())>
auto ghassanpl::named< T, PARAMETER, TRAITS >::operator/ ( U && val) const
inlineconstexpr

Definition at line 379 of file named.h.

◆ operator<=>()

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
auto ghassanpl::named< T, PARAMETER, TRAITS >::operator<=> ( U const & b) const
inlineconstexpr

Definition at line 290 of file named.h.

◆ operator==()

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
bool ghassanpl::named< T, PARAMETER, TRAITS >::operator== ( U const & b) const
inlineconstexpr

Definition at line 292 of file named.h.

◆ operator*

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename U>
requires has_trait<displacement> && std::constructible_from<T, decltype(std::declval<T>() * std::declval<U>())>
auto operator* ( U && val,
named< T, PARAMETER, TRAITS > self )
friend

Definition at line 372 of file named.h.

◆ operator-

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
auto operator- ( self_type const & other,
self_type const & self )
friend

Definition at line 328 of file named.h.

Member Data Documentation

◆ has_trait

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
template<typename TRAIT, typename... OTHER>
bool ghassanpl::named< T, PARAMETER, TRAITS >::has_trait
staticconstexpr

Definition at line 208 of file named.h.

◆ name

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
detail::FixedString ghassanpl::named< T, PARAMETER, TRAITS >::name
staticconstexpr

Definition at line 146 of file named.h.

◆ value

template<typename T, detail::FixedString PARAMETER, typename... TRAITS>
T ghassanpl::named< T, PARAMETER, TRAITS >::value

Definition at line 213 of file named.h.