Visual studio 2017 模板化使用可以';不能嵌套在Visual Studio中

Visual studio 2017 模板化使用可以';不能嵌套在Visual Studio中,visual-studio-2017,c++,templates,using,return-type,c++17,Visual Studio 2017,C++,Templates,Using,Return Type,C++17,这是一个简单的玩具示例,但仍然会遇到问题: struct Vector3f64 { double x; double y; double z; }; struct Vector3f32 { float x; float y; float z; }; // I use this to select their element type in functions: template <typename T> using param_ve

这是一个简单的玩具示例,但仍然会遇到问题:

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

struct Vector3f32 {
    float x;
    float y;
    float z;
};

// I use this to select their element type in functions:
template <typename T>
using param_vector = std::conditional_t<std::is_same_v<std::remove_const_t<std::remove_reference_t<T>>, Vector3f64>, double, float>;

// This is the function I want to pull the return type from:
template <typename T>
T VectorVolume(const T x, const T y, const T z) {
    return x * x + y * y + z * z;
}

template<typename F, typename T>
using call_t = decltype(std::declval<F>()(std::declval<T>(), std::declval<T>(), std::declval<T>()));

// This function fails to compile:
template <typename T>
call_t<decltype(&VectorVolume<param_vector<T>>), param_vector<T>> func(const T& param) {
    return VectorVolume(param.x, param.y, param.z);
}

int main() {
    const Vector3f64 foo{ 10.0, 10.0, 10.0 };

    std::cout << func(foo) << std::endl;
}
这在g++上运行良好:如果我不使用语句将一个
传递给另一个,它甚至可以正常工作:

template <typename T>
call_t<decltype(&VectorVolume<param_vector<T>>), double> func(const T& param) {
    return VectorVolume(param.x, param.y, param.z);
}
模板
调用函数(常量和参数){
返回矢量体积(参数x、参数y、参数z);
}
有什么办法可以解决这个问题吗?

正确的解决方案是升级到15.9.5版本,在那里这是固定的。但除非您可以在15.6.7中通过将
call\t
更改为:

template<typename F, typename T>
using call_t = result_of_t<F&&(T, T, T)>;
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);
}
值得注意的是,我们使用了一个优雅的veradic模板,它也分别作为:
模板使用call\u t=result\u of\u t
模板使用call\u t=invoke\u result\t如果将
func
的定义更改为:

template<typename F, typename T>
using call_t = result_of_t<F&&(T, T, T)>;
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);
}
模板
调用函数(常量和参数){
返回矢量体积(参数x、参数y、参数z);
}

能否请您将其缝合到一个可复制的代码块中,我们可以复制并粘贴?@NathanOliver您能否使用该实例进行复制:我发现这些评论很有帮助。如果这还不够的话,我想我可以返工。可能微软试图忽略这些完全不可读的代码;-)版本15.9.5编译成功,所以它可能是一个已修复的错误。@JonathanMee我可以找到解决方法,但我现在没有visual studio 15.6。有没有办法用在线编译器来测试它?编译器资源管理器没有该特定版本。