/* * Copyright (C) 2015 Hamburg University of Applied Sciences (HAW) * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level * directory for more details. */ /** * @ingroup cpp11-compat * @{ * * @file * @brief utility functions * * @author Dominik Charousset * @author Raphael Hiesgen * * @} */ #ifndef RIOT_THREAD_UTILS_HPP #define RIOT_THREAD_UTILS_HPP #include #include namespace riot { namespace detail { /** * @brief A list of integers (wraps a long... template parameter pack). */ template struct int_list {}; /** * @brief Creates indices from `Pos` to `Max`. */ template > struct il_indices; /** * @brief End of recursion, `Pos` reached `Max`. */ template struct il_indices> { /** * @brief Result is the list containing `Is...`. */ using type = int_list; }; /** * @brief Recursion step. */ template struct il_indices> { /** * @brief Append `Pos` to list and increment for the next step. */ using type = typename il_indices>::type; }; /** * @brief Function to create a list of indices from `From` to `To`. */ template typename il_indices::type get_indices() { return {}; } /** * @brief Apply arguments in a tuple to function. */ template inline auto apply_args(F& f, detail::int_list, Tuple&& tup) -> decltype(f(std::get(tup)...)) { return f(std::get(tup)...); } /** * @brief Prefix the argument tuple with additonal arguments. * In this case the tuple is empty. */ template inline auto apply_args_prefixed(F& f, detail::int_list<>, Tuple&, Ts&&... args) -> decltype(f(std::forward(args)...)) { return f(std::forward(args)...); } /** * @brief Prefix the argument tuple with additonal arguments. * In this case the tuple is contains arguments. */ template inline auto apply_args_prefixed(F& f, detail::int_list, Tuple& tup, Ts&&... args) -> decltype(f(std::forward(args)..., std::get(tup)...)) { return f(std::forward(args)..., std::get(tup)...); } /** * @brief Suffix the tuple with additonal arguments. */ template inline auto apply_args_suffxied(F& f, detail::int_list, Tuple& tup, Ts&&... args) -> decltype(f(std::get(tup)..., std::forward(args)...)) { return f(std::get(tup)..., std::forward(args)...); } } // namespace detail } // namespace riot #endif // RIOT_THREAD_UTILS_HPP