Templated usings Can't Select Template Functions to use as Parameters in Visual Studio

前端 未结 2 530
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-27 18:09

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 Vector3f32 {         


        
相关标签:
2条回答
  • 2021-01-27 18:18

    As workaround, you might simply do:

    template <typename T>
    auto func(const T& dir)
    -> decltype(VectorVolume(dir.x, dir.y, dir.z))
    {
        return VectorVolume(dir.x, dir.y, dir.z);
    }
    
    0 讨论(0)
  • 2021-01-27 18:18

    You're really only interested in the function::result_type so there's really no need to go through the bugged path of returning a function. Just return the result type and do a decltype on that (you don't even need to define the function since you're not actually calling it.) Something like this:

    template <typename R, typename... ARGS>
    R make_func(R(*)(ARGS...));
    

    Then just directly use the return type:

    template <typename T>
    decltype(make_func(&VectorVolume<param_vector<T>>)) func(const T& dir) {
        return VectorVolume(dir.x, dir.y, dir.z);
    }
    

    This is works great on Visual Studio 15.6.7 and as an added bonus is fully c++14 compatible: https://ideone.com/gcYo8x

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