Home > Mobile >  Why surround template parameters with parentheses when `require clause` is surrounded by parentheses
Why surround template parameters with parentheses when `require clause` is surrounded by parentheses

Time:08-29

Why surround template parameters with parentheses when require clause is surrounded by parentheses ?

template(typename This, typename Receiver)
    (requires same_as<remove_cvref_t<This>, type> AND
      receiver<Receiver> AND
      constructible_from<std::tuple<Values...>, member_t<This, std::tuple<Values...>>>)
friend auto tag_invoke(tag_t<connect>, This&& that, Receiver&& r)
    noexcept(std::is_nothrow_constructible_v<std::tuple<Values...>, member_t<This, std::tuple<Values...>>>)
    -> operation<Receiver, Values...> {
  return {static_cast<This&&>(that).values_, static_cast<Receiver&&>(r)};
}

from libunifex

CodePudding user response:

Why surround template parameters with parentheses when require clause is surrounded by parentheses ?

The template(typename This, typename Receiver) part you see is actually a macro, which is defined as:

#if UNIFEX_CXX_CONCEPTS
  #define template(...) \
    template <__VA_ARGS__> UNIFEX_PP_EXPAND \
    /**/
#else
  #define template(...) \
    template <__VA_ARGS__ UNIFEX_TEMPLATE_SFINAE_AUX_ \
    /**/
#endif

which is used to simplify template definitions with the suffix UNIFEX_PP_EXPAND.

  • Related