<xstd/ints/memory/align_down.hpp>¶
xstd::align_down¶
// (1)
template<alignable T>
constexpr auto align_down(T value, size_t alignment) noexcept(nothrow_alignable<T>) -> T;
// (2)
template<class T>
auto align_down(T* pointer, size_t alignment) noexcept -> T*;
Rounds down to a multiple of a power-of-two alignment.
- For an
alignablevalue. - For a pointer, through its address.
Parameters¶
| Parameter | Meaning |
|---|---|
value |
the value to round down |
pointer |
the pointer whose address is rounded down |
alignment |
a power of two |
Constraints: (1) T models alignable.
Preconditions: (1) alignment is a power of two.
Return value¶
- Returns: The greatest multiple of
alignmentnot greater thanvalue, as aT, computed asvalue - (value & m)form = T(alignment - 1). A narrow type is returned as itself. It is a constant expression. - Effects: Equivalent to
return reinterpret_cast<T*>(align_down(reinterpret_cast<uintptr_t>(pointer), alignment));.
Exceptions¶
- The exception specification is
nothrow_alignable<T>:noexceptforsize_tanduint8_t, and not forabsl::uint128. - As for
align_up's pointer form.
Remarks¶
(2) As for align_up's pointer form.
Notes¶
- (1) It is exact at the maximum of
size_t. - (2) It returns a
T*.
See also¶
| Entity | Relation |
|---|---|
align_up |
rounds up instead |
is_aligned |
holds of what it returns, and of value exactly when it leaves it unchanged |
alignable |
what (1) asks of T |
boost::alignment::align_down |
the Boost.Align function it agrees with |