C++预处理器—联接参数
C++ preprocessor--join arguments
有没有一种方法可以让C++预处理器使用joiner令牌连接参数?
我已经学会了我可以做:
#include <boost/preprocessor/seq/cat.hpp>
#define arg1 foo
#define arg2 bar
#define arg3 baz
BOOST_PP_SEQ_CAT((arg1)(_)(arg2)(_)(arg3))
得到CCD_ 1。
我有两个问题:
- 有没有一种方法可以在没有重复的显式joiner的情况下做到这一点字符(
(_)
),并且对于可变长度的参数列表 有必要这样传递论点吗:
(arg1)(arg2)(arg3)
我可以把它包装在另一个宏中吗?这将允许我正常传递参数,即:
arg1, arg2, arg3
#define BOOST_PP_VARIADICS
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/seq/fold_left.hpp>
#include <boost/preprocessor/variadic/to_seq.hpp>
#define OP(s, state, x) BOOST_PP_CAT(state, BOOST_PP_CAT(_, x))
#define COMPOSE(...) BOOST_PP_SEQ_FOLD_LEFT(OP, BOOST_PP_SEQ_HEAD(BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)), BOOST_PP_SEQ_TAIL(BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)))
#define arg1 foo
#define arg2 bar
#define arg3 baz
COMPOSE(arg1, arg2, arg3)
关于:
#include <iostream>
#define COMPOSE(prefix,name) prefix##_##name
int main() {
int COMPOSE(first,par);
first_par = 1;
return first_par;
}
相关文章:
- 错误:无效的预处理指令 #i 的意思是 #if?
- C++预处理会生成变量成员、资源库和映射
- 使用预处理指令检查是否包含标头?
- 预处理的 C/C++ 文件是否特定于计算机?
- 使用 GCC 对 C 文件进行部分预处理(不删除 "define" 指令)
- 在 CPLEX 中求解线性规划,无需剪切和预处理
- CPP -D 选项,用于预处理 Fortran 代码
- 错误:粘贴"tmp_UINT"和"+"未提供有效的预处理令牌
- 任务计划程序库的预处理不起作用 - 多定义错误
- Eclipse 问题 - 编译期间不考虑 .c 和 .cpp 文件中定义的预处理
- 使用python预处理后,C++(opencv)中的垫子类型数据与image_to_array相同
- Howo 使用 cl 预处理为 masm 组装生成一个单独的文件
- 我有一个预处理的 C/C++ 源文件 (cacti.i).如何从这个 .i 文件生成可执行二进制文件,以便我可以像 ./
- 如何使用Visual Studio C/C++编译器(cl.exe)来预处理我的objective-C代码
- 是具有预处理前分支实现的结构违反ODR
- 优化了标签(空结构)函数参数的处理
- C++开关-经过预处理的大小写参数
- C ++ MySQL 存储的预处理多个输出参数错误
- C++用2个参数预处理宏
- 在编译时在c/c++预处理宏中验证参数为ARRAY类型