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;
71 a1 = ALIGNMENT_MODULO(N ,
sizeof(T)),
72 a2 = ALIGNMENT_MODULO(h::N2 ,
sizeof(T)),
73 a3 = ALIGNMENT_MODULO(
sizeof(h),
sizeof(T)),
74 a =
sizeof(h) ==
sizeof(s) ? ALIGNMENT_MIN(a1, a2) : a3,
75 result = ALIGNMENT_MIN(a, next::result)
81 struct AlignmentTester<T, 0>
85 result = ALIGNMENT_MODULO(
sizeof(AlignmentStruct<T>),
sizeof(T))
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
Dune namespace.
Definition: alignment.hh:14
Calculates the alignment requirement of a type.
Definition: alignment.hh:100
@ value
The alignment requirement.
Definition: alignment.hh:110