c++ - Trying to sum two compile time tuple integer sequences -


If you are keeping track of the history of my question, then I will end up in a nightmare for a one-dimensional analysis library Updating Macro and learning C ++ 11, variadic templates, and meta programming and functional programming paradigms. For my life, this stuff is still magic.

Nevertheless, I have topless of exponential constant that define physical units.

  template & lt; int ... I & gt; Make_dimension = std :: tuple & lt; Using the std :: ratio, & lt; I & gt; ... & gt ;; Scalar_dimension = make_adimension & lt; Using 0, 0, 0, 0, 0, 0, 0>; Length_admination = making_desk using & lt; 1, 0, 0, 0, 0, 0, 0>; Using time_evolution = counter; 0, 0, 1, 0, 0, 0, 0>;   

This is the library (part) that models SI units. You can only multiply in contrast to units, you can add units and scalar as addition to it. These libraries are in Dindi, causing them to compile time errors if you combine units inappropriately in it & gt; There are 400 units and most of them are defined in the case of other units when multiplication of units, exponents are added, and dividing the units, the exponents are reduced. So to define velocity, I like the means of expressing it:

  by using velocity_feature = split_values ​​& lt; Length_time, time_information & gt;   

And it should be equivalent to writing functionally:

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

I am goggling, but I do not have the vocabulary of applying some hits. The closest I have found is that there is a for_each that applies the elements of a tuple to runtime ... and this is to blow my mind, so I can not understand how to compile it. Elements The 'make_dimension' above was explained to me a moment ago and it blew my mind, but I got cured. Bugged like I'm asking for a handout, so does anyone have any good resources for learning this stuff? I believe that I am the only one who is interested in doing this only.

The solution of the DIP in @ comments uses a recursive instant template. Although one of the most common techniques for verandic templates, in this case the recursive is probably overkill, because the complete set of changes can be done in a single pack extension, which extends two parameters pack together: < pre> template & lt; Template & lt; Square, orbit & gt; Class, class, orbit & gt; Struct tuple_transform; // Undefined template & lt; Template & lt; Square, orbit & gt; Class changes, class ... t, class ... VS & gt; Struct tuple_transform & lt; Conversion, std :: tuple & lt; Ts ... & gt; std :: tuple & lt; VS ... & gt; & Gt; {Type = std :: tuple & lt; Transforms & lt; Ts, Vs & gt; ... & gt ;; }; Template & lt; Class T, Class U & gt; Divide_dimensions = typename tuple_transform & lt; Std :: ratio_subtract, t, u & gt; :: using the type;

Note that the above is assumed that transforms is a nickname for the desired result type. It matches the behavior of ratio_add etc. - These are the nickname templates for std :: ratio , hence the typename ratio_add & lt; ... & gt; :: type is not required

.

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? -