Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <tuple>
- #include <map>
- #include <functional>
- template <class F, size_t... Is>
- constexpr auto index_apply_impl(F&& f, std::index_sequence<Is...>) {
- return f(std::integral_constant<size_t, Is> {}...);
- }
- template <size_t N, class F>
- constexpr auto index_apply(F&& f) {
- return index_apply_impl(std::forward<F>(f), std::make_index_sequence<N>{});
- }
- template <typename ... Args>
- constexpr void apply(const std::function<void(Args...)>& f, const std::tuple<Args...>& t)
- {
- index_apply<std::tuple_size<std::tuple<Args...> >{}>(
- [&](auto... Is) {
- f(std::get<Is>(t)...);
- });
- }
- void printme(int param)
- {
- std::cout << param << std::endl;
- }
- template <typename ... Args>
- void printme(int param, Args... data)
- {
- std::cout << param << std::endl;
- printme(std::forward<Args>(data)...);
- }
- int main()
- {
- using namespace std::placeholders;
- printme(1, 2, 3, 4, 5);
- //auto printme_binded = std::bind(printme, _1, _2, _3, _4, _5);
- //printme_binded(1, 2, 3, 4, 5);
- apply(printme, std::make_tuple(1, 2, 3, 4, 5));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement