SFINAE To detect non-member function existence

后端 未结 1 1860
日久生厌
日久生厌 2020-12-11 23:34

Does anybody know of a method for specializing a template depending on whether a non-member method is defined? I know there are numerous ways for specializing if a member fu

相关标签:
1条回答
  • 2020-12-12 00:09

    If you are using C++0x, you could simply use decltype.

    template<typename Char, typename CharTraits, typename T>
            decltype(
                *(std::basic_ostream<Char, CharTraits>*)(nullptr) << *(T*)(nullptr)
            )
    

    That'll certainly cause a substitution failure if a T cannot be output. You could probably do something similar in C++03, but I'm not sure how.

    Edit: Just realised that the decltype expression doesn't actually produce a true or false value and won't compile. But you get the picture. Try this.

    0 讨论(0)
提交回复
热议问题