]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/aligned_storage_empy_test.cpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / libs / type_traits / test / aligned_storage_empy_test.cpp
1
2 // (C) Copyright Thorsten Ottosen 2009.
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifdef TEST_STD
8 # include <type_traits>
9 # include <boost/type_traits/type_with_alignment.hpp> // max_align and long_long_type
10 #else
11 # include <boost/type_traits/alignment_of.hpp>
12 # include <boost/type_traits/aligned_storage.hpp>
13 # include <boost/type_traits/is_pod.hpp>
14 #endif
15 #include "test.hpp"
16 #include "check_integral_constant.hpp"
17
18
19 namespace
20 {
21 template< unsigned N, unsigned Alignment >
22 struct alignment_implementation1
23 {
24 boost::detail::aligned_storage::aligned_storage_imp<N,Alignment> type;
25 const void* address() const { return type.address(); }
26 };
27
28 template< unsigned N, unsigned Alignment >
29 struct alignment_implementation2 :
30 #ifndef BOOST_BORLANDC
31 private
32 #else
33 public
34 #endif
35 boost::detail::aligned_storage::aligned_storage_imp<N,Alignment>
36 {
37 typedef boost::detail::aligned_storage::aligned_storage_imp<N,Alignment> type;
38 const void* address() const { return static_cast<const type*>(this)->address(); }
39 };
40
41 template< unsigned N, class T >
42 std::ptrdiff_t get_address1()
43 {
44 static alignment_implementation1<N*sizeof(T), tt::alignment_of<T>::value> imp1;
45 return static_cast<const char*>(imp1.address()) - reinterpret_cast<const char*>(&imp1);
46 }
47
48 template< unsigned N, class T >
49 std::ptrdiff_t get_address2()
50 {
51 static alignment_implementation2<N*sizeof(T), tt::alignment_of<T>::value> imp2;
52 return static_cast<const char*>(imp2.address()) - reinterpret_cast<const char*>(&imp2);
53 }
54
55 template< class T >
56 void do_check()
57 {
58 std::ptrdiff_t addr1 = get_address1<0,T>();
59 std::ptrdiff_t addr2 = get_address2<0,T>();
60 //
61 // @remark: only the empty case differs
62 //
63 BOOST_CHECK( addr1 != addr2 );
64
65 addr1 = get_address1<1,T>();
66 addr2 = get_address2<1,T>();
67 BOOST_CHECK( addr1 == addr2 );
68
69 addr1 = get_address1<2,T>();
70 addr2 = get_address2<2,T>();
71 BOOST_CHECK( addr1 == addr2 );
72
73 addr1 = get_address1<3,T>();
74 addr2 = get_address2<3,T>();
75 BOOST_CHECK( addr1 == addr2 );
76
77 addr1 = get_address1<4,T>();
78 addr2 = get_address2<4,T>();
79 BOOST_CHECK( addr1 == addr2 );
80
81 addr1 = get_address1<17,T>();
82 addr2 = get_address2<17,T>();
83 BOOST_CHECK( addr1 == addr2 );
84
85 addr1 = get_address1<32,T>();
86 addr2 = get_address2<32,T>();
87 BOOST_CHECK( addr1 == addr2 );
88 }
89 }
90
91 TT_TEST_BEGIN(type_with_empty_alignment_buffer)
92
93 #ifndef TEST_CUDA_DEVICE
94
95 do_check<char>();
96 do_check<short>();
97 do_check<int>();
98 do_check<long>();
99 do_check<float>();
100 do_check<double>();
101 do_check<long double>();
102
103 #ifdef BOOST_HAS_MS_INT64
104 do_check<__int64>();
105 #endif
106 #ifdef BOOST_HAS_LONG_LONG
107 do_check<boost::long_long_type>();
108 #endif
109
110 do_check<int(*)(int)>();
111 do_check<int*>();
112 do_check<VB>();
113 do_check<VD>();
114 do_check<enum_UDT>();
115 do_check<mf2>();
116 do_check<POD_UDT>();
117 do_check<empty_UDT>();
118 do_check<union_UDT>();
119 do_check<boost::detail::max_align>();
120
121 #endif
122
123 TT_TEST_END
124
125
126
127
128
129
130
131
132