2016-11-26 57 views
1

我在C++代码一起的有没有办法让C预处理器改变我使用的STL实现?

#include<vector> 

std::vector<double> foo; 

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

#include<ustlh.> 

ustl::vector<double> foo; 

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

是否有另一种方法让C预处理器执行此操作?还是有另一种方式,并不意味着修改原始源代码?

回答

0

你不得不做这样的事情:

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

vector<double> foo; 
相关问题