Почему концептуальное ограничение C++20 не работает должным образом?C++

Программы на C++. Форум разработчиков
Гость
Почему концептуальное ограничение C++20 не работает должным образом?

Сообщение Гость »

Код: Выделить всё

#include 
#include 
#include 

template
requires requires(T const& t) {
!std::is_enum_v;
{ std::to_string(t) } -> std::same_as;
}
void Foo(T const&) {
}

template
requires std::is_enum_v
void Foo(T const&) {
}

enum Color {
Red,
Green,
Blue,
};

int main() {
Foo(Red); // error: Call to 'Foo' is ambiguous
}
Obviously, the two overloaded Foo are mutually exclusive; that is to say, if std::is_enum_v is true, the former should not be selected. But clang-18 -std=c++20 gives an error.
Why does C++20's concept constraint not work as expected?


Источник: https://stackoverflow.com/questions/781 ... s-expected

Вернуться в «C++»