简体   繁体   English

定义_HAS_TRADITIONAL_STL以启用STL功能是否安全?

[英]Is it safe to define _HAS_TRADITIONAL_STL to enable STL functionality?

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. 在尝试在VS2008项目中使用<functional>中的std::select1st ,我发现它是由_HAS_TRADITIONAL_STL防护程序ifdef确定的。

  • Is there a reason for this? 是否有一个原因?

  • Is it safe to simply define _HAS_TRADITIONAL_STL before including <functional> ? 在包含<functional>之前简单地定义_HAS_TRADITIONAL_STL是否安全?

The reason std::select1st is not present by default is that it is not part of the C++ standard library. 默认情况下不存在std::select1st的原因是它不属于C ++标准库。 It is one of the parts of the Standard Template Library (STL) that was not adopted into the C++ standard. 它是标准模板库(STL)的一部分,未被C ++标准采用。

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. 我在MSDN上找不到有关_HAS_TRADITIONAL_STL任何文档,并且似乎没有在Visual Studio 2010附带的标准库版本中使用它。当Dinkumware将其交付给Microsoft时,该库可能已包含在该库中。

That having been said, it is probably safe to define if you want to use std::select1st . 话虽如此,定义是否要使用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++). 请注意,使用由该标志启用的任何功能都是特定于实现的,并且不可移植(甚至在Visual C ++的版本之间可能会发生变化)。 You would probably be better off implementing your own select1st function: 您可能最好实现自己的select1st函数:

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; }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM