views:

168

answers:

1

In attempting to use std::select1st from <functional> in a VS2008 project I found that it was ifdef'd out by a _HAS_TRADITIONAL_STL guard.

  • Is there a reason for this?

  • Is it safe to simply define _HAS_TRADITIONAL_STL before including <functional>?

+5  A: 

The reason std::select1st is not present by default is that it is not part of the C++ standard library. It is one of the parts of the Standard Template Library (STL) that was not adopted into the C++ standard.

I can't find any documentation on MSDN for _HAS_TRADITIONAL_STL, and it doesn't appear to be used in the version of the standard library distributed with Visual Studio 2010. It is probably included in the library by Dinkumware when they deliver it to Microsoft.

That having been said, it is probably safe to define if you want to use std::select1st. Just note that using anything enabled by that flag is implementation-specific and nonportable (and may even change between versions of Visual C++). You would probably be better off implementing your own select1st function:

template <typename PairT>
struct select1st : public std::unary_function<PairT, typename PairT::first_type>
{
    typename PairT::first_type operator()(const PairT& a) { return a.first; }
};
James McNellis
Thanks! Any idea why select1st wasn't chosen to be part of the standard? the guard name seems to imply it's part of "traditional" stl.
Catskul
@Catskul: The _traditional STL_ is referring to the original standard template library implemented by SGI. Most of the STL was included in the C++ standard library; some things were not (e.g. `select1st` and, at least currently, `hash_map`). I don't know why some things were left out; someone else here would probably be able to answer that better than I.
James McNellis