/* * 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 { /** * A list of integers (wraps a long... template parameter pack). */ template struct int_list {}; /** * Creates indices for from `Pos` to `Max`. */ template > struct il_indices; template struct il_indices> { using type = int_list; }; template struct il_indices> { using type = typename il_indices>::type; }; template typename il_indices::type get_indices() { return {}; } /** * apply arguments to function */ template inline auto apply_args(F& f, detail::int_list, Tuple&& tup) -> decltype(f(std::get(tup)...)) { return f(std::get(tup)...); } template inline auto apply_args_prefixed(F& f, detail::int_list<>, Tuple&, Ts&&... args) -> decltype(f(std::forward(args)...)) { return f(std::forward(args)...); } 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)...); } 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