Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename F, typename Tuple, size_t... I>
- decltype(auto) apply_impl(F&& f, Tuple&& t, std::index_sequence<I...>) {
- return std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...);
- }
- template <typename F, typename Tuple>
- decltype(auto) apply(F&& f, Tuple&& t) {
- using Indices = std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>;
- return apply_impl(std::forward<F>(f), std::forward<Tuple>(t), Indices{});
- }
- template <typename Function, typename... Args>
- void* helperf(void* params) {
- typedef std::tuple<Function, std::tuple<Args...>> hell;
- std::unique_ptr<hell> ptr(static_cast<hell*>(params));
- apply(std::move(std::get<0>(*ptr)), std::move(std::get<1>(*ptr)));
- return nullptr;
- }
- template <typename Function, typename... Args>
- thread::thread(Function&& f, Args&&... args) {
- typedef std::tuple<Function, std::tuple<Args...>> hell;
- auto topass = std::unique_ptr<hell>(
- new hell(std::move(f), std::forward_as_tuple<Args...>(std::forward<Args...>(args...))));
- pthread_create(&_thread, NULL, &helperf<Function, Args...>, topass.release());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement