blob: 3098e8d00a4b2a7d4d56847965189ff1f198f67a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*
Copyright 2014-2015 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/align/alignment_of.hpp>
#include <boost/align/is_aligned.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
template<std::size_t N>
struct A { };
template<std::size_t N>
void test(char* p, A<N>)
{
BOOST_TEST(boost::alignment::is_aligned(p, N));
BOOST_TEST(!boost::alignment::is_aligned(p + 1, N));
}
void test(char* p, A<1>)
{
BOOST_TEST(boost::alignment::is_aligned(p, 1));
}
template<class T>
void test()
{
T o;
test(reinterpret_cast<char*>(&o),
A<boost::alignment::alignment_of<T>::value>());
}
class X;
int main()
{
test<bool>();
test<char>();
test<wchar_t>();
#if !defined(BOOST_NO_CXX11_CHAR16_T)
test<char16_t>();
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T)
test<char32_t>();
#endif
test<short>();
test<int>();
test<long>();
#if !defined(BOOST_NO_LONG_LONG) && !defined(_MSC_VER)
test<long long>();
#endif
test<float>();
#if !defined(BOOST_MSVC)
test<double>();
test<long double>();
#endif
test<void*>();
test<char*>();
test<int*>();
test<X*>();
test<void(*)()>();
#if !defined(_MSC_VER) || !defined(__clang__)
#if !defined(BOOST_MSVC)
test<int X::*>();
test<int(X::*)()>();
#endif
#endif
return boost::report_errors();
}
|