Is it possible to use a modified version of a class template parameter pack in a members template?

I am trying to write a class template with a variadic template parameter pack which is separated into two groups of arguments. Those shall be used in member templates.

template <class... Args>
class Foo {
public:
    Foo(const Args&... args) :gr1{/*...*/}, gr2{/*...*/} {} 
private:
    template_one<Group1...> gr1;
    template_two<Group2...> gr2;
};

What I have come up with is:

A type sorter which returns a pair of tuples containing sorted types.

template <typename... Args>
struct type_sorter;

template <>
struct type_sorter<> {
    constexpr static auto sort() {return std::pair<std::tuple<>, std::tuple<>>{}; }
};

template <typename Arg, typename... Args>
struct type_sorter<Arg, Args...> {
    constexpr static auto sort() {
        auto ret = type_sorter<Args...>::sort();

        if constexpr (std::is_function_v<Arg>)
            return std::make_pair(std::tuple_cat(ret.first, std::tuple<Arg*>{}), ret.second);
        else
            return std::make_pair(ret.first, std::tuple_cat(ret.second, std::tuple<Arg>{}));
    }
};

A param sorter which returns a pair of tuples containing both sorted types and parameters.

template <class Arg>
constexpr auto param_sort(Arg&& arg) {
    if constexpr (std::is_function_v<typename std::remove_reference_t<Arg>>)
        return std::make_pair(std::tuple<Arg>(arg), std::tuple<>());
    else
        return std::make_pair(std::tuple<>(), std::tuple<Arg>(arg));
}

template <class Arg, class... Args>
constexpr auto param_sort(Arg&& arg, Args&&... args) {
    auto ret = param_sort(std::forward<Args>(args)...);

    if constexpr (std::is_function_v<typename std::remove_reference_t<Arg>>)
        return std::make_pair(std::tuple_cat(ret.first, std::tuple<Arg>(arg)), ret.second);
    else
        return std::make_pair(ret.first, std::tuple_cat(ret.second, std::tuple<Arg>(arg)));
}

Currently std::is_function is the sorting criterion.
The former can be used to sort types without having to provide arguments while the later sorts both the template parameters and the arguments. This is useful when having only access to the template parameter pack. (At class scope.)

Now they both return tuples:

I would like to be able to extract the parameter packs (Group1, Group2) from the tuples generated by type sorter and use it in the declaration of template_one and template_two.

What I tried is:

template_one<decltype(std::get<
  std::make_index_sequence<std::tuple_size_v<
    decltype(type_sorter<Inputs...>::sort().second)
  >>>(type_sorter<Inputs...>::sort().second)...)
> gr1 {};

Doesn’t compile.

Is something like that even possible?

10

If i correctly understand the question you are looking for a way to get foo<A...> given some std::tuple<A...>.

You can write a trait for that :

template <template <typename ...> class T,typename A> 
struct tuple_expander;

template <template <typename ...> class T,typename ...B>
struct tuple_expander<T,std::tuple<B...>> {
    using type = T<B...>;
};

Live Demo

With Delegating constructor, you might do:

template <class... Args>
class Foo {
    using Tuple1 = decltype(type_sorter<Args...>::sort())::first_type;
    using Tuple2 = decltype(type_sorter<Args...>::sort())::second_type;

    Foo(const std::pair<Tuple1, Tuple2>& p) :gr1{p.first}, gr2{p.second} {}

public:
    Foo(const Args&... args) : Foo(param_sort(args...)) {}

private:
    Tuple1 gr1;
    Tuple2 gr2;
};

Demo

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật