Type of non-type parameter in template template class is non deducible in C++14 but deducible in C++172019 Community Moderator ElectionUse 'class' or 'typename' for template parameters?Clang variadic template specialization error: non-deducible template parameterCan't deduce template typewhy this variable isn't deduced as initializer_list in g++ in C++14?extern array as non-type template argument with clang c++1zIs default template template parameter value deduced context?Why is gcc failing when using lambda for non-type template parameter?Matching variadic non-type templatesTrailing class template arguments not deducedC++17 template constructor class template deduction

Which country has more?

I reported the illegal activity of my boss to his boss. My boss found out. Now I am being punished. What should I do?

School performs periodic password audits. Is my password compromised?

What does *dead* mean in *What do you mean, dead?*?

How to copy the rest of lines of a file to another file

Computation logic of Partway in TikZ

Does the US political system, in principle, allow for a no-party system?

How do we create new idioms and use them in a novel?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Converting from "matrix" data into "coordinate" data

The (Easy) Road to Code

How exactly does an Ethernet collision happen in the cable, since nodes use different circuits for Tx and Rx?

Will expression retain the same definition if particle is changed?

Either of .... (Plural/Singular)

Is this Paypal Github SDK reference really a dangerous site?

Giving a career talk in my old university, how prominently should I tell students my salary?

Traveling to heavily polluted city, what practical measures can I take to minimize impact?

Is divide-by-zero a security vulnerability?

Can I negotiate a patent idea for a raise, under French law?

What do you call someone who likes to pick fights?

Strange opamp's output impedance in spice

Are E natural minor and B harmonic minor related?

Is it appropriate to ask a former professor to order a book for me through an inter-library loan?

Is there stress on two letters on the word стоят



Type of non-type parameter in template template class is non deducible in C++14 but deducible in C++17



2019 Community Moderator ElectionUse 'class' or 'typename' for template parameters?Clang variadic template specialization error: non-deducible template parameterCan't deduce template typewhy this variable isn't deduced as initializer_list in g++ in C++14?extern array as non-type template argument with clang c++1zIs default template template parameter value deduced context?Why is gcc failing when using lambda for non-type template parameter?Matching variadic non-type templatesTrailing class template arguments not deducedC++17 template constructor class template deduction










2















The title is a bit confusing but what I mean is this specific case:



template<class>
struct get_type_of_nontype;

template<class T, T Value, template<T> class Template>
struct get_type_of_nontype<Template<Value>>
using type = T;
;


So I can use it like this:



#include <type_traits>

template<int I>
class int_non_type ;

static_assert(
std::is_same<typename get_type_of_nontype<int_non_type<0>>::type, int>::value,
"T is deduced to be `int` as `template<T> class Template` is `template<int> class int_non_type`"
);


This works fine in C++17. In C++14 I get the following errors:



gcc 8:



<source>:5:8: error: template parameters not deducible in partial specialization:
struct get_type_of_nontype<Template<Value>> {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:5:8: note: 'T'


clang 7:



<source>:5:8: error: class template partial specialization contains a template parameter that cannot be deduced; this partial specialization will never be used [-Wunusable-partial-specialization]
struct get_type_of_nontype<Template<Value>> {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:4:16: note: non-deducible template parameter 'T'
template<class T, T Value, template<T> class Template>
^


And then they both complain that struct get_type_of_nontype<int_non_type<0>> is incomplete, so typename get_type_of_non_type<int_non_type<0>>::type can't compile.



Why is this different between C++14 and C++17? Is this just a compiler bug? If not, is there a way to do this in C++14?










share|improve this question


























    2















    The title is a bit confusing but what I mean is this specific case:



    template<class>
    struct get_type_of_nontype;

    template<class T, T Value, template<T> class Template>
    struct get_type_of_nontype<Template<Value>>
    using type = T;
    ;


    So I can use it like this:



    #include <type_traits>

    template<int I>
    class int_non_type ;

    static_assert(
    std::is_same<typename get_type_of_nontype<int_non_type<0>>::type, int>::value,
    "T is deduced to be `int` as `template<T> class Template` is `template<int> class int_non_type`"
    );


    This works fine in C++17. In C++14 I get the following errors:



    gcc 8:



    <source>:5:8: error: template parameters not deducible in partial specialization:
    struct get_type_of_nontype<Template<Value>> {
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    <source>:5:8: note: 'T'


    clang 7:



    <source>:5:8: error: class template partial specialization contains a template parameter that cannot be deduced; this partial specialization will never be used [-Wunusable-partial-specialization]
    struct get_type_of_nontype<Template<Value>> {
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    <source>:4:16: note: non-deducible template parameter 'T'
    template<class T, T Value, template<T> class Template>
    ^


