<xstd/ints/memory/align_up.hpp>¶
xstd::align_up¶
// (1)
template<alignable T>
constexpr auto align_up(T value, size_t alignment) noexcept(nothrow_alignable<T>) -> T;
// (2)
template<class T>
auto align_up(T* pointer, size_t alignment) noexcept -> T*;
Rounds up 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 up |
pointer |
the pointer whose address is rounded up |
alignment |
a power of two |
Constraints: (1) T models alignable. A signed integer-class type is turned away rather than converted.
Preconditions: (1) alignment is a power of two, and value + (alignment - 1) does not wrap in T, so the result is
representable.
Return value¶
- Returns: The least multiple of
alignmentnot less thanvalue, as aT, computed ass - (s & m)form = T(alignment - 1)ands = value + m. A narrow type is returned as itself rather than promoted. It is a constant expression. - Effects: Equivalent to
return reinterpret_cast<T*>(align_up(reinterpret_cast<uintptr_t>(pointer), alignment));so it answers as Boost.Align's pointer form does and has the integer form's preconditions.
Exceptions¶
- The exception specification is
nothrow_alignable<T>:noexceptforsize_tanduint8_t, and not forabsl::uint128. - It is
noexcept.
Remarks¶
- (2):
- It is not
constexpr, areinterpret_castbeing barred from constant expressions. - The result is an address: it is not checked against the object
pointerpoints into, and no object's lifetime begins there.
- It is not
Notes¶
- (1):
- It is exact up to the greatest multiple of
alignmentthatsize_trepresents. - It takes
uint128.
- It is exact up to the greatest multiple of
- (2):
- It returns a
T*, keeping the pointee type where Boost.Align returnsvoid*.
- It returns a
See also¶
| Entity | Relation |
|---|---|
align_down |
rounds down instead |
is_aligned |
holds of what it returns |
alignable |
what (1) asks of T |
boost::alignment::align_up |
the Boost.Align function it agrees with |