| 1 | #ifndef BOOST_BIND_DETAIL_TUPLE_FOR_EACH_HPP_INCLUDED |
| 2 | #define BOOST_BIND_DETAIL_TUPLE_FOR_EACH_HPP_INCLUDED |
| 3 | |
| 4 | // Copyright 2015-2020, 2024 Peter Dimov. |
| 5 | // |
| 6 | // Distributed under the Boost Software License, Version 1.0. |
| 7 | // |
| 8 | // See accompanying file LICENSE_1_0.txt or copy at |
| 9 | // http://www.boost.org/LICENSE_1_0.txt |
| 10 | |
| 11 | #include <boost/bind/detail/integer_sequence.hpp> |
| 12 | #include <boost/config.hpp> |
| 13 | #include <utility> |
| 14 | #include <type_traits> |
| 15 | #include <cstddef> |
| 16 | |
| 17 | #if defined(BOOST_MSVC) |
| 18 | # pragma warning( push ) |
| 19 | # pragma warning( disable: 4100 ) // unreferenced formal parameter 'tp' |
| 20 | #endif |
| 21 | |
| 22 | namespace boost |
| 23 | { |
| 24 | namespace _bi |
| 25 | { |
| 26 | |
| 27 | // tuple_for_each( f, tp ) |
| 28 | |
| 29 | template<class F, class Tp, std::size_t... J> F tuple_for_each_impl( F&& f, Tp&& tp, integer_sequence<std::size_t, J...> ) |
| 30 | { |
| 31 | using A = int[ 1 + sizeof...(J) ]; |
| 32 | using std::get; |
| 33 | return (void)A{ 0, ((void)f(get<J>(std::forward<Tp>(tp))), 0)... }, std::forward<F>(f); |
| 34 | } |
| 35 | |
| 36 | template<class F, class Tp> F tuple_for_each( F&& f, Tp&& tp ) |
| 37 | { |
| 38 | using seq = make_index_sequence<std::tuple_size<typename std::remove_reference<Tp>::type>::value>; |
| 39 | return _bi::tuple_for_each_impl( std::forward<F>(f), std::forward<Tp>(tp), seq() ); |
| 40 | } |
| 41 | |
| 42 | // tuple_for_each( f, tp1, tp2 ) |
| 43 | |
| 44 | template<class F, class Tp1, class Tp2, std::size_t... J> F tuple_for_each_impl( F&& f, Tp1&& tp1, Tp2&& tp2, integer_sequence<std::size_t, J...> ) |
| 45 | { |
| 46 | using A = int[ 1 + sizeof...(J) ]; |
| 47 | using std::get; |
| 48 | return (void)A{ 0, ((void)f( get<J>(std::forward<Tp1>(tp1)), get<J>(std::forward<Tp2>(tp2)) ), 0)... }, std::forward<F>(f); |
| 49 | } |
| 50 | |
| 51 | template<class F, class Tp1, class Tp2> F tuple_for_each( F&& f, Tp1&& tp1, Tp2&& tp2 ) |
| 52 | { |
| 53 | using seq = make_index_sequence<std::tuple_size<typename std::remove_reference<Tp1>::type>::value>; |
| 54 | return _bi::tuple_for_each_impl( std::forward<F>(f), std::forward<Tp1>(tp1), std::forward<Tp2>(tp2), seq() ); |
| 55 | } |
| 56 | |
| 57 | } // namespace _bi |
| 58 | } // namespace boost |
| 59 | |
| 60 | #if defined(BOOST_MSVC) |
| 61 | # pragma warning( pop ) |
| 62 | #endif |
| 63 | |
| 64 | #endif // #ifndef BOOST_BIND_DETAIL_TUPLE_FOR_EACH_HPP_INCLUDED |
| 65 | |