/*+ ARES/HADES/BORG Package -- ./libLSS/tools/tuple_helper.hpp Copyright (C) 2014-2020 Guilhem Lavaux Copyright (C) 2009-2020 Jens Jasche Additional contributions from: Guilhem Lavaux (2023) +*/ #ifndef __LIBLSS_TUPLE_HELPER_HPP #define __LIBLSS_TUPLE_HELPER_HPP #include #include namespace LibLSS { template struct _tuple_last_helper { template static inline auto convert(Tuple t, Args&&... args) -> decltype( _tuple_last_helper::convert(t, std::get(t), std::forward(args)...)) { return _tuple_last_helper::convert(t, std::get(t), std::forward(args)...); } }; template struct _tuple_last_helper { template static inline auto convert(Tuple t, Args&&... args) -> decltype( std::make_tuple(std::forward(args)...) ) { return std::make_tuple(std::forward(args)...); } }; template auto last_of_tuple(Tuple t) -> decltype(_tuple_last_helper::value-start, Tuple>::convert(t)) { return _tuple_last_helper::value-start, Tuple>::convert(t); } //https://stackoverflow.com/questions/1198260/how-can-you-iterate-over-the-elements-of-an-stdtuple template inline typename std::enable_if::type tuple_for_each(std::tuple const&, FuncT&&) // Unused arguments are given no names. { } template inline typename std::enable_if::type tuple_for_each(std::tuple const& t, FuncT&& f) { f(std::get(t)); tuple_for_each(t, std::forward(f)); } template inline typename std::enable_if::type tuple_for_each(std::tuple&& t, FuncT&& f) { f(std::get(t)); tuple_for_each(std::forward&&>(t), std::forward(f)); } } #endif