4 #ifndef DUNE_ALIGNMENT_HH
5 #define DUNE_ALIGNMENT_HH
9 #elif HAVE_TR1_TYPE_TRAITS
10 #include <tr1/type_traits>
35 struct AlignmentStruct
46 template<
class T, std::
size_t N>
47 struct AlignmentHelper
49 enum { N2 =
sizeof(AlignmentStruct<T>) -
sizeof(T) - N };
55 #define ALIGNMENT_MODULO(a, b) (a % b == 0 ? \
56 static_cast<std::size_t>(b) : \
57 static_cast<std::size_t>(a % b))
58 #define ALIGNMENT_MIN(a, b) (static_cast<std::size_t>(a) < \
59 static_cast<std::size_t>(b) ? \
60 static_cast<std::size_t>(a) : \
61 static_cast<std::size_t>(b))
63 template <
class T, std::
size_t N>
64 struct AlignmentTester
66 typedef AlignmentStruct<T> s;
67 typedef AlignmentHelper<T, N> h;
68 typedef AlignmentTester<T, N - 1> next;
81 struct AlignmentTester<T, 0>
105 #ifdef HAVE_TYPE_TRAITS
106 value = std::alignment_of<T>::value
107 #elif HAVE_TR1_TYPETRAITS
108 value = std::tr1::alignment_of<T>::value
110 value = AlignmentTester<T, sizeof(AlignmentStruct<T>) -
sizeof(T) -1>::result
char c
Definition: alignment.hh:37
T t
Definition: alignment.hh:38
char padding2[N2]
Definition: alignment.hh:52
Calculates the alignment requirement of a type.
Definition: alignment.hh:99
#define ALIGNMENT_MODULO(a, b)
Definition: alignment.hh:55
char padding1[N]
Definition: alignment.hh:50
The alignment requirement.
Definition: alignment.hh:110
#define ALIGNMENT_MIN(a, b)
Definition: alignment.hh:58