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

Meaning of the { } -> "operator" in C++

My activities in C++ have been dormant for a while, so maybe my question isn’t appropriate.

I have seen in the definition of concepts a ‘strange’ syntax like e.g.: {x + 1} -> std::same_as<int>;

Is there a name for the { } -> "operator", resp. when has it been introduced into the standard and for what purpose?
I understand its meaning in the context of defining requirements but would appreciate some further information.

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

>Solution :

Meaning of the { } -> "operator" in C++

It is not a single operator but what is called a compound requirement and has the form:

{ expression } noexcept(optional) return-type-requirement (optional) ;    

return-type-requirement   -   -> type-constraint

and asserts properties of the named expression. Substitution and semantic constraint checking proceeds in the following order:

  1. Template arguments (if any) are substituted into expression;
  2. If noexcept is used, expression must not be potentially throwing;
  3. If return-type-requirement is present, then:
    a) Template arguments are substituted into the return-type-requirement;
    b) decltype((expression)) must satisfy the constraint imposed by the type-constraint. Otherwise, the enclosing requires-expression is false.

(emphasis mine)

This means that decltype((x+1)) must satisfy the constraint imposed by std::same_as<int> which essentially means that the type deduced by/for the expression x+1 should evaluate to an int.

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