Tyl*_*ler 3 c++ metaprogramming template-meta-programming c++20
我习惯使用 x 宏来生成强大的代码。我特别喜欢的功能之一是我不能弄乱值的顺序,也不能忘记一个。
我想知道数组和函数参数是否有类似的策略
例如:
如果一个库提供了一个函数:
void foobar(std::string_view k, std::string_view l, std::string_view m);
Run Code Online (Sandbox Code Playgroud)
在我的代码库中我有:
constexpr std::array<std::string_view, 3> kConstants{"one", "two", "three"};
Run Code Online (Sandbox Code Playgroud)
我可以做一些扩展魔法来得到类似的东西:
foobar(kConstants);
Run Code Online (Sandbox Code Playgroud)
请注意,为了这对我有用,我必须在不修改的情况下执行此操作foobar。我知道我可以用 x 宏做类似的事情。