g++:应该--std选项更改我的代码使用的STL/stdlib
g++ : should --std option change which STL/stdlib my code uses?
我对最近的g++(比如4.8或4.9)是否应该根据所选的--std选项引用不同的STL感到困惑。具体来说,给定选项--std=c++98 vs--std=c++11,在这种情况下,我的代码不应该看到/使用两个不同的STL吗?然而,当我使用c++98选项进行编译时,我似乎仍然得到了最新的STL,它显然不起作用,因为它使用了许多只使用c++11的东西。我在我的系统上搜索了一下,只找到了STL头文件的一个副本(c++11)。如有任何关于该如何运作的澄清,我们将不胜感激。
如果您打开了其中一些标头,那么您会在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
交换机设置维护这些文件的不同副本是没有意义的。
当然可以功能
但是,在实践中,您的实现可能会在它们之间共享相同的标准库实现代码,使用宏打开和关闭功能。GCC就是这么做的。
相关文章:
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 在C应用程序中运行C++(带有STL)函数
- 使用2个键的cpp-stl::优先级队列排序不正确
- 在STL容器中使用模板类
- 带有 -stdlib=libc++ 的 clang++ 9.0.1 找不到<optional>
- 用C++中的CPerson(类)类型的对象初始化STL矢量
- 将stl字符串缩小到小于15个字符的容量
- 在为LINUX创建共享库时,如何避免STL的私有/弱副本
- 检查函数返回类型是否与STL容器类型值相同
- STL算法函数在多个一维容器上的使用
- 在STL - C++中按成绩对学生列表进行排序?
- 为什么 STL 容器适配器堆栈中的 top 返回常量引用?
- λ可以适应STL吗?
- 为什么使用 NDK 不能存在不同的 stl 实现?
- 如果我真的真的想从 STL 容器继承,并且我继承构造函数并删除新运算符,会发生什么?
- 使用 char 分隔符解析C++中的字符串,但将可重复的字符保留为每个解析的子字符串 (C++ STL) 中的分隔符
- 在C++中迭代 STL 集时出现奇怪的问题<CStudent>
- g++:应该--std选项更改我的代码使用的STL/stdlib
- STL和stdlib之间的关系是什么