Inferring return type of templated member functions in CRTP

后端 未结 1 1416
既然无缘
既然无缘 2020-12-31 10:20

Is it possible to infer the return type of a templated member function in a CRTP base class?

While inferring argument types works well, it fails wit

1条回答
  •  一个人的身影
    2020-12-31 11:07

    An extra indirection is your friend:

    template 
    struct f_impl_result
    {
        typedef decltype(static_cast(0)->f_impl(std::declval())) type;
    };
    
    template 
    struct base
    {
        template 
        auto f(T x) -> typename f_impl_result::type
        {
            return static_cast(*this).f_impl(x);
        }
    };
    

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