我很困惑最近的 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/