Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <tuple>
- template <typename... _tFake>
- constexpr void unsequenced(_tFake... fake)
- {
- }
- template<size_t... _vSeq>
- struct unseq_dispatcher
- {
- template<typename _fCallable, typename... _tParams>
- static inline void
- call(_fCallable f, _tParams&&... args)
- {
- unsequenced((f(std::get<_vSeq>(std::forward_as_tuple(args...))), 0)...);
- }
- };
- template <size_t m, size_t idx = 0>
- struct make_natrual_sequence
- {
- template <size_t... ipara>
- using type = typename make_natrual_sequence<m, idx+1>::template type<ipara..., idx>;
- };
- template<size_t m>
- struct make_natrual_sequence<m, m>
- {
- template <size_t... ipara>
- using type = unseq_dispatcher<ipara...>;
- };
- template<typename _fCallable, typename... _tParams>
- inline void
- unseq_apply(_fCallable f, _tParams&&... args)
- {
- make_natrual_sequence<sizeof...(_tParams)>::template type<>::call(f, std::forward<_tParams>(args)...);
- }
- int main()
- {
- using namespace std;
- auto f = [](int a){printf("%d", a);};
- unseq_apply(f, 1, 2, 3, 4, 5);
- }
Advertisement
Add Comment
Please, Sign In to add comment