]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Metafunctions/Miscellaneous//sizeof_ |100 |
2 | ||
3 | sizeof\_ | |
4 | ======== | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename X | |
13 | > | |
14 | struct sizeof\_ | |
15 | { | |
16 | typedef |unspecified| type; | |
17 | }; | |
18 | ||
19 | ||
20 | ||
21 | Description | |
22 | ----------- | |
23 | ||
24 | Returns the result of a ``sizeof(X)`` expression wrapped into an | |
25 | |Integral Constant| of the corresponding type, ``std::size_t``. | |
26 | ||
27 | ||
28 | Header | |
29 | ------ | |
30 | ||
31 | .. parsed-literal:: | |
32 | ||
33 | #include <boost/mpl/sizeof.hpp> | |
34 | ||
35 | ||
36 | Model of | |
37 | -------- | |
38 | ||
39 | |Metafunction| | |
40 | ||
41 | ||
42 | Parameters | |
43 | ---------- | |
44 | ||
45 | +---------------+-------------------+-------------------------------------------+ | |
46 | | Parameter | Requirement | Description | | |
47 | +===============+===================+===========================================+ | |
48 | | ``X`` | Any type | A type to compute the ``sizeof`` for. | | |
49 | +---------------+-------------------+-------------------------------------------+ | |
50 | ||
51 | ||
52 | Expression semantics | |
53 | -------------------- | |
54 | ||
55 | For an arbitrary type ``x``: | |
56 | ||
57 | ||
58 | .. parsed-literal:: | |
59 | ||
60 | typedef sizeof_<x>::type n; | |
61 | ||
62 | ||
63 | :Return type: | |
64 | |Integral Constant|. | |
65 | ||
66 | :Precondition: | |
67 | ``x`` is a complete type. | |
68 | ||
69 | :Semantics: | |
70 | Equivalent to | |
71 | ||
72 | .. parsed-literal:: | |
73 | ||
74 | typedef size_t< sizeof(x) > n; | |
75 | ||
76 | ||
77 | ||
78 | Complexity | |
79 | ---------- | |
80 | ||
81 | Constant time. | |
82 | ||
83 | ||
84 | Example | |
85 | ------- | |
86 | ||
87 | .. parsed-literal:: | |
88 | ||
89 | struct udt { char a[100]; }; | |
90 | ||
91 | BOOST_MPL_ASSERT_RELATION( sizeof_<char>::value, ==, sizeof(char) ); | |
92 | BOOST_MPL_ASSERT_RELATION( sizeof_<int>::value, ==, sizeof(int) ); | |
93 | BOOST_MPL_ASSERT_RELATION( sizeof_<double>::value, ==, sizeof(double) ); | |
94 | BOOST_MPL_ASSERT_RELATION( sizeof_<udt>::value, ==, sizeof(my) ); | |
95 | ||
96 | ||
97 | See also | |
98 | -------- | |
99 | ||
100 | |Metafunctions|, |Integral Constant|, |size_t| | |
101 | ||
102 | ||
103 |