]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/align/test/alignment_of_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / align / test / alignment_of_test.cpp
CommitLineData
7c673cae 1/*
b32b8144
FG
2Copyright 2014 Glen Joseph Fernandes
3(glenjofe@gmail.com)
7c673cae 4
b32b8144
FG
5Distributed under the Boost Software License, Version 1.0.
6(http://www.boost.org/LICENSE_1_0.txt)
7c673cae
FG
7*/
8#include <boost/align/alignment_of.hpp>
9#include <boost/core/lightweight_test.hpp>
10#include <boost/config.hpp>
b32b8144 11#include <cstddef>
7c673cae
FG
12
13template<class T>
14struct remove_reference {
15 typedef T type;
16};
17
18template<class T>
19struct remove_reference<T&> {
20 typedef T type;
21};
22
23#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
24template<class T>
25struct remove_reference<T&&> {
26 typedef T type;
27};
28#endif
29
30template<class T>
31struct remove_all_extents {
32 typedef T type;
33};
34
35template<class T>
36struct remove_all_extents<T[]> {
37 typedef typename remove_all_extents<T>::type type;
38};
39
40template<class T, std::size_t N>
41struct remove_all_extents<T[N]> {
42 typedef typename remove_all_extents<T>::type type;
43};
44
45template<class T>
b32b8144 46struct remove_cv {
7c673cae
FG
47 typedef T type;
48};
49
50template<class T>
b32b8144 51struct remove_cv<const T> {
7c673cae
FG
52 typedef T type;
53};
54
55template<class T>
b32b8144 56struct remove_cv<volatile T> {
7c673cae
FG
57 typedef T type;
58};
59
60template<class T>
b32b8144 61struct remove_cv<const volatile T> {
7c673cae
FG
62 typedef T type;
63};
64
65template<class T>
b32b8144 66struct offset_value {
7c673cae
FG
67 char value;
68 typename remove_cv<typename remove_all_extents<typename
69 remove_reference<T>::type>::type>::type object;
70};
71
7c673cae
FG
72template<class T>
73void test_type()
74{
b32b8144
FG
75 enum {
76 N = boost::alignment::alignment_of<T>::value
77 };
78 BOOST_TEST(offsetof(offset_value<T>, object) == N);
7c673cae
FG
79}
80
81template<class T>
82void test_reference()
83{
84 test_type<T>();
85 test_type<T&>();
86
87#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
88 test_type<T&&>();
89#endif
90}
91
92template<class T>
93void test_array()
94{
95 test_reference<T>();
96 test_reference<T[2]>();
97 test_type<T[]>();
98}
99
100template<class T>
101void test_cv()
102{
103 test_array<T>();
104 test_array<const T>();
105 test_array<volatile T>();
106 test_array<const volatile T>();
107}
108
109template<class T>
b32b8144 110struct Struct {
7c673cae
FG
111 T t;
112};
113
114template<class T>
b32b8144 115union Union {
7c673cae
FG
116 T t;
117};
118
119template<class T>
120void test()
121{
122 test_cv<T>();
b32b8144
FG
123 test_cv<Struct<T> >();
124 test_cv<Union<T> >();
7c673cae
FG
125}
126
127void test_integral()
128{
129 test<bool>();
130 test<char>();
131 test<signed char>();
132 test<unsigned char>();
133 test<wchar_t>();
134
135#if !defined(BOOST_NO_CXX11_CHAR16_T)
136 test<char16_t>();
137#endif
138
139#if !defined(BOOST_NO_CXX11_CHAR32_T)
140 test<char32_t>();
141#endif
142
143 test<short>();
144 test<unsigned short>();
145 test<int>();
146 test<unsigned int>();
147 test<long>();
148 test<unsigned long>();
149
150#if !defined(BOOST_NO_LONG_LONG)
151 test<long long>();
152 test<unsigned long long>();
153#endif
154}
155
156void test_floating_point()
157{
158 test<float>();
159 test<double>();
160 test<long double>();
161}
162
163void test_nullptr_t()
164{
165#if !defined(BOOST_NO_CXX11_NULLPTR) && \
166 !defined(BOOST_NO_CXX11_DECLTYPE)
167 test<decltype(nullptr)>();
168#endif
169}
170
171class X;
172
173void test_pointer()
174{
175 test<void*>();
176 test<char*>();
177 test<int*>();
178 test<X*>();
179 test<void(*)()>();
180}
181
182void test_member_pointer()
183{
184 test<int X::*>();
185 test<int(X::*)()>();
186}
187
188enum E {
189 V = 1
190};
191
192void test_enum()
193{
194 test<E>();
195}
196
197struct S { };
198class C { };
199union U { };
200
201void test_class()
202{
203 test<S>();
204 test<C>();
205 test<U>();
206}
207
208int main()
209{
210 test_integral();
211 test_floating_point();
212 test_nullptr_t();
213 test_pointer();
214 test_member_pointer();
215 test_enum();
216 test_class();
217
218 return boost::report_errors();
219}