Function Overloading Based on Arbitrary Properties of Types doesn't work

China☆狼群 提交于 2019-12-06 10:52:15

SFINAE only works when certain errors (like the ones you have) happen in declaration part. In your case they happen in definition. You have to rewrite your code so that enable_if is used in declaration, in your case of struct extract_caller.

The code I got by fixing the problem doublep mentioned:

struct extract_caller
{
    template <typename T>
    static void extract(const T& val, typename enable_if<(bool)is_extractor_native<T>::val>::type * = 0)
    {
            extractor::extract(val);
    }

    template <typename T>
    static void extract(const T& val, typename enable_if<!(bool)is_extractor_native<T>::val>::type * = 0)
    {
            extract_generic(val);
    }
};

This can be used as

extract_caller::extract(string_value);
extract_caller::extract(double_value);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!