プリプロセッサ以外に、明示的なテンプレートのインスタンス化を条件付きで有効/無効にするにはどうすればよいですか?
検討:
template <typename T> struct TheTemplate{ /* blah */ };
template struct TheTemplate<Type1>;
template struct TheTemplate<Type2>;
template struct TheTemplate<Type3>;
template struct TheTemplate<Type4>;
コンパイル条件によっては、Type3 は Type1 と同じであり、Type4 は Type2 と同じです。これが発生すると、エラーが発生します。タイプが同じであり、Type3 と Type4 でインスタンス化されていないことを検出したい
// this does not work
template struct TheTemplate<Type1>;
template struct TheTemplate<Type2>;
template struct TheTemplate<enable_if<!is_same<Type1, Type3>::value, Type3>::type>;
template struct TheTemplate<enable_if<!is_same<Type2, Type4>::value, Type4>::type>;
私は enable_if と SFINAE を試して気をそらしました (そして、それらが失敗する理由を知っていると思います) が、プリプロセッサだけが機能しました (うーん)。タイプをタプルまたは変数に入れ、重複を取り除き、残りをインスタンス化に使用することを考えています。
テンプレート引数の型に基づいて明示的なテンプレートのインスタンス化を条件付きで有効/無効にする方法はありますか?