Программы на C++. Форум разработчиков
Anonymous
Требуется выражение ищет неправильную функцию кандидата при использовании пространств имен
Сообщение
Anonymous » 06 май 2025, 17:47
Это продолжение этого вопроса: `Требуется выражения и пространства имен функций < /p>
Попытка спроектировать ответ, который я наткнулся на это странное поведение: < /p>
Код: Выделить всё
#include // for std::same_as
#include
#include
// dummy default declaration
template
void foo(T) = delete;
template
constexpr bool b_req = requires(T obj) {
{ foo(obj) } -> std::same_as;
};
// client types
struct S1 {};
struct S2 {};
// non-template candidate for S1
void foo(S1) { std::puts("foo(S1)"); }
int main() {
foo(S1{}); // calls the expected version
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79608912/requires-expression-looking-for-wrong-candidate-function-when-using-namespaces[/url]
1746542869
Anonymous
Это продолжение этого вопроса: `Требуется выражения и пространства имен функций < /p> Попытка спроектировать ответ, который я наткнулся на это странное поведение: < /p> [code]#include // for std::same_as #include #include // dummy default declaration template void foo(T) = delete; template constexpr bool b_req = requires(T obj) { { foo(obj) } -> std::same_as; }; // client types struct S1 {}; struct S2 {}; // non-template candidate for S1 void foo(S1) { std::puts("foo(S1)"); } int main() { foo(S1{}); // calls the expected version std::cout Подробнее здесь: [url]https://stackoverflow.com/questions/79608912/requires-expression-looking-for-wrong-candidate-function-when-using-namespaces[/url]