    And then they both complain that struct get_type_of_nontype<int_non_type<0>> is incomplete, so typename get_type_of_non_type<int_non_type<0>>::type can't compile.



    Why is this different between C++14 and C++17? Is this just a compiler bug? If not, is there a way to do this in C++14?










    share|improve this question
























      2












      2








      2


      1






      The title is a bit confusing but what I mean is this specific case:



      template<class>
      struct get_type_of_nontype;

      template<class T, T Value, template<T> class Template>
      struct get_type_of_nontype<Template<Value>>
      using type = T;
      ;


      So I can use it like this:



      #include <type_traits>

      template<int I>
      class int_non_type ;

      static_assert(
      std::is_same<typename get_type_of_nontype<int_non_type<0>>::type, int>::value,
      "T is deduced to be `int` as `template<T> class Template` is `template<int> class int_non_type`"
      );


      This works fine in C++17. In C++14 I get the following errors:



      gcc 8:



      <source>:5:8: error: template parameters not deducible in partial specialization:
      struct get_type_of_nontype<Template<Value>> {
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      <source>:5:8: note: 'T'


      clang 7:



      <source>:5:8: error: class template partial specialization contains a template parameter that cannot be deduced; this partial specialization will never be used [-Wunusable-partial-specialization]
      struct get_type_of_nontype<Template<Value>> {
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      <source>:4:16: note: non-deducible template parameter 'T'
      template<class T, T Value, template<T> class Template>
      ^


      And then they both complain that struct get_type_of_nontype<int_non_type<0>> is incomplete, so typename get_type_of_non_type<int_non_type<0>>::type can't compile.



      Why is this different between C++14 and C++17? Is this just a compiler bug? If not, is there a way to do this in C++14?










      share|improve this question














      The title is a bit confusing but what I mean is this specific case:



      template<class>
      struct get_type_of_nontype;

      template<class T, T Value, template<T> class Template>
      struct get_type_of_nontype<Template<Value>>
      using type = T;
      ;


      So I can use it like this:



      #include <type_traits>

      template<int I>
      class int_non_type ;

      static_assert(
      std::is_same<typename get_type_of_nontype<int_non_type<0>>::type, int>::value,
      "T is deduced to be `int` as `template<T> class Template` is `template<int> class int_non_type`"
      );


      This works fine in C++17. In C++14 I get the following errors:



      gcc 8:



      <source>:5:8: error: template parameters not deducible in partial specialization:
      struct get_type_of_nontype<Template<Value>> {
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      <source>:5:8: note: 'T'


      clang 7:



      <source>:5:8: error: class template partial specialization contains a template parameter that cannot be deduced; this partial specialization will never be used [-Wunusable-partial-specialization]
      struct get_type_of_nontype<Template<Value>> {
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      <source>:4:16: note: non-deducible template parameter 'T'
      template<class T, T Value, template<T> class Template>
      ^


      And then they both complain that struct get_type_of_nontype<int_non_type<0>> is incomplete, so typename get_type_of_non_type<int_non_type<0>>::type can't compile.



      Why is this different between C++14 and C++17? Is this just a compiler bug? If not, is there a way to do this in C++14?







      c++ templates c++14 c++17 template-templates






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 6 at 23:11









      ArtyerArtyer

      4,705728




      4,705728






















          1 Answer
          1






          active

          oldest

          votes


















          1














          The Standard wording in [temp.deduct.type] paragraphs 13 and 14 changed. So yes, your example is invalid in C++14, but is allowed in C++17 thanks to a new language feature.



          C++14:




          A template type argument cannot be deduced from the type of a non-type template-argument.



          [Example:



          template<class T, T i> void f(double a[10][i]);
          int v[10][20];
          f(v); // error: argument for template-parameter T cannot be deduced


          -- end example]




          C++17:




          When the value of the argument corresponding to a non-type template parameter P that is declared with a dependent type is deduced from an expression, the template parameters in the type of P are deduced from the type of the value. [Example:



          template<long n> struct A ;

          template<typename T> struct C;
          template<typename T, T n> struct C<A<n>>
          using Q = T;
          ;

          using R = long;
          using R = C<A<2>>::Q; // OK; T was deduced to long from the
          // template argument value in the type A<2>


          -- end example] The type of N in the type T[N] is std::size_t. [Example:



          template<typename T> struct S;
          template<typename T, T n> struct S<int[n]>
          using Q = T;
          ;

          using V = decltype(sizeof 0);
          using V = S<int[42]>::Q; // OK; T was deduced to std::size_t from the type int[42]


          -- end example]



          [Example:



          template<class T, T i> void f(int (&a)[i]);
          int v[10];
          void g()
          f(v); // OK: T is std::size_t



          -- end example]




          This seems a bit related to another C++17 template change: C++17 is the first version to allow placeholder types in non-type template parameters, as in template <auto Value> or template <auto* Ptr>. I'd expect compiler implementations would need some similar logic for supporting both of the two language features.






          share|improve this answer























          • Oh so T is deduced from T Value and not template <T> class. This makes it sound like there is no way to do this at all in C++14.

            – Artyer
            Mar 6 at 23:44











          • Probably not. Unless maybe you only need to support a finite list of types like the arithmetic types, in which case you could write a specialization for each one.

            – aschepler
            Mar 6 at 23:46










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033649%2ftype-of-non-type-parameter-in-template-template-class-is-non-deducible-in-c14%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The Standard wording in [temp.deduct.type] paragraphs 13 and 14 changed. So yes, your example is invalid in C++14, but is allowed in C++17 thanks to a new language feature.



          C++14:




          A template type argument cannot be deduced from the type of a non-type template-argument.



          [Example:



          template<class T, T i> void f(double a[10][i]);
          int v[10][20];
          f(v); // error: argument for template-parameter T cannot be deduced


          -- end example]




          C++17:




          When the value of the argument corresponding to a non-type template parameter P that is declared with a dependent type is deduced from an expression, the template parameters in the type of P are deduced from the type of the value. [Example:



          template<long n> struct A ;

          template<typename T> struct C;
          template<typename T, T n> struct C<A<n>>
          using Q = T;
          ;

          using R = long;
          using R = C<A<2>>::Q; // OK; T was deduced to long from the
          // template argument value in the type A<2>


          -- end example] The type of N in the type T[N] is std::size_t. [Example:



          template<typename T> struct S;
          template<typename T, T n> struct S<int[n]>
          using Q = T;
          ;

          using V = decltype(sizeof 0);
          using V = S<int[42]>::Q; // OK; T was deduced to std::size_t from the type int[42]


          -- end example]



          [Example:



          template<class T, T i> void f(int (&a)[i]);
          int v[10];
          void g()
          f(v); // OK: T is std::size_t



          -- end example]




          This seems a bit related to another C++17 template change: C++17 is the first version to allow placeholder types in non-type template parameters, as in template <auto Value> or template <auto* Ptr>. I'd expect compiler implementations would need some similar logic for supporting both of the two language features.






          share|improve this answer























          • Oh so T is deduced from T Value and not template <T> class. This makes it sound like there is no way to do this at all in C++14.

            – Artyer
            Mar 6 at 23:44











          • Probably not. Unless maybe you only need to support a finite list of types like the arithmetic types, in which case you could write a specialization for each one.

            – aschepler
            Mar 6 at 23:46















          1














          The Standard wording in [temp.deduct.type] paragraphs 13 and 14 changed. So yes, your example is invalid in C++14, but is allowed in C++17 thanks to a new language feature.



          C++14:




          A template type argument cannot be deduced from the type of a non-type template-argument.



          [Example:



          template<class T, T i> void f(double a[10][i]);
          int v[10][20];
          f(v); // error: argument for template-parameter T cannot be deduced


          -- end example]




          C++17:




          When the value of the argument corresponding to a non-type template parameter P that is declared with a dependent type is deduced from an expression, the template parameters in the type of P are deduced from the type of the value. [Example:



          template<long n> struct A ;

          template<typename T> struct C;
          template<typename T, T n> struct C<A<n>>
          using Q = T;
          ;

          using R = long;
          using R = C<A<2>>::Q; // OK; T was deduced to long from the
          // template argument value in the type A<2>


          -- end example] The type of N in the type T[N] is std::size_t. [Example:



          template<typename T> struct S;
          template<typename T, T n> struct S<int[n]>
          using Q = T;
          ;

          using V = decltype(sizeof 0);
          using V = S<int[42]>::Q; // OK; T was deduced to std::size_t from the type int[42]


          -- end example]



          [Example:



          template<class T, T i> void f(int (&a)[i]);
          int v[10];
          void g()
          f(v); // OK: T is std::size_t



          -- end example]




          This seems a bit related to another C++17 template change: C++17 is the first version to allow placeholder types in non-type template parameters, as in template <auto Value> or template <auto* Ptr>. I'd expect compiler implementations would need some similar logic for supporting both of the two language features.






          share|improve this answer























          • Oh so T is deduced from T Value and not template <T> class. This makes it sound like there is no way to do this at all in C++14.

            – Artyer
            Mar 6 at 23:44











          • Probably not. Unless maybe you only need to support a finite list of types like the arithmetic types, in which case you could write a specialization for each one.

            – aschepler
            Mar 6 at 23:46













          1












          1








          1







          The Standard wording in [temp.deduct.type] paragraphs 13 and 14 changed. So yes, your example is invalid in C++14, but is allowed in C++17 thanks to a new language feature.



          C++14:




          A template type argument cannot be deduced from the type of a non-type template-argument.



          [Example:



          template<class T, T i> void f(double a[10][i]);
          int v[10][20];
          f(v); // error: argument for template-parameter T cannot be deduced


          -- end example]




          C++17:




          When the value of the argument corresponding to a non-type template parameter P that is declared with a dependent type is deduced from an expression, the template parameters in the type of P are deduced from the type of the value. [Example:



          template<long n> struct A ;

          template<typename T> struct C;
          template<typename T, T n> struct C<A<n>>
          using Q = T;
          ;

          using R = long;
          using R = C<A<2>>::Q; // OK; T was deduced to long from the
          // template argument value in the type A<2>


          -- end example] The type of N in the type T[N] is std::size_t. [Example:



          template<typename T> struct S;
          template<typename T, T n> struct S<int[n]>
          using Q = T;
          ;

          using V = decltype(sizeof 0);
          using V = S<int[42]>::Q; // OK; T was deduced to std::size_t from the type int[42]


          -- end example]



          [Example:



          template<class T, T i> void f(int (&a)[i]);
          int v[10];
          void g()
          f(v); // OK: T is std::size_t



          -- end example]




          This seems a bit related to another C++17 template change: C++17 is the first version to allow placeholder types in non-type template parameters, as in template <auto Value> or template <auto* Ptr>. I'd expect compiler implementations would need some similar logic for supporting both of the two language features.






          share|improve this answer













          The Standard wording in [temp.deduct.type] paragraphs 13 and 14 changed. So yes, your example is invalid in C++14, but is allowed in C++17 thanks to a new language feature.



          C++14:




          A template type argument cannot be deduced from the type of a non-type template-argument.



          [Example:



          template<class T, T i> void f(double a[10][i]);
          int v[10][20];
          f(v); // error: argument for template-parameter T cannot be deduced


          -- end example]




          C++17:




          When the value of the argument corresponding to a non-type template parameter P that is declared with a dependent type is deduced from an expression, the template parameters in the type of P are deduced from the type of the value. [Example:



          template<long n> struct A ;

          template<typename T> struct C;
          template<typename T, T n> struct C<A<n>>
          using Q = T;
          ;

          using R = long;
          using R = C<A<2>>::Q; // OK; T was deduced to long from the
          // template argument value in the type A<2>


          -- end example] The type of N in the type T[N] is std::size_t. [Example:



          template<typename T> struct S;
          template<typename T, T n> struct S<int[n]>
          using Q = T;
          ;

          using V = decltype(sizeof 0);
          using V = S<int[42]>::Q; // OK; T was deduced to std::size_t from the type int[42]


          -- end example]



          [Example:



          template<class T, T i> void f(int (&a)[i]);
          int v[10];
          void g()
          f(v); // OK: T is std::size_t



          -- end example]




          This seems a bit related to another C++17 template change: C++17 is the first version to allow placeholder types in non-type template parameters, as in template <auto Value> or template <auto* Ptr>. I'd expect compiler implementations would need some similar logic for supporting both of the two language features.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 6 at 23:38









          aschepleraschepler

          53k580129




          53k580129












          • Oh so T is deduced from T Value and not template <T> class. This makes it sound like there is no way to do this at all in C++14.

            – Artyer
            Mar 6 at 23:44











          • Probably not. Unless maybe you only need to support a finite list of types like the arithmetic types, in which case you could write a specialization for each one.

            – aschepler
            Mar 6 at 23:46

















          • Oh so T is deduced from T Value and not template <T> class. This makes it sound like there is no way to do this at all in C++14.

            – Artyer
            Mar 6 at 23:44











          • Probably not. Unless maybe you only need to support a finite list of types like the arithmetic types, in which case you could write a specialization for each one.

            – aschepler
            Mar 6 at 23:46
















          Oh so T is deduced from T Value and not template <T> class. This makes it sound like there is no way to do this at all in C++14.

          – Artyer
          Mar 6 at 23:44





          Oh so T is deduced from T Value and not template <T> class. This makes it sound like there is no way to do this at all in C++14.

          – Artyer
          Mar 6 at 23:44













          Probably not. Unless maybe you only need to support a finite list of types like the arithmetic types, in which case you could write a specialization for each one.

          – aschepler
          Mar 6 at 23:46





          Probably not. Unless maybe you only need to support a finite list of types like the arithmetic types, in which case you could write a specialization for each one.

          – aschepler
          Mar 6 at 23:46



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55033649%2ftype-of-non-type-parameter-in-template-template-class-is-non-deducible-in-c14%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page