【问题标题】:Is there a way to have the C preprocessor change which STL implementation I'm using?有没有办法让 C 预处理器更改我正在使用的 STL 实现?
【发布时间】:2017-04-10 18:21:13
【问题描述】:

我的 C++ 代码类似于

#include<vector>

std::vector<double> foo;

我需要为使用称为uSTL 的STL 自定义实现的嵌入式平台编译此代码。使用它需要#includeing 一个ustl.h 头文件和all STL classes are defined in another namespace。因此上面的 sn-p 应该变成

#include<ustlh.>

ustl::vector<double> foo;

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

还有其他方法可以让 C 预处理器执行此操作吗?或者有没有其他不意味着修改原始源代码的方法?

【问题讨论】:

    标签: c++ stl c-preprocessor


    【解决方案1】:

    您必须执行以下操作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-21
      • 2021-06-30
      • 1970-01-01
      • 2019-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多