#ifndef BOOST_MP11_TUPLE_HPP_INCLUDED #define BOOST_MP11_TUPLE_HPP_INCLUDED // Copyright 2015, 2017 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt #include #include #include #include #include #include #if BOOST_MP11_MSVC # pragma warning( push ) # pragma warning( disable: 4100 ) // unreferenced formal parameter 'tp' #endif namespace boost { namespace mp11 { // tuple_apply namespace detail { template BOOST_MP11_CONSTEXPR auto tuple_apply_impl( F && f, Tp && tp, integer_sequence ) -> decltype( std::forward(f)( std::get(std::forward(tp))... ) ) { return std::forward(f)( std::get(std::forward(tp))... ); } } // namespace detail template::type>::value>> BOOST_MP11_CONSTEXPR auto tuple_apply( F && f, Tp && tp ) -> decltype( detail::tuple_apply_impl( std::forward(f), std::forward(tp), Seq() ) ) { return detail::tuple_apply_impl( std::forward(f), std::forward(tp), Seq() ); } // construct_from_tuple namespace detail { template BOOST_MP11_CONSTEXPR T construct_from_tuple_impl( Tp && tp, integer_sequence ) { return T( std::get(std::forward(tp))... ); } } // namespace detail template::type>::value>> BOOST_MP11_CONSTEXPR T construct_from_tuple( Tp && tp ) { return detail::construct_from_tuple_impl( std::forward(tp), Seq() ); } // tuple_for_each namespace detail { template BOOST_MP11_CONSTEXPR F tuple_for_each_impl( Tp && tp, integer_sequence, F && f ) { using A = int[sizeof...(J)]; return (void)A{ ((void)f(std::get(std::forward(tp))), 0)... }, std::forward(f); } template BOOST_MP11_CONSTEXPR F tuple_for_each_impl( Tp && /*tp*/, integer_sequence, F && f ) { return std::forward(f); } } // namespace detail template BOOST_MP11_CONSTEXPR F tuple_for_each( Tp && tp, F && f ) { using seq = make_index_sequence::type>::value>; return detail::tuple_for_each_impl( std::forward(tp), seq(), std::forward(f) ); } // tuple_transform namespace detail { template struct tuple_transform_caller { F const& f_; std::tuple const tps_; BOOST_MP11_CONSTEXPR tuple_transform_caller( Tp const& tp, F const& f, Tps const&... tps ) : f_{f}, tps_{tp, tps...} {} template BOOST_MP11_CONSTEXPR auto operator()( std::integral_constant, integer_sequence) const -> decltype(f_(std::get(std::get(tps_))...)) { return f_(std::get(std::get(tps_))...); } }; template struct tuple_transform_caller { F const& f_; Tp const& tp_; BOOST_MP11_CONSTEXPR tuple_transform_caller( Tp const& tp, F const& f ) : f_{f}, tp_{tp} {} template BOOST_MP11_CONSTEXPR auto operator()( std::integral_constant, integer_sequence ) const -> decltype(f_(std::get(tp_))) { return f_(std::get(tp_)); } }; template< template class Tp, class... Ts, class... Us, std::size_t... J, class Seq = make_index_sequence, // tuple sequence class R = Tp, Us...>>()( std::integral_constant{}, Seq{} ))...> > BOOST_MP11_CONSTEXPR R tuple_transform_impl( tuple_transform_caller, Us...> c, integer_sequence) { return R( c(std::integral_constant{}, Seq{})... ); } } // namespace detail // warning: evaluation order is undefined template< class F, class Tp, class... Tps, class Seq = make_index_sequence::value> // element sequence > BOOST_MP11_CONSTEXPR auto tuple_transform( F const& f, Tp const& tp, Tps const&... tps ) -> decltype(detail::tuple_transform_impl( std::declval>(), Seq{} )) { return detail::tuple_transform_impl( detail::tuple_transform_caller{ tp, f, tps... }, Seq{} ); } } // namespace mp11 } // namespace boost #if BOOST_MP11_MSVC # pragma warning( pop ) #endif #endif // #ifndef BOOST_TUPLE_HPP_INCLUDED