2 Copyright 2007 John Maddock.
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt).
8 [section:alignment_of alignment_of]
10 struct alignment_of : public __integral_constant<std::size_t, ALIGNOF(T)> {};
12 __inherit Class template `alignment_of` inherits from
13 `__integral_constant<std::size_t, ALIGNOF(T)>`, where `ALIGNOF(T)` is the
16 ['Note: strictly speaking you should only rely on
17 the value of `ALIGNOF(T)` being a multiple of the true alignment of T, although
18 in practice it does compute the correct value in all the cases we know about.]
20 __header ` #include <boost/type_traits/alignment_of.hpp>` or ` #include <boost/type_traits.hpp>`
24 [:`alignment_of<int>` inherits from `__integral_constant<std::size_t, ALIGNOF(int)>`.]
26 [:`alignment_of<char>::type` is the type `__integral_constant<std::size_t, ALIGNOF(char)>`.]
28 [:`alignment_of<double>::value` is an integral constant
29 expression with value `ALIGNOF(double)`.]
31 [:`alignment_of<T>::value_type` is the type `std::size_t`.]
34 Visual C++ users should note that MSVC has varying definitions of "alignment".
35 For example consider the following code:
38 typedef long long align_t;
39 assert(boost::alignment_of<align_t>::value % 8 == 0);
41 assert(((std::uintptr_t)&a % 8) == 0);
44 assert(((std::uintptr_t)&a1 % 8) == 0);
47 In this code, even though `boost::alignment_of<align_t>` reports that `align_t` has 8-byte
48 alignment, the final assert will fail for a 32-bit build because `a1` is not aligned on an
49 8 byte boundary. Note that had we used the MSVC intrinsic `__alignof` in place of `boost::alignment_of`
50 we would still get the same result. In fact for MSVC alignment requirements (and promises) only really
51 apply to dynamic storage, and not the stack.