Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SFINAE: Check whether the concatenation of two variadic packs is the same as one pack

Is there a way to check whether the concatenation of two variadic argument packs is the same as a third variadic argument pack.

template<typename... Args>
struct ClassOne
{
}

template<typename... Args>
struct ClassTwo
{
}

template<typename... Args>
struct ClassThree
{
}

template<typename... PackA, typename... PackB, typename... PackC>
void foo(ClassOne<PackA...>, ClassTwo<PackB...>, ClassThree<PackC...>)
{
}

I would like foo to only be enabled if PackA... = PackB..., PackC...

like image 699
Andreas Loanjoe Avatar asked Jan 29 '23 16:01

Andreas Loanjoe


1 Answers

Rather straightforward...

template <typename ...>
struct pack{};

template<typename... PackA, typename... PackB, typename... PackC,
  typename = typename std::enable_if
     <std::is_same<pack<PackA...>, 
                   pack<PackB..., PackC...>>::value
     >::type>
void foo(ClassOne<PackA...>, ClassTwo<PackB...>, ClassThree<PackC...>)
{
}
like image 181
n. 1.8e9-where's-my-share m. Avatar answered Feb 13 '23 15:02

n. 1.8e9-where's-my-share m.