OpenVPN 3 Core Library
Loading...
Searching...
No Matches
openvpn::IntrinsicType< BaseT, T > 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 >:
[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.
 
constexpr BaseT operator+= (BaseT arg) noexcept
 Add assignment operator.
 
constexpr BaseT operator-= (BaseT arg) noexcept
 Subtract assignment operator.
 
constexpr BaseT operator*= (BaseT arg) noexcept
 Multiply assignment operator.
 
constexpr BaseT operator/= (BaseT arg) noexcept
 Divide assignment operator.
 
constexpr BaseT & operator|= (BaseT arg) noexcept
 Bitwise OR assignment operator.
 
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
 

Detailed Description

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

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 34 of file intrinsic_type.hpp.

Member Typedef Documentation

◆ value_type

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

Definition at line 36 of file intrinsic_type.hpp.

Constructor & Destructor Documentation

◆ IntrinsicType()

template<typename BaseT , typename T >
constexpr openvpn::IntrinsicType< BaseT, T >::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 43 of file intrinsic_type.hpp.

Member Function Documentation

◆ CrtpBase() [1/2]

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

Const version of helper function to perform CRTP cast.

Returns
Const reference to the derived type

Definition at line 172 of file intrinsic_type.hpp.

◆ CrtpBase() [2/2]

template<typename BaseT , typename T >
BaseT & openvpn::IntrinsicType< BaseT, T >::CrtpBase ( )
inlineprivatenoexcept

Helper function to perform CRTP cast.

Returns
Reference to the derived type

Definition at line 163 of file intrinsic_type.hpp.

Here is the caller graph for this function:

◆ get()

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

Getter for the underlying value.

Returns
The stored value

Definition at line 144 of file intrinsic_type.hpp.

Here is the caller graph for this function:

◆ operator value_type()

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

Conversion operator to value_type.

Returns
The stored value

Definition at line 153 of file intrinsic_type.hpp.

◆ operator&=()

template<typename BaseT , typename T >
constexpr BaseT & openvpn::IntrinsicType< BaseT, T >::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 133 of file intrinsic_type.hpp.

◆ operator*=()

template<typename BaseT , typename T >
constexpr BaseT openvpn::IntrinsicType< BaseT, T >::operator*= ( BaseT  arg)
inlineconstexprnoexcept

Multiply assignment operator.

Parameters
argThe object to multiply
Returns
Reference to the modified object

Definition at line 95 of file intrinsic_type.hpp.

◆ operator+=()

template<typename BaseT , typename T >
constexpr BaseT openvpn::IntrinsicType< BaseT, T >::operator+= ( BaseT  arg)
inlineconstexprnoexcept

Add assignment operator.

Parameters
argThe object to add
Returns
Reference to the modified object

Definition at line 73 of file intrinsic_type.hpp.

◆ operator-=()

template<typename BaseT , typename T >
constexpr BaseT openvpn::IntrinsicType< BaseT, T >::operator-= ( BaseT  arg)
inlineconstexprnoexcept

Subtract assignment operator.

Parameters
argThe object to subtract
Returns
Reference to the modified object

Definition at line 84 of file intrinsic_type.hpp.

◆ operator/=()

template<typename BaseT , typename T >
constexpr BaseT openvpn::IntrinsicType< BaseT, T >::operator/= ( BaseT  arg)
inlineconstexprnoexcept

Divide assignment operator.

Parameters
argThe object to divide
Returns
Reference to the modified object

Definition at line 106 of file intrinsic_type.hpp.

◆ operator=() [1/2]

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

Assignment operator from BaseT.

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

Definition at line 62 of file intrinsic_type.hpp.

◆ operator=() [2/2]

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

Assignment operator from value_type.

Parameters
vThe value to assign
Returns
Reference to the modified object

Definition at line 51 of file intrinsic_type.hpp.

◆ operator|=()

template<typename BaseT , typename T >
constexpr BaseT & openvpn::IntrinsicType< BaseT, T >::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 119 of file intrinsic_type.hpp.

Member Data Documentation

◆ mValue

template<typename BaseT , typename T >
value_type openvpn::IntrinsicType< BaseT, T >::mValue
private

Definition at line 178 of file intrinsic_type.hpp.


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