私は次のテストコードを持っています:
// 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, typename T0, unsigned int... TDIM0, class> friend inline const MyClass<T0, TDIM0...> myFunction(const T1& x, const MyClass<T0, TDIM0...>& y);
誰かがそれを避けるための解決策を持っていますか?
さらに、フレンド関数の構文は完全に問題ない/安全だと思いますか?それとも、いくつかの奇妙なケースでエラーが発生する可能性があると思いますか?