1
template <int... ValuesOrSentinals>
struct type {};

template <typename T, typename U>
struct are_compatibles;
template <int... TVals, int... UVals>
struct are_compatibles<type<TVals...>, type<UVals...>>
    : public conjunction<bool_constant<sizeof...(TVals) == sizeof...(UVals)>,
                         bool_constant<((TVals == UVals) && ...)>> {};

ここでは、2 つのパラメーター パック間の互換性チェックを定義します。実際のメンバー チェックは、等価チェックよりも複雑なので、フォールバックできませんis_same<integer_sequence<int, TVals...>, integer_sequence<int, UVals...>>。各メンバーを個別にチェックする必要があります。

  • are_compatibles<type<1, 2>, type<1, 2>>::value == true;コンパイルします。
  • are_compatibles<type<1, 2>, type<2, 1>>::value == falseコンパイルします。
  • are_compatibles<type<1, 2>, type<1>>::value == falseパラメーター パックの長さが同じでないため、コンパイルに失敗します。

長さの異なるメンバーごとのパラメーター パックを比較する方法はありますか?

4

3 に答える 3