c – 朋友功能默认模板:英特尔ICPC警告

我有以下测试代码:

// friendfunction.h                                                                                   
#include <iostream>

template<typename T,unsigned int... TDIM> class MyClass
{
  template<typename T1,typename T0,unsigned int... TDIM0,class> friend inline const MyClass<T0,TDIM0...> myFunction(const T1& x,const MyClass<T0,TDIM0...>& y);
};

template<typename T0,typename T,unsigned int... TDIM,class = typename std::enable_if<std::is_fundamental<T0>::value>::type> inline const MyClass<T,TDIM...> myFunction(const T0& x,const MyClass<T,TDIM...>& y)
{
  std::cout<<"It works !"<<std::endl;
  return MyClass<T,TDIM...>(y);
}

// friendfunction.cpp
#include "friendfunction.h"
int main(int argc,char *argv[])
{
  MyClass<double,3,3> myClass;
  myFunction(10,myClass);
  return 0;
}

用g(4.6.1)我编译:

g++ -Wall -Wextra -Winline -Wno-unused -O3 -std=c++0x friendfunction.cpp -o friendfunction

并使用intel ICPC(12.1.0 20111011):

icpc -Wall -Wno-unused -O3 -std=c++0x friendfunction.cpp -o friendfunction

使用g我没有错误也没有警告,但是对于Intel C我有以下警告:

friendfunction.h(5): warning #2922: template parameter "<unnamed>" cannot be used because it follows a parameter pack and cannot be deduced from the parameters of function template "myFunction"
template<typename T1,TDIM0...>& y);

有人有解决方案来避免这种情况吗?

此外,你是否发现友元函数的语法完全正确/安全,或者你认为它可以为一些奇怪的情况产生错误?

解决方法

只是猜测,但似乎icpc希望参数包是最后一个模板参数.如果包中的variadic参数无法与包后面的另一个参数区分开来,那么这是合理的,恕我直言.但在你的情况下,可变参数是整数,下一个是类类型,所以看起来icpc出错了……

相关文章

一.C语言中的static关键字 在C语言中,static可以用来修饰局...
浅谈C/C++中的指针和数组(二) 前面已经讨论了指针...
浅谈C/C++中的指针和数组(一)指针是C/C++...
从两个例子分析C语言的声明 在读《C专家编程》一书的第三章时...
C语言文件操作解析(一)在讨论C语言文件操作之前,先了解一下...
C语言文件操作解析(三) 在前面已经讨论了文件打开操作,下面...