g++ (バージョン 4.8.1_1、Macports) および clang++ (バージョン 3.3、Macports) 用の TMP を多用するコードを作成しています。g++ は次のコード リストをUNBRIDLED FURYで拒否しますが、clang++ はそれを優雅に見事にコンパイルします。
- 正しいのはどのコンパイラですか? (私はそれが g++ であると強く疑っていますが、バグ レポートを提出する前に他の人から安心を得たいと思っています。)
- 提案する簡単またはエレガントな回避策はありますか? (テンプレート エイリアスを使用する必要があるため、g++ にコードを受け入れさせる構造体に切り替えることはオプションではありません。)
これがあなたのために作られたコードリストです。
template <class... Ts>
struct sequence;
template <int T>
struct integer;
// This definition of `extents` causes g++ to issue a compile-time error.
template <int... Ts>
using extents = sequence<integer<Ts>...>;
// However, this definition works without any problems.
// template <int... Ts>
// struct extents;
template <int A, int B, class Current>
struct foo;
template <int A, int B, int... Ts>
struct foo<A, B, extents<Ts...>>
{
using type = int;
};
template <int B, int... Ts>
struct foo<B, B, extents<Ts...>>
{
using type = int;
};
int main()
{
using t = foo<1, 1, extents<>>::type;
return 0;
}
g++ の出力は次のとおりです。
er.cpp: In function 'int main()':
er.cpp:39:41: error: ambiguous class template instantiation for 'struct foo<1, 1, sequence<> >'
using t = typename foo<1, 1, extents<>>::type;
^
er.cpp:26:8: error: candidates are: struct foo<A, B, sequence<integer<Ts>...> >
struct foo<A, B, extents<Ts...>>
^
er.cpp:32:8: error: struct foo<B, B, sequence<integer<Ts>...> >
struct foo<B, B, extents<Ts...>>
^
er.cpp:39:43: error: 'type' in 'struct foo<1, 1, sequence<> >' does not name a type
using t = typename foo<1, 1, extents<>>::type;
^
これがclang ++の出力です:
ご協力いただきありがとうございます!