Loading...
Searching...
No Matches
thread_util.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Hamburg University of Applied Sciences (HAW)
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
22#ifndef RIOT_THREAD_UTILS_HPP
23#define RIOT_THREAD_UTILS_HPP
24
25#include <tuple>
26#include <utility>
27
28namespace riot {
29namespace detail {
30
34template <long... Is>
35struct int_list {};
36
40template <long Max, long Pos = 0, typename Indices = int_list<>>
42
46template <long Pos, long... Is>
47struct il_indices<Pos, Pos, int_list<Is...>> {
51 using type = int_list<Is...>;
52};
53
57template <long Max, long Pos, long... Is>
58struct il_indices<Max, Pos, int_list<Is...>> {
62 using type = typename il_indices<Max, Pos + 1, int_list<Is..., Pos>>::type;
63};
64
68template <long To, long From = 0>
70 return {};
71}
72
76template <class F, long... Is, class Tuple>
77inline auto apply_args(F& f, detail::int_list<Is...>, Tuple&& tup)
78 -> decltype(f(std::get<Is>(tup)...)) {
79 return f(std::get<Is>(tup)...);
80}
81
86template <class F, class Tuple, class... Ts>
87inline auto apply_args_prefixed(F& f, detail::int_list<>, Tuple&, Ts&&... args)
88 -> decltype(f(std::forward<Ts>(args)...)) {
89 return f(std::forward<Ts>(args)...);
90}
91
96template <class F, long... Is, class Tuple, class... Ts>
97inline auto apply_args_prefixed(F& f, detail::int_list<Is...>, Tuple& tup,
98 Ts&&... args)
99 -> decltype(f(std::forward<Ts>(args)..., std::get<Is>(tup)...)) {
100 return f(std::forward<Ts>(args)..., std::get<Is>(tup)...);
101}
102
106template <class F, long... Is, class Tuple, class... Ts>
107inline auto apply_args_suffxied(F& f, detail::int_list<Is...>, Tuple& tup,
108 Ts&&... args)
109 -> decltype(f(std::get<Is>(tup)..., std::forward<Ts>(args)...)) {
110 return f(std::get<Is>(tup)..., std::forward<Ts>(args)...);
111}
112
113} // namespace detail
114} // namespace riot
115
116#endif // RIOT_THREAD_UTILS_HPP
RIOT C++ namespace.
Definition chrono.hpp:35
typename il_indices< Max, Pos+1, int_list< Is..., Pos > >::type type
Append Pos to list and increment for the next step.
Creates indices from Pos to Max.
A list of integers (wraps a long... template parameter pack).
il_indices< To, From >::type get_indices()
Function to create a list of indices from From to To.
auto apply_args_suffxied(F &f, detail::int_list< Is... >, Tuple &tup, Ts &&... args) -> decltype(f(std::get< Is >(tup)..., std::forward< Ts >(args)...))
Suffix the tuple with additional arguments.
auto apply_args_prefixed(F &f, detail::int_list<>, Tuple &, Ts &&... args) -> decltype(f(std::forward< Ts >(args)...))
Prefix the argument tuple with additional arguments.
auto apply_args(F &f, detail::int_list< Is... >, Tuple &&tup) -> decltype(f(std::get< Is >(tup)...))
Apply arguments in a tuple to function.