Given the following class-templates, how can the group
function be defined such that it provides the identifiers in Id
whose corresponding If
is represented in the parameter-pack Ifs
?
template<auto... Id>
struct Group {};
template<auto Id, template<class> class If>
struct Pair {};
template<class... U>
struct Pairs;
template<auto... Id, template<class> class... If>
struct Pairs<Pair<Id, If>...> final {
template<template<class> class... Ifs>
static consteval auto group() -> Group<...>;
};
The intended use is something like this:
enum Id {
Id1,
Id2,
Id3
};
template<class T> struct Interface1 {};
template<class T> struct Interface2 {};
using T = Pairs<Pair<Id1, Interface2>, Pair<Id2, Interface1>, Pair<Id3, Interface2>>;
auto pairs = T{};
auto group0 = T::group<>(); // Group<>
auto group1 = T::group<Interface1>(); // Group<Id2>
auto group2 = T::group<Interface2>(); // Group<Id1, Id3>
auto group3 = T::group<Interface1, Interface2>(); // Group<Id1, Id2, Id3>