Why calling the function isn’t ambiguous in SFINAE?

I am using SFINAE to check whether some class has 'print()' function or not. The code works but why calling has_print() is not ambiguous?

class cls {
public:
    void print() {
        std::cout << "some text" << std::endl;
    }
};

template<typename T>
auto has_print(T tt) -> decltype(T().print(), std::true_type()) {
    tt.print();
    return std::true_type();
}

std::false_type has_print(...) {
    std::cout << "Doesn't contain print()" << std::endl;
    return std::false_type();
}

int main() {
    cls c;
    has_print(c);

    return 0;
}

It could match both of them.



Read more here: https://stackoverflow.com/questions/67015877/why-calling-the-function-isnt-ambiguous-in-sfinae

Content Attribution

This content was originally published by Kanony at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: