OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::IntrinsicType< BaseT, T, typename > Struct Template Reference

CRTP type designed to allow creation of strong types based on intrinsics. More...

#include <intrinsic_type.hpp>

Inheritance diagram for openvpn::IntrinsicType< BaseT, T, typename >:
[legend]

Public Types

using value_type = T
 

Public Member Functions

constexpr IntrinsicType (value_type v=value_type()) noexcept
 Constructs an IntrinsicType object.
 
BaseT & operator= (value_type v)
 Assignment operator from value_type.
 
BaseT & operator= (BaseT arg) noexcept
 Assignment operator from BaseT.
 
template<typename = std::enable_if_t<std::is_integral_v<T>>>
constexpr BaseT & operator|= (BaseT arg) noexcept
 Bitwise OR assignment operator.
 
template<typename = std::enable_if_t<std::is_integral_v<T>>>
constexpr BaseT & operator&= (BaseT arg) noexcept
 Bitwise AND assignment operator.
 
constexpr value_type get () const noexcept
 Getter for the underlying value.
 
constexpr operator value_type () const noexcept
 Conversion operator to value_type.
 

Private Member Functions

BaseT & CrtpBase () noexcept
 Helper function to perform CRTP cast.
 
const BaseT & CrtpBase () const noexcept
 Const version of helper function to perform CRTP cast.
 

Private Attributes

value_type mValue
 

Friends

constexpr bool operator== (const BaseT lhs, const BaseT rhs) noexcept
 Equality operator - class friend.
 

Detailed Description

template<typename BaseT, typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
struct openvpn::IntrinsicType< BaseT, T, typename >

CRTP type designed to allow creation of strong types based on intrinsics.

Template Parameters
BaseTThe final type name
TThe value type

The IntrinsicType template struct is designed to encapsulate a value of type T and provide a set of operations for manipulating this value. The struct uses the Curiously Recurring Template Pattern (CRTP) to enable static polymorphism, where BaseT is the derived type that inherits from IntrinsicType.

This enables an arithmetic type to be essentially used as a base type for a new strong type, which can be used to enforce type safety and prevent accidental misuse of the underlying value. The struct provides a set of operators for bitwise operations, and could be extended to provide additional operators as needed.

Definition at line 33 of file intrinsic_type.hpp.

Member Typedef Documentation

◆ value_type

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
using openvpn::IntrinsicType< BaseT, T, typename >::value_type = T

Definition at line 35 of file intrinsic_type.hpp.

Constructor & Destructor Documentation

◆ IntrinsicType()

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr openvpn::IntrinsicType< BaseT, T, typename >::IntrinsicType ( value_type  v = value_type())
inlineexplicitconstexprnoexcept

Constructs an IntrinsicType object.

Parameters
vThe value to initialize the object with
Note
Default constructs the value_type if no parameter is provided

Definition at line 42 of file intrinsic_type.hpp.

Member Function Documentation

◆ CrtpBase() [1/2]

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
const BaseT & openvpn::IntrinsicType< BaseT, T, typename >::CrtpBase ( ) const
inlineprivatenoexcept

Const version of helper function to perform CRTP cast.

Returns
Const reference to the derived type

Definition at line 138 of file intrinsic_type.hpp.

◆ CrtpBase() [2/2]

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
BaseT & openvpn::IntrinsicType< BaseT, T, typename >::CrtpBase ( )
inlineprivatenoexcept

Helper function to perform CRTP cast.

Returns
Reference to the derived type

Definition at line 129 of file intrinsic_type.hpp.

Here is the caller graph for this function:

◆ get()

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr value_type openvpn::IntrinsicType< BaseT, T, typename >::get ( ) const
inlineconstexprnoexcept

Getter for the underlying value.

Returns
The stored value

Definition at line 110 of file intrinsic_type.hpp.

Here is the caller graph for this function:

◆ operator value_type()

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr openvpn::IntrinsicType< BaseT, T, typename >::operator value_type ( ) const
inlineconstexprnoexcept

Conversion operator to value_type.

Returns
The stored value

Definition at line 119 of file intrinsic_type.hpp.

◆ operator&=()

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
template<typename = std::enable_if_t<std::is_integral_v<T>>>
constexpr BaseT & openvpn::IntrinsicType< BaseT, T, typename >::operator&= ( BaseT  arg)
inlineconstexprnoexcept

Bitwise AND assignment operator.

Parameters
argThe object to AND with
Returns
Reference to the modified object
Note
This operator is marked constexpr and noexcept, and is enabled only for integral types

Definition at line 100 of file intrinsic_type.hpp.

◆ operator=() [1/2]

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
BaseT & openvpn::IntrinsicType< BaseT, T, typename >::operator= ( BaseT  arg)
inlinenoexcept

Assignment operator from BaseT.

Parameters
argThe object to assign from
Returns
Reference to the modified object

Definition at line 72 of file intrinsic_type.hpp.

◆ operator=() [2/2]

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
BaseT & openvpn::IntrinsicType< BaseT, T, typename >::operator= ( value_type  v)
inline

Assignment operator from value_type.

Parameters
vThe value to assign
Returns
Reference to the modified object

Definition at line 50 of file intrinsic_type.hpp.

◆ operator|=()

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
template<typename = std::enable_if_t<std::is_integral_v<T>>>
constexpr BaseT & openvpn::IntrinsicType< BaseT, T, typename >::operator|= ( BaseT  arg)
inlineconstexprnoexcept

Bitwise OR assignment operator.

Parameters
argThe object to OR with
Returns
Reference to the modified object
Note
This operator is marked constexpr and noexcept, and is enabled only for integral types

Definition at line 86 of file intrinsic_type.hpp.

Friends And Related Symbol Documentation

◆ operator==

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
constexpr bool operator== ( const BaseT  lhs,
const BaseT  rhs 
)
friend

Equality operator - class friend.

Parameters
lhsLeft argument
rhsRight argument
Returns
true if the underlying are equal otehrwise false

Definition at line 62 of file intrinsic_type.hpp.

Member Data Documentation

◆ mValue

template<typename BaseT , typename T , typename = std::enable_if_t<std::is_arithmetic_v<T>>>
value_type openvpn::IntrinsicType< BaseT, T, typename >::mValue
private

Definition at line 144 of file intrinsic_type.hpp.


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