Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9006763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:29:58+00:00 2026-06-16T01:29:58+00:00

This question follows : Force a specific overload when template template Consider the following

  • 0

This question follows : Force a specific overload when template template

Consider the following code :

#include <iostream>
#include <vector>
#include <array>
#include <type_traits>

// Version A
template<typename T>
void f(const T& x)
{
    std::cout<<"Version A"<<std::endl;
}

// Version B
template<typename... T1, template<typename...> class T>
void f(const T<T1...>& x)
{
    std::cout<<"Version B"<<std::endl;
}

// Version C
template<typename T1, typename TN, template<typename, TN...> class T, TN... N>
void f(const T<T1, N...>& x)
{
    std::cout<<"Version C"<<std::endl;
}

// Main
int main(int argc, char* argv[])
{
    f(double());
    f(std::vector<double>());
    f(std::array<double, 3>()); // <- How to force the use of Version C ?
    return 0;
}

By default, it will produce (with GCC 4.7.1) :

Version A
Version B
Version A

How to force the use of Version C when the passed type is a template with the good shape (I can add new versions of f, I can add std::enable_if or other C++11 type traits syntax, but if possible I would like to avoid adding an helper class) ?

Note : The trick should work for every integral type TN…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:29:59+00:00Added an answer on June 16, 2026 at 1:29 am

    You can’t deduce the type of a non-type template argument in template argument deduction. This is explicitly stated in the standard:

    14.8.2.5 Deducing template arguments from a type [temp.deduct.type]

    13 – A template type argument cannot be deduced from the type of a non-type template-argument.
    14 – [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 ]

    This works:

    // Version C
    template<typename T1, template<typename, size_t...> class T, size_t... N>
    void f(const T<T1, N...>&) {
        std::cout<<"Version C"<<std::endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem follows on from a previous question . When I run the following
This question follows this one : Function overloading and template deduction priority Considering the
This question follows on from a previous question, that has raised a further issue.
This question follows on from a previous question. However stackoverflow presents me from commenting
this follows on from my last question which I thought was answered but for
This question follows on from a question I asked yesterday about why using the
This question follows on from the problem posted here when i run explain I
this question follows on from previous thread: XSLT: Sorting based on sum of values
This question is a follow on from this one ... I am binding to
This question is a follow up with a previous question Previous Question The previous

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.