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

  • SEARCH
  • Home
  • 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 971159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:55:02+00:00 2026-05-16T02:55:02+00:00

Does C++ standard guarantee the following?: template<typename T> void function(T (&)[1]); template<typename T> void

  • 0

Does C++ standard guarantee the following?:

template<typename T>
void function(T (&)[1]);

template<typename T>
void function(T*);

int a[1];
function(a); // first function gets called, not second version
  • 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-05-16T02:55:03+00:00Added an answer on May 16, 2026 at 2:55 am

    Yes, this is guaranteed, but the reason is different than what GMan says. The “array of length 1” overload will be selected because it is more specialized than the second in template functions partial order. Basically, it means that an argument in the form T(&)[1] will always match the second template argument in the form T*, so the first overload will always be selected when conversion sequences don’t decide.

    From 13.3.3:

    Given these definitions, a viable
    function F1 is defined to be a better
    function than another viable function
    F2 if for all arguments i, ICSi(F1) is
    not a worse conversion sequence than
    ICSi(F2), and then

    • for some argument j, ICSj(F1) is a better conversion sequence than
      ICSj(F2), or, if not that,

    • F1 is a non-template function and F2 is a template function specialization,
      or, if not that,

    • F1 and F2 are template functions, and the function template for F1 is
      more specialized than the tem- plate
      for F2 according to the partial
      ordering rules described in 14.5.5.2,
      or, if not that,

    …

    Normal functions are only affected by the first item; when any template functions are in the set of candidate functions, the second or third item can decide. The reason we want it like that is we want to be able to write seemingly ambiguous templated overloads. Eg.

    template <class T> void f(T);
    template <class T> void f(T*);
    

    would otherwise be ambiguous for int*. In C++0x, you can even write declarations like:

    template <class ...Ts>           void f(const Ts&... args);
    template <class T, class ... Ts> void f(const T& a, const Ts&... args);
    

    and the second will be selected whenever there is at least one argument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does the standard guarantee that order of equal elements will not change (eh, forgot
I believe that the C++ standard for std::sort does not guarantee O(n) performance on
Does the C standard support something similar to __func__ for the function arguments' names?
In the C++11 standard, Section 23.3.6.2 [vector.cons], the following is said: template <class InputIterator>
Given that: 1) The C++03 standard does not address the existence of threads in
Does C++ standard guarantee that here would be no crash when returning auto_ptr 's
Is this guaranteed to be always true: std::numeric_limits<int>::max() == INT_MAX What does C++ standard
Is the following code portable? template<typename In> struct input_sequence_range : public pair<In,In> { input_sequence_range(In
§24.1.1/3 from C++03 Standard reads, For input iterators, a == b does not imply
Does the C++ standard guarantee that the call c = std::min(f(x), g(x)); evaluates the

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.