This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[c++0x] aligned_union implementation
- From: CoffeeBuzz <chris dot fairles at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 28 Aug 2007 15:26:57 -0700 (PDT)
- Subject: [c++0x] aligned_union implementation
Tossed together a aligned_union implementation. I just want to make sure I'm
understanding what its suppose to do.
template<typename... _Types>
struct __largest_alignment;
template<typename _Tp, typename... _Types>
struct __largest_alignment<_Tp,_Types...> {
typedef typename conditional<
(alignment_of<typename
__largest_alignment<_Types...>::type>::value > alignment_of<_Tp>::value),
integral_constant<size_t,alignment_of<typename
__largest_alignment<_Types...>::type>::value>,
integral_constant<size_t,alignment_of<_Tp>::value>>::type
type;
};
template<typename _Tp>
struct __largest_alignment<_Tp> {typedef
integral_constant<size_t,alignment_of<_Tp>::value> type;};
template<std::size_t _Len, typename... _Types>
struct aligned_union {
static const size_t alignment_value =
__largest_alignment<_Types...>::type::value;
typedef typename aligned_storage<_Len, alignment_value>::type type;
};
So 'alignment_value' gives the "largest" alignment of all the types. I'm not
sure if "largest" means "most stringent" so correct me if I'm wrong. Now,
for the type I think the above isn't quite correct since it must be "at
least" _Len but if _Len is smaller than the largest in _Types then it should
be sizeof(the largest type) correct?
Chris
--
View this message in context: http://www.nabble.com/-c%2B%2B0x--aligned_union-implementation-tf4344680.html#a12377647
Sent from the gcc - libstdc++ mailing list archive at Nabble.com.