Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 模板参数中的模板参数太多_C++_Templates - Fatal编程技术网

C++ 模板参数中的模板参数太多

C++ 模板参数中的模板参数太多,c++,templates,C++,Templates,我试图实现一些模板代码,如下所示,它在GCC7上运行良好,但在Clang6上编译失败。有什么想法吗 #include <iostream> template <template <typename, typename> class Op> class Function { }; template <typename A, typename B, bool is_f = std::is_floating_point<A>::value ||

我试图实现一些模板代码,如下所示,它在GCC7上运行良好,但在Clang6上编译失败。有什么想法吗

#include <iostream>

template <template <typename, typename> class Op>
class Function
{
};

template <typename A, typename B, bool is_f = std::is_floating_point<A>::value || std::is_floating_point<B>::value > struct Operator;

template <typename A, typename B>
struct Operator<A, B, false>
{};


template <typename A, typename B>
struct Operator<A, B, true>
{};

using FunctionOperator = Function<Operator>;


int main(int argc, char * argv[]){
    std::cout << "hi!\n";
    return 0;
}
#包括
模板
类函数
{
};
模板结构算子;
模板
结构运算符
{};
模板
结构运算符
{};
使用FunctionOperator=函数;
int main(int argc,char*argv[]){

std::coutClang显然有一个问题,即基本的
操作符
结构模板有3个而不是2个参数,因此拒绝在
函数
模板中接受它。 根据对这个问题的回答,Clang是错误的,GCC在这个问题上符合标准。无论如何,这里有一个解决这个问题的快速方法:

template <template <typename, typename> class Op>
class Function
{
};

template <typename A, typename B, bool is_f = std::is_floating_point<A>::value || std::is_floating_point<B>::value > struct Operator;

template <typename A, typename B>
struct Operator<A, B, false>
{};


template <typename A, typename B>
struct Operator<A, B, true>
{};

template<class A, class B>
using Op = Operator<A, B>;

using FunctionOperator = Function<Op>;


int main(int argc, char * argv[]){
    FunctionOperator o;
    std::cout << "hi!\n";
    return 0;
}
模板
类函数
{
};
模板结构算子;
模板
结构运算符
{};
模板
结构运算符
{};
模板
使用Op=运算符;
使用FunctionOperator=函数;
int main(int argc,char*argv[]){
函数运算符o;
标准::cout
template <template <typename, typename> class Op>
class Function
{
};

template <typename A, typename B, bool is_f = std::is_floating_point<A>::value || std::is_floating_point<B>::value > struct Operator;

template <typename A, typename B>
struct Operator<A, B, false>
{};


template <typename A, typename B>
struct Operator<A, B, true>
{};

template<class A, class B>
using Op = Operator<A, B>;

using FunctionOperator = Function<Op>;


int main(int argc, char * argv[]){
    FunctionOperator o;
    std::cout << "hi!\n";
    return 0;
}