pstore2
Functions
aligned.hpp File Reference

Functions for aligning values and pointers. More...

#include <cstdint>
#include <type_traits>
#include "pstore/support/assert.hpp"
Include dependency graph for aligned.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename Ty , typename = typename std::enable_if<std::is_unsigned<Ty>::value>>
constexpr bool pstore::is_power_of_two (Ty const n) noexcept
 
template<typename IntType , typename AlignType >
constexpr IntType pstore::aligned (IntType const v, AlignType const align) noexcept
 
template<typename AlignType , typename IntType , typename = std::enable_if<std::is_integral<IntType>::value>>
constexpr IntType pstore::aligned (IntType const v) noexcept
 
template<typename PointeeType >
constexpr PointeeType const * pstore::aligned (void const *const p) noexcept
 
template<typename PointeeType >
constexpr PointeeType * pstore::aligned (void *const p) noexcept
 
template<typename DestPointeeType , typename SrcPointeeType = DestPointeeType>
constexpr DestPointeeType const * pstore::aligned_ptr (SrcPointeeType const *const p) noexcept
 
template<typename DestPointeeType , typename SrcPointeeType = DestPointeeType>
constexpr DestPointeeType * pstore::aligned_ptr (SrcPointeeType *const p) noexcept
 
template<typename Ty >
constexpr Ty pstore::calc_alignment (Ty const v, std::size_t const align) noexcept
 Calculate the value that must be added to p v in order that it has the alignment given by align. More...
 
template<typename Ty >
constexpr Ty pstore::calc_alignment (Ty const v) noexcept
 Calculate the value that must be added to v in order for it to have the alignment required by type Ty. More...
 

Detailed Description

Functions for aligning values and pointers.

Function Documentation

◆ aligned() [1/2]

template<typename IntType , typename AlignType >
constexpr IntType pstore::aligned ( IntType const  v,
AlignType const  align 
)
noexcept
Parameters
vThe value to be aligned.
alignThe alignment required for v.
Returns
The value closest to but greater than or equal to v for which v modulo align is zero.

◆ aligned() [2/2]

template<typename AlignType , typename IntType , typename = std::enable_if<std::is_integral<IntType>::value>>
constexpr IntType pstore::aligned ( IntType const  v)
noexcept
Parameters
vThe value to be aligned.
Returns
The value closest to but greater than or equal to v for which v modulo alignof(decltype(v)) is zero.

◆ calc_alignment() [1/2]

template<typename Ty >
constexpr Ty pstore::calc_alignment ( Ty const  v,
std::size_t const  align 
)
noexcept

Calculate the value that must be added to p v in order that it has the alignment given by align.

Parameters
vThe value to be aligned.
alignThe alignment required for v.
Returns
The value that must be added to v in order that it has the alignment given by align.

◆ calc_alignment() [2/2]

template<typename Ty >
constexpr Ty pstore::calc_alignment ( Ty const  v)
noexcept

Calculate the value that must be added to v in order for it to have the alignment required by type Ty.

Parameters
vThe value to be aligned.
Returns
The value that must be added to v in order that it has the alignment required by type Ty.

◆ is_power_of_two()

template<typename Ty , typename = typename std::enable_if<std::is_unsigned<Ty>::value>>
constexpr bool pstore::is_power_of_two ( Ty const  n)
noexcept
Returns
True if the input value is a power of 2.