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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:35:48+00:00 2026-06-15T02:35:48+00:00

I’ve been hanging around a problem for at least two weeks, being blocked by

  • 0

I’ve been hanging around a problem for at least two weeks, being blocked by stuff that I’m not able to understand and making questions in SO that doesn’t really pointed to the real problem (silly me!). Finally now, I wish I had found the real point of my headache in this question.

I’ve been using a template struct as helper to detect whether or not a given type has a member method or not, this template struct looks like this:

template
<
    typename Type,
    typename Return,
    typename Parameter,
    Return (Type::*)(Parameter)
> struct W {};

The main idea arround the struct W is to put as fourth parameter a member function pointer to the member function I need to test using the SFINAE trick, in a previous question an alternative was suggested and it helped me so much to understand many concepts that I’ve been missing, but in the end, it doesn’t solves my real problem.

The piece of code that i’m working on, must work in both Linux and Windows platforms, the compiler i’m using for windows is MSVC (Visual Stuido 2010 10.0) and gcc (Devian 4.4.5-8) on Linux side. The problem is that the same piece of code doesn’t compile in MSVC but it does in gcc (I was shocked, usually is the oposite, cause MSVC is less standard-strict).

The origin of the problem was that my SFINAE approach fails to detect the method set::insert while compiling under MSVC, in order to look for this fail i wrote a simple test:

#include <set>

int main(int argc, char **argv)
{
    typedef std::set<int> setint;

    std::pair<setint::iterator, bool> (setint::*p_1)(const setint::value_type &) = &setint::insert;
    W<setint, std::pair<setint::iterator, bool>, const setint::value_type &, &setint::insert> w_1;

    return 0;
}

As i mentioned before: this sample compiles without problem using gcc, but while using MSVC gives an error at the declaration of w_1:

error C2440: 'specialization' : cannot convert from 'overloaded-function' to 'std::pair<_Ty1,_Ty2> (__thiscall std::set<_Kty>::* )(const int &)'
    with
    [
        _Ty1=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<int,std::less<int>,std::allocator<int>,false>>>,
        _Ty2=bool,
        _Kty=int
    ]
    None of the functions with this name in scope match the target type

While creating a function pointer works as expected, so the declaration of p_1 compiles; but with the same signature as template parameter does not. This is why the set::insert detection fails during the symbols substitution of SFINAE. The error text cannot convert from 'overloaded-function' doesn’t provides me any clue about what’s going on (or i’m not able to find any, due my poor english understanding).

At first sight, i’ve been thinking that the problem is the symbols substitution, but it would make sense if it failed in both MSVC and gcc as well. So for now i’m wondering if the problem is some MSVC compiler-specific way to do things.

Any clue about why is it failing under MSVC and how to make gcc and MSVC works in the same way?

Extra question: std::map and std::set provides a nested type _Pairib as return type for ::insert method under the MSVC implementation of red-black tree (or whatever is under map and set), there’s no equivalent in the gcc implementation?

EDIT:

After reading the chill answer, I’ve looked into the MSVC’s std::set implementation.

std::set is a derived class of std::_Tree that provides the method i want to check:

// class std::_Tree, file xtree in the path 'VisualStudioPath/VC/include/'
_Pairib insert(const value_type& _Val)
    {    // try to insert node with value _Val, favoring right side
    return (insert(_Val, false));
    }

This insert method belongs to the std::_Tree scope, not to std::set scope, but it is into the public scope and is a inherited method as well, so why it isn’t accesible during the name substitution?

  • 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-15T02:35:49+00:00Added an answer on June 15, 2026 at 2:35 am

    The cause for failing is that in the VC stdlib, the insert is not actually a member of the set class template itself, but is inherited:

    Test case,

    template
    <
        typename Type,
        typename Return,
        typename Parameter,
        Return (Type::*)(Parameter)
    > struct W {};
    
    struct A { void foo (int); };
    
    struct B : public A {};
    
    int main(int argc, char **argv)
    {
        void (B::*p)(int) = &B::foo;
        // W<B, void, int, &B::foo> w; // error
        W<A, void, int, &A::foo> w;
    
        return 0;
    }
    

    PS. The error is error in both some GCC and some MSVC.

    But it is on the public scope and is an inherited method as well, so I don’t get why isn’t it accesible.

    Because no conversion is allowed in this case, “14.3.2. Template non-type arguments [#5]”

    For a non-type template-parameter of type pointer to member function,
    if the template-argument is of type std::nullptr_t, the null member
    pointer conversion (4.11) is applied; otherwise, no conversions apply.
    If the template-argument represents a set of overloaded member
    functions, the matching member function is selected from the set
    (13.4).

    PPS. So, you do the conversion explicitly and voila, you don’t need to care for possible base classes:

    W<setint,
      std::pair<setint::iterator, bool>,
      const setint::value_type &,
      static_cast<std::pair<setint::iterator, bool> (setint::*)(const setint::value_type &)> (&setint::insert)> w_1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I have been unable to fix a problem with Java Unicode and encoding. The
I need a function that will clean a strings' special characters. I do NOT
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace

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.