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