]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_traits/test/aligned_storage_empy_test.cpp
add subtree-ish sources for 12.0.3
[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 #include "test.hpp"
8 #include "check_integral_constant.hpp"
9 #ifdef TEST_STD
10 # include <type_traits>
11 # include <boost/type_traits/type_with_alignment.hpp> // max_align and long_long_type
12 #else
13 # include <boost/type_traits/alignment_of.hpp>
14 # include <boost/type_traits/aligned_storage.hpp>
15 # include <boost/type_traits/is_pod.hpp>
16 #endif
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 __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 do_check<char>();
94 do_check<short>();
95 do_check<int>();
96 do_check<long>();
97 do_check<float>();
98 do_check<double>();
99 do_check<long double>();
100
101 #ifdef BOOST_HAS_MS_INT64
102 do_check<__int64>();
103 #endif
104 #ifdef BOOST_HAS_LONG_LONG
105 do_check<boost::long_long_type>();
106 #endif
107
108 do_check<int(*)(int)>();
109 do_check<int*>();
110 do_check<VB>();
111 do_check<VD>();
112 do_check<enum_UDT>();
113 do_check<mf2>();
114 do_check<POD_UDT>();
115 do_check<empty_UDT>();
116 do_check<union_UDT>();
117 do_check<boost::detail::max_align>();
118
119 TT_TEST_END
120
121
122
123
124
125
126
127
128