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 8436457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:10:59+00:00 2026-06-10T07:10:59+00:00

Consider the following typical SFINAE test function (it checks if a type has a

  • 0

Consider the following typical SFINAE test function (it checks if a type has a begin() member function)

    template <class> constexpr bool
has_begin_member (...) { return false; }

    template <class T> constexpr bool
has_begin_member (decltype (std::declval <T>().begin ())* = 0) { 
    return true;
}

I can call it with an argument:

has_begin_member <int> (0); // yields false

but without any arguments:

has_begin_member <int> (); // compilation error

it leads to the following ambiguity:

error: call of overloaded 'has_begin_member()' is ambiguous
note: candidates are:
note: constexpr bool has_begin_member(...)
note: constexpr bool has_begin_member(decltype (declval<T>().begin())*)

Why doesn’t the “ellipsis trick” work in that case?

Edit: full program:

#include <utility>
#include <vector>

    template <class> constexpr bool
has_begin_member (...) { return false; }

    template <class T> constexpr bool
has_begin_member (decltype (std::declval <T>().begin ())* = 0) { 
    return true;
}


static_assert (!has_begin_member <int> (0), "broken");
static_assert (has_begin_member <std::vector <int>> (0), "broken");

static_assert (!has_begin_member <int> (), "broken");
static_assert (has_begin_member <std::vector <int>> (), "broken");

    int 
main (){}

Compilation:

g++ -std=c++11 -o toto ./toto.cpp
./toto.cpp:17:58: error: call of overloaded 'has_begin_member()' is ambiguous
./toto.cpp:17:58: note: candidates are:
./toto.cpp:5:5: note: constexpr bool has_begin_member(...) [with <template-parameter-1-1> = std::vector<int>]
./toto.cpp:8:5: note: constexpr bool has_begin_member(decltype (declval<T>().begin())*) [with T = std::vector<int>; decltype (declval<T>().begin()) = __gnu_cxx::__normal_iterator<int*, std::vector<int> >]
  • 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-10T07:11:01+00:00Added an answer on June 10, 2026 at 7:11 am

    For the has_begin_member<int>() case the second overload is not viable because template argument substitution fails, so only the first overload is viable, so no ambiguity.

    For the has_begin_member<std::vector<int>>() case substitution succeeds so there are two viable functions.

    13.3.2 [over.match.viable]:

    • If there are m arguments in the list, all candidate functions having exactly m parameters are viable.
    • A candidate function having fewer than m parameters is viable only if it has an ellipsis in its parameter
      list (8.3.5). For the purposes of overload resolution, any argument for which there is no corresponding
      parameter is considered to “match the ellipsis” (13.3.3.1.3) .
    • A candidate function having more than m parameters is viable only if the (m+1)-st parameter has a
      default argument (8.3.6). For the purposes of overload resolution, the parameter list is truncated
      on the right, so that there are exactly m parameters.

    In this case m is zero, the first overload is viable (by the second bullet) and the second overload is also viable (by the third bullet) but for the purposes of overload resolution the parameter with a default argument is ignored, and so the best viable functions is found by comparing:

    template<> constexpr bool has_begin_member<vector<int>>(...);
    template<> constexpr bool has_begin_member<vector<int>>();
    

    Which is obviously ambiguous, just like this is:

    int f(...);
    int f();
    
    int i = f();  // error
    

    There is no conversion sequence needed to call either function, so they cannot be ranked in terms of which has a “better conversion sequence” than the other (using the rules in 13.3.3.2 [over.ics.rank],) which means they are ambiguous.

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

Sidebar

Related Questions

Consider a typical social networking website, which has more or less the following models:
Consider the following class: class MyClass { public: template<class T> typename T::result_type apply(T& func)
Consider the following function template: template<typename T> void Foo(T) { // ... } Pass-by-value
Consider the following code snippet: class Test { public int Length{ get; set; }
Consider following class class test { public: test(int x){ cout<< test \n; } };
Consider the following typical Scala 'pimp' code: class PimpedA(a:A){ def pimp() = hi }
Consider following: <div class=wrap> <div class=left></div> <div class=right></div> </div> Left div has less height
Consider following class of custom array template <typename element, unsigned int size> class array
Consider following 2 programs giving same error First calss: public class Testing { Testing
Consider following tables in MySQL database: entries: creator_id INT entry TEXT is_expired BOOL other:

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.