0

他のコンパイラで受け入れられるこのコードは、次のエラーで失敗しg++-4.1ます。

template<typename T> struct foo;

template<template<typename> class ClassTemplate, typename Arg>
  struct foo<ClassTemplate<Arg> >
{
  typedef Arg type;
};

template<template<typename, typename> class ClassTemplate, typename Arg1, typename Arg2>
  struct foo<ClassTemplate<Arg1,Arg2> >
{
  typedef Arg1 type;
};

template<typename T1, typename T2 = int> class bar {};

int main()
{
  typedef bar<int> test_me;
  typedef foo<test_me>::type type;
  return 0;
}

コンパイラ出力:

$ g++ test.cpp 
test.cpp: In function ‘int main()’:
test.cpp:20: error: ambiguous class template instantiation for ‘struct foo<bar<int, int> >’
test.cpp:5: error: candidates are: struct foo<ClassTemplate<Arg> >
test.cpp:11: error:                 struct foo<ClassTemplate<Arg1, Arg2> >
test.cpp:20: error: ‘type’ in class ‘foo<bar<int, int> >’ does not name a type

barのデフォルト テンプレート パラメータの存在が原因のようです。

fooこのコンパイラに実装できる他の方法はありますか?

4

0 に答える 0