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)
8 #include "check_integral_constant.hpp"
10 # include <type_traits>
11 # include <boost/type_traits/type_with_alignment.hpp> // max_align and long_long_type
13 # include <boost/type_traits/alignment_of.hpp>
14 # include <boost/type_traits/aligned_storage.hpp>
15 # include <boost/type_traits/is_pod.hpp>
21 template< unsigned N
, unsigned Alignment
>
22 struct alignment_implementation1
24 boost::detail::aligned_storage::aligned_storage_imp
<N
,Alignment
> type
;
25 const void* address() const { return type
.address(); }
28 template< unsigned N
, unsigned Alignment
>
29 struct alignment_implementation2
:
35 boost::detail::aligned_storage::aligned_storage_imp
<N
,Alignment
>
37 typedef boost::detail::aligned_storage::aligned_storage_imp
<N
,Alignment
> type
;
38 const void* address() const { return static_cast<const type
*>(this)->address(); }
41 template< unsigned N
, class T
>
42 std::ptrdiff_t get_address1()
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
);
48 template< unsigned N
, class T
>
49 std::ptrdiff_t get_address2()
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
);
58 std::ptrdiff_t addr1
= get_address1
<0,T
>();
59 std::ptrdiff_t addr2
= get_address2
<0,T
>();
61 // @remark: only the empty case differs
63 BOOST_CHECK( addr1
!= addr2
);
65 addr1
= get_address1
<1,T
>();
66 addr2
= get_address2
<1,T
>();
67 BOOST_CHECK( addr1
== addr2
);
69 addr1
= get_address1
<2,T
>();
70 addr2
= get_address2
<2,T
>();
71 BOOST_CHECK( addr1
== addr2
);
73 addr1
= get_address1
<3,T
>();
74 addr2
= get_address2
<3,T
>();
75 BOOST_CHECK( addr1
== addr2
);
77 addr1
= get_address1
<4,T
>();
78 addr2
= get_address2
<4,T
>();
79 BOOST_CHECK( addr1
== addr2
);
81 addr1
= get_address1
<17,T
>();
82 addr2
= get_address2
<17,T
>();
83 BOOST_CHECK( addr1
== addr2
);
85 addr1
= get_address1
<32,T
>();
86 addr2
= get_address2
<32,T
>();
87 BOOST_CHECK( addr1
== addr2
);
91 TT_TEST_BEGIN(type_with_empty_alignment_buffer
)
99 do_check
<long double>();
101 #ifdef BOOST_HAS_MS_INT64
104 #ifdef BOOST_HAS_LONG_LONG
105 do_check
<boost::long_long_type
>();
108 do_check
<int(*)(int)>();
112 do_check
<enum_UDT
>();
115 do_check
<empty_UDT
>();
116 do_check
<union_UDT
>();
117 do_check
<boost::detail::max_align
>();