std::is_sufficiently_aligned
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Memory management library
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
Garbage collector support (until C++23)
(exposition only*)
(C++11)
(C++23)
(C++11)
(C++17)
(C++11)
(C++11)
(C++20)
(C++20)
(C++17)
(C++11)
(C++17)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(until C++20*)
(until C++20*)
(until C++20*)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)
(C++11)
(C++17)
(C++20)
(C++17)
(C++11)
(C++11)
(C++11)
(until C++17*)
(C++11)
(C++17)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++11)
(C++20)
(C++11)
(C++11)
(C++20)
is_sufficiently_aligned
(C++26)
Defined in header
<memory>
template< std::size_t N, class T >
bool is_sufficiently_aligned( T* ptr );
(since C++26)
bool is_sufficiently_aligned( T* ptr );
Checks whether the pointer ptr points to an object whose alignment has a value of at least N.
The behavior is undefined if ptr does not point to an object of type T
(ignoring cv-qualification at every level).
[edit] Return value
true if ptr points to an object that has alignment at least N; otherwise false.
[edit] Exceptions
Throws nothing.
[edit] Notes
std::is_sufficiently_aligned
can be used as a precondition to std::assume_aligned .
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_is_sufficiently_aligned |
202411L |
(C++26) | std::is_sufficiently_aligned
|
[edit] Possible implementation
template<std::size_t N, class T> bool is_sufficiently_aligned(T* ptr) { return std::bit_cast <std::uintptr_t >(ptr) % N == 0; }
[edit] Example
This section is incomplete
Reason: no example
Reason: no example
[edit] See also
alignas
(C++11)
specifies that the storage for the variable should be aligned by specific amount(specifier)[edit]
(since C++11)(deprecated in C++23)
(class template) [edit]