Are concepts as type names in function declarations valid in C++20?

Viewed 91

The following code compiles fine on both gcc and clang (trunk with -std=c++20) but errors on msvc (19.27 /std:c++latest).

template<typename T>
concept subable = requires(T lhs, T rhs) { lhs - rhs; };

auto sub(subable auto x, subable auto y) {
    return x - y;
}


int main() {
    const auto z = sub(4, 5);
}

afaik the above code should be valid in C++20, it was in the concepts-ts. Is this a case of microsoft being behind other implementations? (C++20 isn't even out yet after all) or did this not make it into 20?

1 Answers

Concepts cannot be used to replace typenames in C++20. However, that's not what your code is doing. You are using abbreviated function template syntax, by declaring the type of the parameter to use the placeholder type auto. Abbreviated function templates can be constrained by applying a type-concept name to the auto-declared parameter (some versions of VS have not implemented abbreviated function template syntax).

But this is not the syntax that was used in Concepts-TS, where a type concept would replace the typename.

Related