`(... && TraitsOf())` 在 C++ 中是什么意思
What is the `(... && TraitsOf())` mean in C++
我正在尝试理解这个 C++ 语法:
constexpr auto all_deps_type_set =
(... | TraitsOf(types::type_c<HaversackTs>).all_deps);
(...|
部分是什么意思?
示例:https://github.com/google/hotels-template-library/blob/master/haversack/haversack_test_util.h
HaversackTs
是一个 parameter pack,这意味着它包含一些可变数量的模板类型。 ...
扩展模板参数包,使用给定的二元运算符(在我们的例子中,按位 |
)折叠它。因此,如果在此模板的特定实例中,HaversackTs
恰好是 int, std::string
,那么该行将意味着
constexpr auto all_deps_type_set =
(TraitsOf(types::type_c<int>).all_deps | TraitsOf(types::type_c<std::string>).all_deps);
right-hand边是针对参数包中的每种类型分别展开,结果使用|
合并。通过简单地在每个参数之间应用 |
,这自然地推广到两个以上的参数。
我正在尝试理解这个 C++ 语法:
constexpr auto all_deps_type_set =
(... | TraitsOf(types::type_c<HaversackTs>).all_deps);
(...|
部分是什么意思?
示例:https://github.com/google/hotels-template-library/blob/master/haversack/haversack_test_util.h
HaversackTs
是一个 parameter pack,这意味着它包含一些可变数量的模板类型。 ...
扩展模板参数包,使用给定的二元运算符(在我们的例子中,按位 |
)折叠它。因此,如果在此模板的特定实例中,HaversackTs
恰好是 int, std::string
,那么该行将意味着
constexpr auto all_deps_type_set =
(TraitsOf(types::type_c<int>).all_deps | TraitsOf(types::type_c<std::string>).all_deps);
right-hand边是针对参数包中的每种类型分别展开,结果使用|
合并。通过简单地在每个参数之间应用 |
,这自然地推广到两个以上的参数。