Both of the following programs are accepted by clang but rejected by gcc and msvc. Demo
#include <iostream>
#include <type_traits>
#include <functional>
template <typename T>
class myclass {
public:
void func(const T&) requires true //#1
{
std::cout << "true version";
}
void func(const T&) requires false //#2
{
std::cout << "false version";
}
};
int main(){
myclass<int> obj;
auto mylambda = std::bind(&myclass<int>::func, &obj, 5); //accepted by clang rejected by gcc
mylambda();
}
As we can see the program given above is rejected by gcc with the error:
error: no matching function for call to 'bind(<unresolved overloaded function type>, myclass<int>*, int)'
24 | auto mylambda = std::bind(&myclass<int>::func, &obj, 5); //accepted by clang rejected by gcc
If we modify the program a little bit to use the template parameter the program is still rejected by gcc and msvc but accepted by clang. Demo
#include <iostream>
#include <type_traits>
#include <functional>
template<bool B>
struct S {
void f() requires B { std::cout << "true\n"; } //#1
void f() requires (!B) { std::cout << "false\n"; } //#2
};
int main() {
S<true> obj{};
auto mylambda = std::bind(&S<true>::f, &obj) ; //gcc rejects this but clang accepts this
mylambda();
}
So my question is which compiler is right here(if any)?