libstdc++
GNU C++ library
Loading...
Searching...
No Matches

◆ assume_aligned() [1/2]

template<size_t _Align, class _Tp>
_Tp * std::assume_aligned ( _Tp * __ptr)
nodiscardconstexprnoexcept

Inform the compiler that a pointer is aligned.

Template Parameters
_AlignAn alignment value (i.e. a power of two)
_TpAn object type
Parameters
__ptrA pointer that is aligned to _Align

C++20 20.10.6 [ptr.align]

Definition at line 90 of file align.h.

91 {
92 static_assert(std::has_single_bit(_Align));
93 if (std::is_constant_evaluated())
94 return __ptr;
95 else
96 {
97 // This function is expected to be used in hot code, where
98 // __glibcxx_assert would add unwanted overhead.
99 _GLIBCXX_DEBUG_ASSERT((__UINTPTR_TYPE__)__ptr % _Align == 0);
100 return static_cast<_Tp*>(__builtin_assume_aligned(__ptr, _Align));
101 }
102 }
#define _GLIBCXX_DEBUG_ASSERT(_Condition)
Definition assertions.h:65

References _GLIBCXX_DEBUG_ASSERT, and assume_aligned().

Referenced by assume_aligned().

Here is the call graph for this function:
Here is the caller graph for this function: