Inferring return type of templated member functions in CRTP

后端 未结 1 1411
既然无缘
既然无缘 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 <typename D, typename T>
    struct f_impl_result
    {
        typedef decltype(static_cast<D*>(0)->f_impl(std::declval<T>())) type;
    };
    
    template <typename Derived>
    struct base
    {
        template <typename T>
        auto f(T x) -> typename f_impl_result<Derived, T>::type
        {
            return static_cast<Derived&>(*this).f_impl(x);
        }
    };
    
    0 讨论(0)
提交回复
热议问题