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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:51:11+00:00 2026-06-17T20:51:11+00:00

We have a problem porting our code to the slightly less old version 2010

  • 0

We have a problem porting our code to the slightly less old version 2010 of VC++.

The issues is caused by the implementation of map in VC which results in a derived to base conversion of a pointer-to-member in a non-type-argument being required:

#include <map>
#include <algorithm>

template <typename MapValueType, int MapValueType::*var>
bool f (MapValueType const & v);

int main ()
{
  typedef std :: map<int, int> MapType;
  MapType m;
  std :: find_if (m.begin ()
      , m.end ()
      , f<MapType::value_type, & MapType::value_type::second> );
}

The following message is generated:

Standard conversion from pointer-to-member of base to pointer-to-member of derived is not applied for template arguments file.cc(x) : error C2973:
‘f’ : invalid template argument ‘int std::_Pair_base<_Ty1,_Ty2>::* ‘

So it seems that the implementation of value_type in std::map has the pair in a base class.

Any ideas on how to solve this and keep the pointer-to-member as a non-type-argument?

Is our only option to change the structure so that f is a functor with a member pointer-to-member?

  • 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-17T20:51:12+00:00Added an answer on June 17, 2026 at 8:51 pm

    Provided that your code should compile IMO (and it does on GCC 4.7.2 and Clang 3.2), I believe your design is unnecessarily intricate. A pair only has two member variables, so you are going to access either the first or the second.

    I do not see the need for a functor object either: just use a boolean template argument to determine whether the code shall work on the first or on the second member variable.
    Here’s a possibility:

    #include <map>
    #include <algorithm>
    
    template <typename MapValueType, bool first>
    bool f (MapValueType const & p)
    {
        auto& v = (first) ? p.first : p.second;
        // ... do your work on v ...    
    }
    
    int main ()
    {
        typedef std :: map<int, int> MapType;
        MapType m;
    
        // Will work on the `first` member
        std::find_if(m.begin (), m.end (), f<MapType::value_type, true>);
    
        // Will work on the `second` member
        std::find_if(m.begin (), m.end (), f<MapType::value_type, false>);
    }
    

    If you really cannot change your client code nor your code inside the f() function, then you could go for this VS2010-specific hack:

    // Add "_MyBase" here... works, but ugly IMO
    template <typename MapValueType, int MapValueType::_Mybase::* var>
    bool f(MapValueType const & v);
    
    // And the client side could stay unchanged...
    int main ()
    {
        typedef std :: map<int, int> MapType;
        MapType m;
        std::find_if(
            m.begin(), 
            m.end (), 
            f<MapType::value_type, &MapType::value_type::second>
            );
    }
    

    Finally, if your code has to compile on other platforms and all the constraints on the non-modifiability of the function’s and client code still hold, then you can define a preprocessor macro that expands to _Mybase:: for VS2010 and to the empty string for other compilers.

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

Sidebar

Related Questions

We have recently been faced with the problem of porting our C++ framework to
I am currently tasked with porting our website code onto a linux server (from
I have some binary data which has a corresponding map file which identifies each
I currently have an ActiveX control which links in many c/c++ dlls. The problem
I'm in the process of porting some old C code to Java and, due
I'm porting a Delphi project to 64 bits and I have a problem with
Good day, Stackoverflow! I have a little (big) problem with porting one of my
We are porting our app to Delphi XE2 from Delphi 6. Problem is, the
I have a problem POSTing data via HTTPS in Java. The server response is
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar

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.