'Is constrained auto cast valid?
Since C++20, the constrained auto
is introduced by:
Concept auto identifier = init
Which means, for instance:
std::integral auto x = 10;
is valid.
Also, for new-expressions, concept is allowed to be paired with auto
:
new Concept auto { expr };
// or:
new Concept auto ( expr );
auto{expr}
or auto(expr)
was introduced in C++23 as roughly equivalent to:
auto __temp { expr };
return __temp;
Does it mean that Concept auto { expr }
or Concept auto ( expr )
is also valid?
The simple use case would be usable in trying to create a decay copy while checking its operations checked by constraint.
Solution 1:[1]
[dcl.spec.auto.general]/5 allows only auto
to be the simple-type-specifier of a functional type conversion, even though a constrained placeholder-type-specifier can be a simple-type-specifier grammatically.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Davis Herring |