Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What are the benefits of using `and` instead of `&&` when defining concepts?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>;
         };

>Solution :

There is absolutely no difference between && and and. As tokens they behave identically in all respects expect 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].

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading