...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
template <class T> struct alignment_of : public integral_constant<std::size_t, ALIGNOF(T)> {};
Inherits: Class template alignment_of
inherits from integral_constant<std::size_t, ALIGNOF(T)>
,
where ALIGNOF(T)
is the
alignment of type T.
Note: strictly speaking you should only rely on the value of ALIGNOF(T)
being
a multiple of the true alignment of T, although in practice it does compute
the correct value in all the cases we know about.
Header: #include
<boost/type_traits/alignment_of.hpp>
or #include <boost/type_traits.hpp>
Examples:
alignment_of<int>
inherits fromintegral_constant<std::size_t, ALIGNOF(int)>
.
alignment_of<char>::type
is the typeintegral_constant<std::size_t, ALIGNOF(char)>
.
alignment_of<double>::value
is an integral constant expression with valueALIGNOF(double)
.
alignment_of<T>::value_type
is the typestd::size_t
.
Important | |
---|---|
Visual C++ users should note that MSVC has varying definitions of "alignment". For example consider the following code:
typedef long long align_t; assert(boost::alignment_of<align_t>::value % 8 == 0); align_t a; assert(((std::uintptr_t)&a % 8) == 0); char c = 0; align_t a1; assert(((std::uintptr_t)&a1 % 8) == 0);
In this code, even though |