Jay Zhu
Jay Zhu

Reputation: 1672

What is the `(... && TraitsOf())` mean in C++

I am trying to understand this C++ syntax:

    constexpr auto all_deps_type_set =
        (... | TraitsOf(types::type_c<HaversackTs>).all_deps);

What does the (...| part mean?

Example: https://github.com/google/hotels-template-library/blob/master/haversack/haversack_test_util.h

Upvotes: 3

Views: 73

Answers (1)

Silvio Mayolo
Silvio Mayolo

Reputation: 70287

HaversackTs is a parameter pack, which means it contains some variable number of types given to the template. ... expands a template parameter pack, using a given binary operator (in our case, the bitwise |) to fold over it. So if, in a particular instantiation of this template, HaversackTs happened to be int, std::string, then that line would mean

constexpr auto all_deps_type_set =
    (TraitsOf(types::type_c<int>).all_deps | TraitsOf(types::type_c<std::string>).all_deps);

The right-hand side is expanded separately for each type in the parameter pack, and the results are combined using |. This generalizes naturally to more than two arguments by simply applying | between each one.

Upvotes: 1

Related Questions