有没有办法让 C 预处理器更改我正在使用的 STL 实现?

Is there a way to have the C preprocessor change which STL implementation I'm using?

本文关键字:实现 STL 预处理 处理器 有没有      更新时间:2023-10-16

我沿着

的行中的C 代码
#include<vector>
std::vector<double> foo;

我需要为嵌入式平台编译此代码,该平台使用称为USTL的STL的自定义实现。使用它需要#include ustl.h标头文件,并且所有STL类都在另一个名称空间中定义。因此,以上片段应成为

#include<ustlh.>
ustl::vector<double> foo;

我不想修改源代码,因为它是其他非安装应用程序使用的库代码。我正在考虑使用C预处理器将#include<vector>转换为#include<ustl.h>,但这似乎是不可能的(宏名称必须是有效的标识符)。

有其他方法可以让C预处理器这样做吗?还是另一种方式不会暗示修改原始源代码?

您必须做类似的事情:

#ifdef USE_USTL
#include <ustl.h>
using ustl::vector;
#else
#include <vector>
using std::vector;
#endif
vector<double>  foo;