c++ - Non-type template parameters in function and in inheritance -
I'm following great tutorial. The author uses variation templates and I came to the point where I got stuck, I do not understand. Can you help me
Why is not this compilation?
// This is a simple template Next, the author fixes this code:
template & lt; Size_t ... index & gt; Struct index_sequence {type = index_sequence & lt; Indies ... & gt;; }; Template & lt; Typename sequence, typename ... type & gt; Struct tuple_impl; Template & lt; Size_t ... index, typename ... type & gt; Struct tuple_impl & lt; Index_scension & lt; Indies ... & gt;, type ... & gt; : Tuple_element & lt; Index, type & gt; ... {}; 2 Why is everything okay in this matter? I see an almost identical pattern here: tuple_element & lt; Index, type & gt; ...
3. Why it can not be compiled:
template & lt; Size_t ... index & gt; Zero g (index ...) {}; // Error: Variable or Field 'G' declared zero
-
There will be no point in compiling the compiler when the first sequence ends and the second is beginning - so it is finally allowed only one parameter pack in various templates of intervals.
tuple_impl & lt; A, b, c, d, e, f & gt; // is still an index or a type already? What about eThis works because
tuple_implis the only template that has a parameter pack in itself,type .... It is just glad that the first parameter in this specialization is also a template, which also has a parameter pack. Therefore, unlike a template with two packets, you have two templates with one packet each, which is fine.This is not to be done with the varied templates, that is, it will not work with the same logic either, for the same reason that, since the
index ...are not types, but the value, if you are not defining a function, if it is not zero, then the compiler should have problems later. Consider this example, which is slightly modified, but basically the same build:template & lt; Size_t I & gt; The middle line is middle: the compiler thinks this is a variable definition, which starts withI . So error in your case, because the variable typezerojust does not understand. My compiler then exits a warning about the template, thinks thatgis a templated variable, and they are a C + 1 1y extension. After that, he realizes that the variable definition is a;does not end, emits an error and exits ...
Comments
Post a Comment