mercredi 7 septembre 2022

How to forward a trimmed version of parameter pack?

Suppose my constructors (A5) takes a parameter pack. I want it to forward the first N elements to one member constructor (B) and the rest to another (C). Both member constructors taking parameter packs as well. Is there a way to do it?

template<int N> struct B;

template<int N> struct C;

template<int N, typename ...Args>
auto get_first(Args&&... args);

template<int N, typename ...Args>
auto get_last(Args&&... args);

template<int N>
struct A5
{
  B<N> b;
  C<5-N> c;

  template<typename ...Args>
  A5(Args&&... args)
    : b(get_first<N>(args)...) // how this might look like?
    , c(get_last<5-N>(args)...)
  {}
};

Problem in my case is, that the number of arguments needed for the constructors of B and C depends on the non-type parameter.

It would be nice to know how to implement something like get_first and get_last. If it's not possible, I'd be interested in why.

Also, suggestions for other possible solutions or workarounds would be appreciated.

This was probably asked before, but I cannot find any related questions.

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire