Home > OS >  What is the `(... && TraitsOf())` mean in C
What is the `(... && TraitsOf())` mean in C

Time:05-21

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

CodePudding user response:

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.

  •  Tags:  
  • c
  • Related