]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/type_traits/doc/alignment_of.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / type_traits / doc / alignment_of.qbk
CommitLineData
7c673cae
FG
1[/
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).
6]
7
8[section:alignment_of alignment_of]
9 template <class T>
10 struct alignment_of : public __integral_constant<std::size_t, ALIGNOF(T)> {};
11
12__inherit Class template `alignment_of` inherits from
13`__integral_constant<std::size_t, ALIGNOF(T)>`, where `ALIGNOF(T)` is the
14alignment of type T.
15
16['Note: strictly speaking you should only rely on
17the value of `ALIGNOF(T)` being a multiple of the true alignment of T, although
18in practice it does compute the correct value in all the cases we know about.]
19
20__header ` #include <boost/type_traits/alignment_of.hpp>` or ` #include <boost/type_traits.hpp>`
21
22__examples
23
24[:`alignment_of<int>` inherits from `__integral_constant<std::size_t, ALIGNOF(int)>`.]
25
26[:`alignment_of<char>::type` is the type `__integral_constant<std::size_t, ALIGNOF(char)>`.]
27
28[:`alignment_of<double>::value` is an integral constant
29expression with value `ALIGNOF(double)`.]
30
31[:`alignment_of<T>::value_type` is the type `std::size_t`.]
32
33[important
34Visual C++ users should note that MSVC has varying definitions of "alignment".
35For example consider the following code:
36
37``
38 typedef long long align_t;
39 assert(boost::alignment_of<align_t>::value % 8 == 0);
40 align_t a;
41 assert(((std::uintptr_t)&a % 8) == 0);
42 char c = 0;
43 align_t a1;
44 assert(((std::uintptr_t)&a1 % 8) == 0);
45``
46
47In this code, even though `boost::alignment_of<align_t>` reports that `align_t` has 8-byte
48alignment, the final assert will fail for a 32-bit build because `a1` is not aligned on an
498 byte boundary. Note that had we used the MSVC intrinsic `__alignof` in place of `boost::alignment_of`
50we would still get the same result. In fact for MSVC alignment requirements (and promises) only really
51apply to dynamic storage, and not the stack.
52]
53
54[endsect]
55