c++ - Parameter pack used for default template parameter -


i'd this:

template<int... myints> struct {}  template<int... myints, class traits = a<myints...>> struct b {} 

i know parameter packs should appear @ end, remember there exceptions. think there way make code (or similar) work?

thanks

one way:

  • wrap types tuples.

  • use specialisation convert type lists types

 

#include <tuple> #include <utility>  template<int...myints> struct {};  namespace detail {     template<class sequence>     struct make_a_from;      template<class t, t...ts>     struct make_a_from<std::integer_sequence<t, ts...>> {         using type = a<ts...>;     }; } template<class sequence> using make_a_from = typename detail::make_a_from<sequence>::type;  template<class sequence, class traitstuple = make_a_from<sequence> > struct b;  template<typename int, int...myints, class traits>  struct b<std::integer_sequence<int, myints...>, traits> {     using ints_tuple = std::tuple<std::integral_constant<int, myints>...>;     using traits_type = traits; };  namespace detail {     template<typename int, int...is>     struct make_b     {         using type = b<std::integer_sequence<int, is...>>;     }; }  template<int...is> using make_b = b<std::integer_sequence<int, is...>>;  int main() {     make_b<1,3,4,5> b;     b<std::integer_sequence<int, 5,6,7,8>> b2;     b<std::integer_sequence<int, 5,6,7,8>, class customtrait> b3; } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -