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

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived