C++ 模板参数中的模板参数太多
我试图实现一些模板代码,如下所示,它在GCC7上运行良好,但在Clang6上编译失败。有什么想法吗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 ||
#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;
}