Add tuple_for_each.

This commit is contained in:
Peter Dimov
2015-06-24 14:57:32 +03:00
parent 4a33810f9b
commit 05ab3e7a42
4 changed files with 164 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#ifndef BOOST_TUPLE_FOR_EACH_HPP_INCLUDED
#define BOOST_TUPLE_FOR_EACH_HPP_INCLUDED
#include <boost/integer_sequence.hpp>
#include <boost/config.hpp>
#include <tuple>
#include <utility>
#include <type_traits>
#include <cstddef>
namespace boost
{
namespace detail
{
template<class Tp, std::size_t... J, class F> BOOST_CONSTEXPR F tuple_for_each_impl( Tp && tp, boost::integer_sequence<std::size_t, J...>, F && f )
{
using A = int[sizeof...(J)];
return (void)A{ (f(std::get<J>(std::forward<Tp>(tp))), 0)... }, std::forward<F>(f);
}
} // namespace detail
template<class Tp, class F> BOOST_CONSTEXPR F tuple_for_each( Tp && tp, F && f )
{
using seq = boost::make_index_sequence<std::tuple_size<typename std::remove_reference<Tp>::type>::value>;
return detail::tuple_for_each_impl( std::forward<Tp>(tp), seq(), std::forward<F>(f) );
}
} // namespace boost
#endif // #ifndef BOOST_TUPLE_FOR_EACH_HPP_INCLUDED