3

I found that some CppCon speakers used and instead of && to define concepts and used && in "normal" boolean expressions, but I can't figure out the benefits of doing so.

The only material about naming convensions of concepts that I can found is P1851: Guidelines For snake_case Concept Naming, but it says nothing about this.

Can anyone tell me why?

Example:

template <typename T>
concept boolean_testable
    = std::convertible_to<T, bool>
      and requires(T&& t) {
            { !std::forward<T>(t) } -> std::convertible_to<bool>;
          };

Instead of:

template <typename T>
concept boolean_testable
    = std::convertible_to<T, bool>
      && requires(T&& t) {
           { !std::forward<T>(t) } -> std::convertible_to<bool>;
         };

Although the complete substitutability between && and and caught my eye, I still can't figure out why some programmers deliberately choose to use and only when defining concepts. I noticed they still used && in other context (boolean expressions, T&&...). I can't figure out the benefits they got from such style.

I'm not asking for the difference between and and && but the motivation of using and instead of && only when in concept definition. There's no duplicate question as far as I know.

Dharman
  • 30,962
  • 25
  • 85
  • 135
FeignClaims
  • 193
  • 8

2 Answers2

9

There is absolutely no difference between && and and. As tokens they behave identically in all aspects except that the preprocessor # stringify operator respects their different spelling.

For example you can even replace T&& with T and and the code will still have identical meaning.

This is purely a style choice.

See [lex.digraph].

user17732522
  • 53,019
  • 2
  • 56
  • 105
-1

In summary, the benefits might be:

  • and is an English word. Using and (along with or and not) makes the concept definition read like a beutiful verse.
  • In concept definition it's pretty common to have a lot of rvalue-reference, so using and instead of && helps readablity.
FeignClaims
  • 193
  • 8