c++ - Trying to define types with variadic templates -


I'm new to varied templates, so stay here with me.

I am trying to bring my dimensional analysis library to the 21st century and to C +11, I would like the ability to define a type of type, not an example, it is basically that What do I want to say:

  Velocity_dimension = make_dimension & lt; 1, 0, -1, 0, 0, 0, 0>;   

The result should be of the following:

  velocity_dimension = std :: tuple & lt; Std :: ratio & lt; 1>, std :: ratio & lt; 0 & gt; , Std :: Ratio & lt; -1 & gt; std :: ratio & lt; 0>, std :: ratio & lt; 0>, std :: ratio & lt; 0>, std :: ratio & lt; 0 & gt; & Gt ;;   

I am struggling to wrap my mind about varied templates and how to get the interface. I am trying to experiment with:

  template & lt; Typename t, typename ... args & gt; Make_list = std :: tuple & lt; Using the Std :: Ratio & lt; T & gt;, make_list & lt; ARG & gt; ... & gt; & Gt; ;   

I think that just tells me how much I do not understand how these things should work.

You want something that takes a number into a variable number of integers, not type, Therefore, the template parameter list should not contain typename .

Similarly std :: proportion & lt; T & gt; Template logic must be an integer in , no type.

Your recursive make_list will not work because you can not specialize in an alias template, so there is no way to end the recursive. You can do something like this with a class template and can provide partial expertise to finish the recurring, but there is no need to do this.

I think you want:

  template & lt; int ... I & gt; Make_dimension = std :: tuple & lt; Using the std :: ratio, & lt; I & gt; ... & gt ;;   

It packs a parameter pack of integers, then it returns the std :: ratio and wrapping a lot in the tubal. / P>

Packs expansion pattern here std :: ratio I> ... which means that each element in the i parameter pack I to std :: ratio i> gt; , so if there is a pack then 1, 2, 3 then the extension is std :: ratio & lt; 1>, std :: ratio & lt; 2>, std :: ratio & lt; 3 & gt;

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -