diff options
Diffstat (limited to 'std')
-rw-r--r-- | std/tuple.hpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/std/tuple.hpp b/std/tuple.hpp index 9e05d40bc4..b24361c793 100644 --- a/std/tuple.hpp +++ b/std/tuple.hpp @@ -5,11 +5,42 @@ #endif #include <tuple> +#include <type_traits> using std::tuple; using std::make_tuple; using std::get; + +template <size_t I = 0, typename FnT, typename... Tp> +typename std::enable_if<I == sizeof...(Tp), void>::type +for_each_tuple(std::tuple<Tp...> &, FnT &&) +{ +} + +template <size_t I = 0, typename FnT, typename... Tp> +typename std::enable_if<I != sizeof...(Tp), void>::type +for_each_tuple(std::tuple<Tp...> & t, FnT && fn) +{ + fn(I, std::get<I>(t)); + for_each_tuple<I + 1, FnT, Tp...>(t, std::forward<FnT>(fn)); +} + +template <size_t I = 0, typename FnT, typename... Tp> +typename std::enable_if<I == sizeof...(Tp), void>::type +for_each_tuple_const(std::tuple<Tp...> const &, FnT &&) +{ +} + +template <size_t I = 0, typename FnT, typename... Tp> +typename std::enable_if<I != sizeof...(Tp), void>::type +for_each_tuple_const(std::tuple<Tp...> const & t, FnT && fn) +{ + fn(I, std::get<I>(t)); + for_each_tuple_const<I + 1, FnT, Tp...>(t, std::forward<FnT>(fn)); +} + + #ifdef DEBUG_NEW #define new DEBUG_NEW #endif |