Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-24 09:53:06

0001 /*=============================================================================
0002     Copyright (c) 2016 Paul Fultz II
0003     unpack_tuple.hpp
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 ==============================================================================*/
0007 
0008 #ifndef BOOST_HOF_GUARD_UNPACK_TUPLE_HPP
0009 #define BOOST_HOF_GUARD_UNPACK_TUPLE_HPP
0010 
0011 #include <boost/hof/unpack_sequence.hpp>
0012 #include <boost/hof/returns.hpp>
0013 #include <boost/hof/detail/forward.hpp>
0014 #include <boost/hof/detail/seq.hpp>
0015 #include <tuple>
0016 #include <array>
0017 
0018 namespace boost { namespace hof {
0019 
0020 namespace detail {
0021 
0022 template<class Sequence>
0023 constexpr typename gens<std::tuple_size<Sequence>::value>::type 
0024 make_tuple_gens(const Sequence&)
0025 {
0026     return {};
0027 }
0028 
0029 #if (defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7)
0030 
0031 template<std::size_t I, class Tuple>
0032 struct tuple_element_return
0033 : std::tuple_element<I, Tuple>
0034 {};
0035 
0036 template<std::size_t I, class Tuple>
0037 struct tuple_element_return<I, Tuple&>
0038 : std::add_lvalue_reference<typename tuple_element_return<I, Tuple>::type>
0039 {};
0040 
0041 template<std::size_t I, class Tuple>
0042 struct tuple_element_return<I, Tuple&&>
0043 : std::add_rvalue_reference<typename tuple_element_return<I, Tuple>::type>
0044 {};
0045 
0046 template<std::size_t I, class Tuple>
0047 struct tuple_element_return<I, const Tuple>
0048 : std::add_const<typename tuple_element_return<I, Tuple>::type>
0049 {};
0050 
0051 template< std::size_t I, class Tuple, class R = typename tuple_element_return<I, Tuple&&>::type >
0052 R tuple_get( Tuple&& t ) 
0053 { 
0054     return (R&&)(std::get<I>(boost::hof::forward<Tuple>(t))); 
0055 }
0056 #define BOOST_HOF_UNPACK_TUPLE_GET boost::hof::detail::tuple_get
0057 #else
0058 #define BOOST_HOF_UNPACK_TUPLE_GET std::get
0059 
0060 #endif
0061 
0062 template<class F, class T, std::size_t ...N>
0063 constexpr auto unpack_tuple(F&& f, T&& t, seq<N...>) BOOST_HOF_RETURNS
0064 (
0065     f(
0066         BOOST_HOF_AUTO_FORWARD(BOOST_HOF_UNPACK_TUPLE_GET<N>(BOOST_HOF_AUTO_FORWARD(t)))...
0067     )
0068 );
0069 
0070 struct unpack_tuple_apply
0071 {
0072     template<class F, class S>
0073     constexpr static auto apply(F&& f, S&& t) BOOST_HOF_RETURNS
0074     (
0075         boost::hof::detail::unpack_tuple(BOOST_HOF_FORWARD(F)(f), BOOST_HOF_FORWARD(S)(t), boost::hof::detail::make_tuple_gens(t))
0076     );
0077 };
0078 
0079 }
0080 
0081 template<class... Ts>
0082 struct unpack_sequence<std::tuple<Ts...>>
0083 : detail::unpack_tuple_apply
0084 {};
0085 
0086 template<class T, class U>
0087 struct unpack_sequence<std::pair<T, U>>
0088 : detail::unpack_tuple_apply
0089 {};
0090 
0091 template<class T, std::size_t N>
0092 struct unpack_sequence<std::array<T, N>>
0093 : detail::unpack_tuple_apply
0094 {};
0095 
0096 }} // namespace boost::hof
0097 
0098 #endif