1 /* 2 Copyright 2019 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/is_aligned.hpp> 9 #include <boost/core/lightweight_test.hpp> 10 11 template<std::size_t N> 12 struct A { }; 13 14 template<class T, std::size_t N> test(A<N>)15void test(A<N>) 16 { 17 T v1 = N; 18 BOOST_TEST(boost::alignment::is_aligned(v1, N)); 19 T v2 = N - 1; 20 BOOST_TEST(!boost::alignment::is_aligned(v2, N)); 21 T v3 = N + 1; 22 BOOST_TEST(!boost::alignment::is_aligned(v3, N)); 23 T v4 = N + N; 24 BOOST_TEST(boost::alignment::is_aligned(v4, N)); 25 } 26 27 template<class T> test(A<1>)28void test(A<1>) 29 { 30 T v = 1; 31 BOOST_TEST(boost::alignment::is_aligned(v, 1)); 32 } 33 34 template<class T> test()35void test() 36 { 37 test<T>(A<1>()); 38 test<T>(A<2>()); 39 test<T>(A<4>()); 40 test<T>(A<8>()); 41 test<T>(A<16>()); 42 test<T>(A<32>()); 43 test<T>(A<64>()); 44 test<T>(A<128>()); 45 } 46 main()47int main() 48 { 49 test<int>(); 50 test<unsigned>(); 51 test<long>(); 52 test<unsigned long>(); 53 test<short>(); 54 test<unsigned short>(); 55 #if !defined(BOOST_NO_LONG_LONG) 56 test<long long>(); 57 test<unsigned long long>(); 58 #endif 59 test<std::size_t>(); 60 test<std::ptrdiff_t>(); 61 62 return boost::report_errors(); 63 } 64