/*
-(c) 2014 Glen Joseph Fernandes
-<glenjofe -at- gmail.com>
+Copyright 2014 Glen Joseph Fernandes
+(glenjofe@gmail.com)
-Distributed under the Boost Software
-License, Version 1.0.
-http://boost.org/LICENSE_1_0.txt
+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/core/lightweight_test.hpp>
#include <boost/config.hpp>
-
-#define OFFSET(t, m) ((std::size_t)(&((t*)0)->m))
+#include <cstddef>
template<class T>
struct remove_reference {
};
template<class T>
-struct remove_const {
+struct remove_cv {
typedef T type;
};
template<class T>
-struct remove_const<const T> {
+struct remove_cv<const T> {
typedef T type;
};
template<class T>
-struct remove_volatile {
+struct remove_cv<volatile T> {
typedef T type;
};
template<class T>
-struct remove_volatile<volatile T> {
+struct remove_cv<const volatile T> {
typedef T type;
};
template<class T>
-struct remove_cv {
- typedef typename remove_volatile<typename
- remove_const<T>::type>::type type;
-};
-
-template<class T>
-struct alignof_helper {
+struct offset_value {
char value;
typename remove_cv<typename remove_all_extents<typename
remove_reference<T>::type>::type>::type object;
};
-template<class T>
-std::size_t result()
-{
- return boost::alignment::alignment_of<T>::value;
-}
-
-template<class T>
-std::size_t expect()
-{
- return OFFSET(alignof_helper<T>, object);
-}
-
template<class T>
void test_type()
{
- BOOST_TEST_EQ(result<T>(), expect<T>());
+ enum {
+ N = boost::alignment::alignment_of<T>::value
+ };
+ BOOST_TEST(offsetof(offset_value<T>, object) == N);
}
template<class T>
}
template<class T>
-struct W1 {
- T t;
-};
-
-template<class T>
-class W2 {
-public:
+struct Struct {
T t;
};
template<class T>
-union W3 {
+union Union {
T t;
};
void test()
{
test_cv<T>();
- test_cv<W1<T> >();
- test_cv<W2<T> >();
- test_cv<W3<T> >();
+ test_cv<Struct<T> >();
+ test_cv<Union<T> >();
}
void test_integral()