Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cascade variadic template template parameters

How can I cascade variadic types? I.e.:

template <typename... T>
using Cascade = ???; // T1<T2<T3<...>>>

Example:

using Vector2D = Cascade<std::vector, std::vector, double>;
static_assert(std::is_same_v<Vector2D, std::vector<std::vector<double>>>);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You cannot have CascadeRight. T1 is not a typename, it is a template, and so are most of the others, but the last one is a typename. You cannot have different parameter kinds (both types and templates) in the same parameter pack. You also cannot have anything after a parameter pack.

You can have CascadeLeft like this:

  template <typename K, template <typename...> class ... T>
  class CascadeLeft;                  
                                      
  template <typename K>               
  class CascadeLeft<K>                
  {                                   
      using type = K;                 
  };                                  
                                      
  template <typename K, 
            template <typename...> class T0, 
            template <typename...> class... T>
  class CascadeLeft<K, T0, T...>      
  {                                   
      using type = typename CascadeLeft<T0<K>, T...>::type;
  };   

Frankly, std::vector<std::vector<double>> is much more transparent than CascadeLeft<double, std::vector, std::vector>, so I wouldn’t bother.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading