In a class that mixes CRTP, variadic templates, metaprogrammation and operator overloading, I would like to compare two variadic unsigned int templates parameters in order to do some static assertion. I think that helper structs would be a good way to do this but I don’t know exactly how to do it. I think about something of the form :
template<unsigned int... TDIM, unsigned int... TDIM0> struct HelperCheckDimensions
{
static const bool ok = /* SOMETHING */
};
where TDIM and TDIM0 are the two parameters I want to compare. It will allow me to type :
static_assert(HelperCheckDimensions<TDIM..., TDIM0...>::ok, "ERROR : Dimensions are different !");
I want the result to be true only if sizeof...(TDIM)==sizeof...(TDIM0) AND TDIM[0] == TDIM0[0], TDIM[1] == TDIM0[1], ..., TDIM[n] == TDIM0[n].
How to do that ?
Thank you very much.
I would say a class variadic-template of this form doesn’t make sense:
It doesn’t make sense, because if I write this:
then what
TDIMandTDIM0should be? How the compiler should do partition of the arguments?Is this correct:
Or is this correct:
Or this:
Hope that helps why it doesn’t make sense.
From your comment:
Well the template definition of this form is not allowed by the Standard:
I don’t know the reasons why the Standard doesn’t allow it even though it makes sense to me, at least in this case (maybe it adds unworthy complexity to the language). According to the Standard, the template-parameter-pack must be the last parameter of a template definition.
If you compile the above code in GCC, it gives this error:
Hope that helps.