Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. struct EngineFunctionArgumentOffsets {};
  2.  
  3. template< typename T >
  4. struct _EngineFunctionArgumentOffsets {
  5.     static int* offsets()
  6.     {
  7.         static auto foo = new int[1] { 0 };
  8.         return foo;
  9.     }
  10. };
  11.  
  12. template<typename ...ArgTs>
  13. struct _EngineFunctionArgumentOffsets< void(ArgTs...) > : public EngineFunctionArgumentOffsets
  14. {
  15. private:
  16.     template<typename T> using AVT = typename EngineTypeTraits<T>::ArgumentValueType;
  17.     typedef fixed_tuple<AVT<ArgTs> ...> FixedArgs;
  18.  
  19.     template<size_t ...> struct Seq {};
  20.     template<size_t N, size_t ...S> struct Gens : Gens<N - 1, N - 1, S...> {};
  21.     template<size_t ...I> struct Gens<0, I...> { typedef Seq<I...> type; };
  22.  
  23.     using SeqType = typename Gens<sizeof...(ArgTs)>::type;
  24.  
  25.     template<size_t I>
  26.     static int getOffset(const FixedArgs& args) {
  27.         return (int)((size_t)& fixed_tuple_accessor<I>::get(args)) - ((size_t)& args);
  28.     }
  29.  
  30.     template<size_t ...I>
  31.     static int* offsetsDispatchHelper(const FixedArgs& args, Seq<I...>) {
  32.         int *tmp = new int[sizeof...(ArgTs)] { getOffset<I>(args)... };
  33.         return tmp;
  34.     }
  35.  
  36. public:
  37.     static int* offsets()
  38.     {
  39.         FixedArgs args;
  40.         return offsetsDispatchHelper(args, SeqType());
  41.     }
  42. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement