I have working 'compile-time' code where a curious pattern keeps occuring. The simplest case is:
template <int... E>
struct SomeInts { };
template <int... E>
constexpr auto InvertF( const SomeInts<E...>& ) -> SomeInts<( -E )...>;
template <typename S>
using Invert = decltype( InvertF( S() ) );
// use case:
using X = Invert<SomeInts<1, 3, 3, 7>>; // => SomeInts<-1, -3, -3, -7>
Straightforward enough. The detour via the function-template InvertF
looks somewhat clever. I've never seen this before, so it's either genius or superfluous!
Can this be simplified? How?
Just my thoughts: If the using Invert
template could extract an E...
pack somehow, it could just be = SomeInts<(-E)...>
. Smells like template template parameter, but I just can't get my head around this. The standard is probably to have a struct
instead of using
, but the matching/extraction issue remains.