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

时间:2016-11-26 16:22:27

标签: c++ stl c-preprocessor

我在C ++中有

的代码
#include<vector>

std::vector<double> foo;

我需要为嵌入式平台编译此代码,该平台使用名为uSTL的自定义STL实现。使用它需要#include ustl.h头文件和all STL classes are defined in another namespace。因此上面的代码段应该成为

#include<ustlh.>

ustl::vector<double> foo;

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

有没有其他方法让C预处理器执行此操作?或者是否有其他方式不会暗示修改原始源代码?

1 个答案:

答案 0 :(得分:0)

你必须做类似的事情:

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

vector<double>  foo;