lundi 10 mai 2021

Compare memberwise parameter packs of different lengths

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) && ...)>> {};

Here I define a compatibility check between two parameter packs. The actual member check is more complicated than an equality check, so I can't fallback to is_same<integer_sequence<int, TVals...>, integer_sequence<int, UVals...>>. I must check each member on its own.

static_assert(!are_compatibles<type<1, 2>, type<1, 2>>::value); compiles on MSVC.

static_assert(!are_compatibles<type<1, 2>, type<1>>::value); fails to compile on MSVC because parameter packs are not the same length. Is there a way to compare memberwise parameter packs of different lengths?

Aucun commentaire:

Enregistrer un commentaire