c++ - g++ : should --std option change which STL/stdlib my code uses?

标签 c++ c++11 gcc stl g++

我很困惑最近的 g++(例如 4.8 或 4.9)是否应该根据所选择的 --std 选项引用不同的 STL。具体来说,给定选项 --std=c++98 与 --std=c++11,在那种情况下我的代码不应该看到/使用两个不同的 STL 吗?然而,当我使用 c++98 选项编译时,似乎我仍在获取最新的 STL,这显然不起作用,因为它使用了许多仅 c++11 的东西。我在我的系统上搜索过,只找到了一份 STL 头文件(c++11 的)。任何关于它应该如何工作的澄清都是值得赞赏的。

最佳答案

如果您打开其中一些 header ,那么您会在 bits/STL_algo.h

中看到类似这样的开关
#if __cplusplus >= 201103L
  /**
   *  @brief  Checks that a predicate is true for all the elements
   *          of a sequence.
   *  @ingroup non_mutating_algorithms
   *  @param  __first   An input iterator.
   *  @param  __last    An input iterator.
   *  @param  __pred    A predicate.
   *  @return  True if the check is true, false otherwise.
   *
   *  Returns true if @p __pred is true for each element in the range
   *  @p [__first,__last), and false otherwise.
  */
  template<typename _InputIterator, typename _Predicate>
    inline bool
    all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
    { return __last == std::find_if_not(__first, __last, __pred); }

...

#endif

对于不同的 -std 开关设置,实现必须维护这些文件的不同拷贝是荒谬的。

关于c++ - g++ : should --std option change which STL/stdlib my code uses?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28351987/

相关文章:

c++ - Direct3D Sprite->SetTransform 用法?

c++ - 如何返回 std::string.c_str()

c++ - 通过手动安装库来修复gcc undefined include <>

Javascript 映射变量

c++ - Poco::Net HTTPServer:如何检测断开连接的客户端?

c++ - 可见性生效时如何导出公共(public)内部/嵌套类?

C++ 运算符 []

c++ - 如何使用 gtest 构造检查存储在 vector 中的结构(字段)?

c - 如何使用 GNU 工具链来学习 C 编程?

c - 在 C 中的变量中定义的数组大小无法在 IAR 中编译,但在 Keil 中构建良好