#ifndef LY1b9novVl8oDseRTw8dH5lzpNo #define LY1b9novVl8oDseRTw8dH5lzpNo #include #include #include #include #include #include #include #include #include #include #include #include #include #define STATIC_ASSERT_IS_POWER_OF_TWO(x) BOOST_STATIC_ASSERT( !(x & (x-1)) ); template struct StaticVal { inline static const T value() { return T(numerator) / T(denominator); } }; // forcing a type conversion of non-ptr types #define FORCE_CONV(Type, Val) (*(reinterpret_cast(& Val))) // generate a constructor which fails when called // TODO (beauty): catch error after optimization, before runtime // (e.g. by linking to a forbidden symbol) #define GEN_ANYCAST_CTOR_3(name) \ template name(T1 t1, T2 t2, T3 t3) // a void you may return struct Void { typedef Void type; // for metaprogramming brainfucks typedef Void con_arg_t; }; // just to beautify some code struct BaseCase {}; // prevent instanciation of default or unimplemented cases #define DO_NOT_INSTANCE(T) BOOST_STATIC_ASSERT((false && boost::is_same::value)); // forward decl of a function which will never exist (allows showing // errors at link time: later than DO_NOT_INSTANCE but before // assert(false) void oOoOo_LINK_TIME_ASSERTION_FAILED_oOoOo() __attribute__ ((noreturn)); #define DO_NOT_CALL {oOoOo_LINK_TIME_ASSERTION_FAILED_oOoOo();} namespace UnpackTypeListImpl { using namespace boost::mpl; template class Tgt, typename Iter, typename EndIter, typename... NewList> struct Action { typedef typename Action::type, EndIter, NewList..., typename deref::type >::type type; }; template class Tgt, typename EndIter, typename... List> struct Action { typedef Tgt type; }; } // NS // unpack a boost::mpl sequence into a variadic type list template class Tgt, typename Seq, typename... NewList> struct UnpackTypeList { typedef typename UnpackTypeListImpl ::Action::type, typename boost::mpl::end::type, NewList...>::type type; }; // create a unique class from a type, given a variadic garbage type // list; if the type is an empty struct it is not stored but created // upon every request // TODO: access functions (right now the stored values are only // accessed using outraging pointer casts) template struct MakeUniqueImpl; template struct MakeUnique { typedef MakeUniqueImpl::value, boost::is_fundamental::value, Garbage...> type; }; template struct MakeUniqueImpl { MakeUniqueImpl(const T &v) {} MakeUniqueImpl(T &&v) {} MakeUniqueImpl() = default; }; template struct MakeUniqueImpl { MakeUniqueImpl(const T &v) : v(v) {} MakeUniqueImpl(T &&v) : v(v) {} MakeUniqueImpl() = default; T v; }; template struct MakeUniqueImpl : protected T { MakeUniqueImpl(T&& a) : T(std::move(a)) {} MakeUniqueImpl() = default; }; #endif // LY1b9novVl8oDseRTw8dH5lzpNo