#ifndef BOOST_MP11_TUPLE_HPP_INCLUDED #define BOOST_MP11_TUPLE_HPP_INCLUDED // Copyright 2015-2020 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 #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 { // std::forward_as_tuple is not constexpr in C++11 or libstdc++ 5.x template BOOST_MP11_CONSTEXPR auto tp_forward_r( T&&... t ) -> std::tuple { return std::tuple( std::forward( t )... ); } template BOOST_MP11_CONSTEXPR auto tp_forward_v( T&&... t ) -> std::tuple { return std::tuple( std::forward( t )... ); } template BOOST_MP11_CONSTEXPR auto tp_extract( Tp&&... tp ) -> decltype( tp_forward_r( std::get( std::forward( tp ) )... ) ) { return tp_forward_r( std::get( std::forward( tp ) )... ); } #if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) template BOOST_MP11_CONSTEXPR auto tuple_transform_impl( integer_sequence, F const& f, Tp&&... tp ) -> decltype( tp_forward_v( tuple_apply( f, tp_extract( std::forward(tp)... ) )... ) ) { return tp_forward_v( tuple_apply( f, tp_extract( std::forward(tp)... ) )... ); } #else template BOOST_MP11_CONSTEXPR auto tuple_transform_impl( integer_sequence, F const& f, Tp1&& tp1 ) -> decltype( tp_forward_v( f( std::get( std::forward(tp1) ) )... ) ) { return tp_forward_v( f( std::get( std::forward(tp1) ) )... ); } template BOOST_MP11_CONSTEXPR auto tuple_transform_impl( integer_sequence, F const& f, Tp1&& tp1, Tp2&& tp2 ) -> decltype( tp_forward_v( f( std::get( std::forward(tp1) ), std::get( std::forward(tp2) ) )... ) ) { return tp_forward_v( f( std::get( std::forward(tp1) ), std::get( std::forward(tp2) ) )... ); } template BOOST_MP11_CONSTEXPR auto tuple_transform_impl( integer_sequence, F const& f, Tp1&& tp1, Tp2&& tp2, Tp3&& tp3 ) -> decltype( tp_forward_v( f( std::get( std::forward(tp1) ), std::get( std::forward(tp2) ), std::get( std::forward(tp3) ) )... ) ) { return tp_forward_v( f( std::get( std::forward(tp1) ), std::get( std::forward(tp2) ), std::get( std::forward(tp3) ) )... ); } #endif // !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) } // namespace detail #if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1910 ) template::type>::value>> BOOST_MP11_CONSTEXPR auto tuple_transform( F const& f, Tp1&& tp1, Tp&&... tp ) -> decltype( detail::tuple_transform_impl( Seq(), f, std::forward(tp1), std::forward(tp)... ) ) { return detail::tuple_transform_impl( Seq(), f, std::forward(tp1), std::forward(tp)... ); } #else template::type>::value>...>, class E = mp_if, mp_front>, class Seq = make_index_sequence> BOOST_MP11_CONSTEXPR auto tuple_transform( F const& f, Tp&&... tp ) -> decltype( detail::tuple_transform_impl( Seq(), f, std::forward(tp)... ) ) { return detail::tuple_transform_impl( Seq(), f, std::forward(tp)... ); } #endif // BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1910 ) } // namespace mp11 } // namespace boost #if BOOST_MP11_MSVC # pragma warning( pop ) #endif #endif // #ifndef BOOST_TUPLE_HPP_INCLUDED