Templated usings Can't be Nested in Visual Studio

前端 未结 1 1984
不知归路
不知归路 2020-12-22 10:11

This is about as simplified as I could make a toy example that still hit the bug:

struct Vector3f64 {
    double x;
    double y;
    double z;
};

struct Ve         


        
相关标签:
1条回答
  • 2020-12-22 10:39

    As mentioned by @NathanOliver the right solution is to upgrade to 15.9.5 where this is fixed. But barring that you can use result_of or invoke_result to solve that on 15.6.7 by changing call_t to:

    template<typename F, typename T>
    using call_t = result_of_t<F&&(T, T, T)>;
    

    Note that result_of is deprecated in c++17 so if you are running with "/std:c++17" or "/std:c++latest" this won't work, you'll need to use the more convenient:

    template<typename F, typename T>
    using call_t = invoke_result_t<F, T, T, T>;
    

    It's worth noting that Guillaume Racicot's answer used an elegant veradic template, which also works respectively as: template <typename F, typename... Args> using call_t = result_of_t<F&&(Args&&...)> or template<typename F, typename... Args> using call_t = invoke_result_t<F, Args...>; if you change your definition of func to:

    template <typename T>
    call_t<decltype(&VectorVolume<param_vector<T>>), param_vector<T>, param_vector<T>, param_vector<T>> func(const T& param) {
        return VectorVolume(param.x, param.y, param.z);
    }
    
    0 讨论(0)
提交回复
热议问题