提问人:rishabh thakkar 提问时间:3/28/2023 最后编辑:johnrishabh thakkar 更新时间:3/28/2023 访问量:55
了解延迟宏
Understanding deferring macro
问:
我正在尝试理解延迟的宏层次结构。这有意义吗?
// Online C++ compiler to run C++ program online
#include <iostream>
#define EMPTY()
#define EVAL_1(...) __VA_ARGS__
#define EVAL_2(...) EVAL_1(EVAL_1(__VA_ARGS__))
#define DEFER(...) __VA_ARGS__ EMPTY()
#define DEFER2(...) __VA_ARGS__ DEFER(EMPTY) ()
#define DEFER3(...) __VA_ARGS__ DEFER2(EMPTY) ()
#define DEFER4(...) __VA_ARGS__ DEFER3(EMPTY) ()
#define A(x) x
int main() {
// The parameter is evaluated during expansion.
std::cout << (EVAL_1(DEFER(A)(5)))<<std::endl; //line 1: evaluate(A (5)) = 5. Output = 5
//std::cout << (EVAL_1(DEFER2(A)(5)))<<std::endl; // line 2: evaluate(A EMPTY() (5)) = A(5), Output = error.
//std::cout << (EVAL_1(DEFER3(A)(5)))<<std::endl; // line 3: evaluate(A EMPTY EMPTY() () (5)) = A EMPTY() (5), Output = error.
//std::cout << (EVAL_1(DEFER4(A)(5)))<<std::endl; // line 4: evaluate(A EMPTY EMPTY EMPTY() () () (5)) = A EMPTY EMPTY () () (5), Output = error.
std::cout << (EVAL_2(DEFER(A)(5)))<<std::endl; //line 5: evaluate(evaluate(5)) from line 1. Output = 5.
std::cout << (EVAL_2(DEFER2(A)(5)))<<std::endl;//line 6: evaluate(evaluate(A(5))) = 5. Output =5
std::cout << (EVAL_2(DEFER3(A)(5)))<<std::endl;//line 7: evaluate(evaluate(A EMPTY() (5)))=5.
//std::cout <<(EVAL_2(DEFER4(A)(5)))<<std::endl;//line8: error
return 0;
}
是否有任何我遗漏或误解的微妙特征?
答: 暂无答案
评论