Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::AlignedStorage< N, Alignment > Struct Template Reference

A buffer of bytes with given alignment. More...

#include <AlignedStorage.h>

Public Member Functions

template<typename T >
T & reinterpret_as ()
 Access wanted OS Handle with it's actual type. More...
 
template<typename T >
const T & reinterpret_as () const
 Access wanted OS Handle with it's actual type. More...
 

Detailed Description

template<int N, int Alignment = alignof(void*)>
struct SC::AlignedStorage< N, Alignment >

A buffer of bytes with given alignment.

Typically used in PIMPL or similar mechanisms to hide OS Specific system includes. For example it's used used to wrap SocketIPAddress, a Mutex and ConditionVariable.

Template Parameters
NSize in bytes of the Operating System Handle
AlignmentAlignment in Bytes of the operating system Handle

Member Function Documentation

◆ reinterpret_as() [1/2]

template<int N, int Alignment = alignof(void*)>
template<typename T >
T & SC::AlignedStorage< N, Alignment >::reinterpret_as ( )
inline

Access wanted OS Handle with it's actual type.

This is typically done in a .cpp file where the concrete type of the Handle is known For example it is used inside Mutex class like:

pthread_mutex_t& myMutes = handle.reinterpret_as<pthread_mutex_t>()
Template Parameters
TType of the handle. It will statically check size and alignment of requested type.
Returns
A reference to actual OS handle

◆ reinterpret_as() [2/2]

template<int N, int Alignment = alignof(void*)>
template<typename T >
const T & SC::AlignedStorage< N, Alignment >::reinterpret_as ( ) const
inline

Access wanted OS Handle with it's actual type.

This is typically done in a .cpp file where the concrete type of the Handle is known For example it is used inside Mutex class like:

pthread_mutex_t& myMutes = handle.reinterpret_as<pthread_mutex_t>()
Template Parameters
TType of the handle. It will statically check size and alignment of requested type.
Returns
A reference to actual OS handle

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