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

前端 未结 2 534
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  旧时难觅i
    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 
    R make_func(R(*)(ARGS...));
    

    Then just directly use the return type:

    template 
    decltype(make_func(&VectorVolume>)) 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

提交回复
热议问题