Попытка спроектировать ответ, который я наткнулся на это странное поведение: < /p>
Код: Выделить всё
#include // for std::same_as
#include
#include
// dummy default declaration
template
void foo(T) = delete;
template
void bar(T t) {
foo(t);
};
// client types
struct S1 {};
struct S2 {};
// "specializations" for S1
void foo(S1) { std::puts("foo(S1)"); }
int main() {
foo(S1{}); // calls the expected version
bar(S1{}); // try to call the deleted version the wrong version
}
< /code>
oulpul: < /p>
foo(S1)
foo(S1)
Код: Выделить всё
// dummy default declaration
namespace N {
template
void foo(T) = delete;
}
template
void bar(T t) {
N::foo(t);
};
// client types
struct S1 {};
struct S2 {};
// "specializations" for S1
namespace N {
void foo(S1) { std::puts("foo(S1)"); }
} // namespace N
int main() {
N::foo(S1{}); // calls the expected version
bar(S1{}); // try to call the deleted version the wrong version
}
Код: Выделить всё
// a kind of trait, false by default
template struct Trait : public std::false_type
{};
template
constexpr bool b_struct = Trait::value;
// client types
struct S1 {};
struct S2 {};
// specializations for S1
template struct Trait : public std::true_type
{};
int main() {
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79608912/function-selection-finding-unexpected-candidate-when-using-namespaces[/url]
Мобильная версия