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

发布于 2024-08-26 07:05:29 字数 282 浏览 0 评论 0原文

在尝试在 VS2008 项目中使用 中的 std::select1st 时,我发现它被 _HAS_TRADITIONAL_STL ifdef 了。警卫。

  • 这有什么原因吗?

  • 在包含之前简单地定义_HAS_TRADITIONAL_STL是否安全?

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>?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔少女心 2024-09-02 07:05:30

默认情况下 std::select1st 不存在的原因是它不是 C++ 标准库的一部分。它是标准模板库 (STL) 中未采用 C++ 标准的部分之一。

我在 MSDN 上找不到 _HAS_TRADITIONAL_STL 的任何文档,并且它似乎没有在随 Visual Studio 2010 分发的标准库版本中使用。它可能包含在 Dinkumware 的库中当他们将其交付给微软时。

话虽如此,定义是否要使用 std::select1st 可能是安全的。请注意,使用该标志启用的任何内容都是特定于实现的且不可移植的(甚至可能在 Visual C++ 版本之间发生变化)。您最好实现自己的 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; }
};

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; }
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文