/* (c) 2014 Glen Joseph Fernandes Distributed under the Boost Software License, Version 1.0. http://boost.org/LICENSE_1_0.txt */ #include #include #include #define OFFSET(t, m) ((std::size_t)(&((t*)0)->m)) template struct remove_reference { typedef T type; }; template struct remove_reference { typedef T type; }; #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template struct remove_reference { typedef T type; }; #endif template struct remove_all_extents { typedef T type; }; template struct remove_all_extents { typedef typename remove_all_extents::type type; }; template struct remove_all_extents { typedef typename remove_all_extents::type type; }; template struct remove_const { typedef T type; }; template struct remove_const { typedef T type; }; template struct remove_volatile { typedef T type; }; template struct remove_volatile { typedef T type; }; template struct remove_cv { typedef typename remove_volatile::type>::type type; }; template struct alignof_helper { char value; typename remove_cv::type>::type>::type object; }; template std::size_t result() { return boost::alignment::alignment_of::value; } template std::size_t expect() { return OFFSET(alignof_helper, object); } template void test_type() { BOOST_TEST_EQ(result(), expect()); } template void test_reference() { test_type(); test_type(); #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) test_type(); #endif } template void test_array() { test_reference(); test_reference(); test_type(); } template void test_cv() { test_array(); test_array(); test_array(); test_array(); } template struct W1 { T t; }; template class W2 { public: T t; }; template union W3 { T t; }; template void test() { test_cv(); test_cv >(); test_cv >(); test_cv >(); } void test_integral() { test(); test(); test(); test(); test(); #if !defined(BOOST_NO_CXX11_CHAR16_T) test(); #endif #if !defined(BOOST_NO_CXX11_CHAR32_T) test(); #endif test(); test(); test(); test(); test(); test(); #if !defined(BOOST_NO_LONG_LONG) test(); test(); #endif } void test_floating_point() { test(); test(); test(); } void test_nullptr_t() { #if !defined(BOOST_NO_CXX11_NULLPTR) && \ !defined(BOOST_NO_CXX11_DECLTYPE) test(); #endif } class X; void test_pointer() { test(); test(); test(); test(); test(); } void test_member_pointer() { test(); test(); } enum E { V = 1 }; void test_enum() { test(); } struct S { }; class C { }; union U { }; void test_class() { test(); test(); test(); } int main() { test_integral(); test_floating_point(); test_nullptr_t(); test_pointer(); test_member_pointer(); test_enum(); test_class(); return boost::report_errors(); }