<xstd/ints/memory/is_aligned.hpp>¶
xstd::is_aligned¶
// (1)
template<alignable T>
constexpr auto is_aligned(T value, size_t alignment) noexcept(nothrow_alignable<T>) -> bool;
// (2)
template<class T>
auto is_aligned(T* pointer, size_t alignment) noexcept -> bool;
Whether a value is a multiple of a power-of-two alignment.
- For an
alignablevalue. - For a pointer, through its address.
Parameters¶
| Parameter | Meaning |
|---|---|
value |
the value to test |
pointer |
the pointer whose address is tested |
alignment |
a power of two |
Constraints: (1) T models alignable.
Preconditions: (1) alignment is a power of two.
Return value¶
- Returns:
trueexactly whenvalueis a multiple ofalignment, computed asT(value & m) == T(0UZ)form = T(alignment - 1), as aboolwhateverTis. It is a constant expression. - Returns:
is_aligned(reinterpret_cast<uintptr_t>(pointer), alignment).
Exceptions¶
- The exception specification is
nothrow_alignable<T>:noexceptforsize_tanduint8_t, and not forabsl::uint128. - It is
noexcept.
Remarks¶
(2) It is not constexpr.
Notes¶
(1) It holds of what align_up and align_down return, and of value exactly when align_down leaves it unchanged.
See also¶
| Entity | Relation |
|---|---|
align_up, align_down |
what they return satisfies it |
alignable |
what (1) asks of T |
boost::alignment::is_aligned |
the Boost.Align function it agrees with |