1 #ifndef _BASICUNION_H_ 2 #define _BASICUNION_H_ 3 4 #include "Types.h" 5 6 template <typename FullType, typename HalfType> 7 struct basic_union 8 { 9 static_assert(sizeof(FullType) == (2 * sizeof(HalfType)), "Full type size isn't twice of half type size."); 10 basic_unionbasic_union11 basic_union() {} basic_unionbasic_union12 basic_union(const FullType& f) : f(f) {} basic_unionbasic_union13 basic_union(const HalfType& h0, const HalfType& h1) : h0(h0), h1(h1) {} 14 15 union 16 { 17 struct 18 { 19 HalfType h0; 20 HalfType h1; 21 }; 22 FullType f; 23 }; 24 }; 25 26 typedef basic_union<uint32, uint16> UNION32_16; 27 typedef basic_union<uint64, uint32> UNION64_32; 28 typedef basic_union<uint64, UNION32_16> UNION64_32_16; 29 30 #endif 31