1

I am porting a large C++ COM project from VS2008 to VS2010. There is a line of code as follows, which compiles fine in my VS2008 project, but gives the referenced error when compiled in VS2010:

std::select2nd<std::map<DWORD, ISomethingUseful*>::value_type>());

The compile error is:

error C2039: 'select2nd' : is not a member of 'std'

I know this is a "non standard" function, but whoever wrote this code originally found it in the std namespace in VS2008, and whichever #include they used seems to be no longer correct in VS2010.

Does anyone know where this function is now in VS2010? And specifically which header file needs to be included now to use it?


EDIT: To get around this problem for now I've grabbed the code from the VS2008 VC\include\functional header file, and included in my code base (inside a utility class) as outlined in my answer below.

Would still appreciate any insights that anyone else is able to provide!

Ozraptor
  • 564
  • 4
  • 11
  • Are you sure that whoever wrote this code _found_ the function in std, not _added_ the function to std? – SingerOfTheFall Jul 17 '12 at 06:35
  • Hmmm - well if they wrote it and added it to the std namespace, I can't find the source for that anywhere in the solution / project space I am working in. Good point though - will have a good look around and make sure it is not hiding somewhere! – Ozraptor Jul 17 '12 at 06:39
  • Did you see http://stackoverflow.com/questions/771453/copy-map-values-to-vector-in-stl? – Digital Da Jul 17 '12 at 06:43
  • 1
    @DigitalDa, what does it have to do with the question? – SingerOfTheFall Jul 17 '12 at 06:46
  • Ok the plot thickens - in the old VS2008 project the function comes from the in-built library/header. It is missing from that header in VS2010. So the question is has it been deprecated? Or just moved? Note an MSDN search and google search has not shed any light on the answer to this question so far! – Ozraptor Jul 17 '12 at 06:50
  • @DigitalDa - yes I already found that one in my searches, but it does not answer my question. – Ozraptor Jul 17 '12 at 06:52
  • 2
    I tried searching the VS2010 library, it doesn't look like it's included at all. This reference seems to suggest it was an SGI non-standard function: http://www.sgi.com/tech/stl/select2nd.html . It looks like it does the same as ".second" though so you could try that or write the function yourself and implement it as .second. – Scott Logan Jul 17 '12 at 07:02
  • 1
    By the looks of it, it was part of stl_function.h, the old header for functional. In the SGI implementation there is even a comment: //select1st and select2nd are extensions: they are not part of the standard. You could nab the code from www.sgi.com/tech/stl/stl_function.h if you need it. – Yuushi Jul 17 '12 at 07:10
  • 3
    Well for now I've got things going by copying the VS2008 implementation of the select2nd function from and including it in my code base. I'll wait and see if anyone comes up with a better answer, if not I'll post the solution here including the source code to use, for posterity! Thanks for the help so far. – Ozraptor Jul 17 '12 at 07:13
  • @SingerOfTheFall because one of the answers offered a workaround, similar to what Brendan chose. – Digital Da Jul 17 '12 at 08:40
  • I wonder why it is `const/const`... It is not standard, of course, meaning it can be implemented in any way. But it would make sense to enable the LHS usage, i.e. add a non-const version of the operator that returns a non-const reference. – AnT stands with Russia Aug 06 '12 at 05:32

1 Answers1

1

Well, it seems that the answer to this question is that the std::select2nd(...) function was supported in VS2008 via the functional library, but that it has been deprecated in VS2010. Here is the code from VS2008 that can be used if needed to re-incarnate this function when porting code to VS2010:

template<class Pair> struct select2nd : public std::unary_function<Pair, typename Pair::second_type>
{   
    // functor for unary second of pair selector operator
    const typename Pair::second_type& operator()(const Pair& Left) const
    {   
        // apply second selector operator to pair operand
        return (Left.second);
    }
};
MSalters
  • 173,980
  • 10
  • 155
  • 350
Ozraptor
  • 564
  • 4
  • 11