File indexing completed on 2025-01-18 09:30:24
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_CONTEXT_DETAIL_TUPLE_H
0008 #define BOOST_CONTEXT_DETAIL_TUPLE_H
0009
0010 #include <tuple>
0011 #include <utility>
0012
0013 #include <boost/config.hpp>
0014
0015 #include <boost/context/detail/config.hpp>
0016 #include <boost/context/detail/index_sequence.hpp>
0017
0018 #ifdef BOOST_HAS_ABI_HEADERS
0019 # include BOOST_ABI_PREFIX
0020 #endif
0021
0022 namespace boost {
0023 namespace context {
0024 namespace detail {
0025
0026 template< typename ... S, typename ... T, std::size_t ... I >
0027 void
0028 head_impl( std::tuple< S ... > & s,
0029 std::tuple< T ... > & t, index_sequence< I ... >) {
0030 t = std::tuple< T ... >{ std::get< I >( s) ... };
0031 }
0032
0033 template< typename ... S, typename ... T, std::size_t ... I >
0034 void
0035 head_impl( std::tuple< S ... > && s,
0036 std::tuple< T ... > & t, index_sequence< I ... >) {
0037 t = std::tuple< T ... >{ std::get< I >( std::move( s) ) ... };
0038 }
0039
0040 template< typename ... S, std::size_t ... I1, typename ... T, std::size_t ... I2 >
0041 void
0042 tail_impl( std::tuple< S ... > & s, index_sequence< I1 ... >,
0043 std::tuple< T ... > & t, index_sequence< I2 ... >) {
0044 constexpr std::size_t Idx = (sizeof...(I1)) - (sizeof...(I2));
0045 t = std::tuple< T ... >{ std::get< (Idx + I2) >( s) ... };
0046 }
0047
0048 template< typename ... S, std::size_t ... I1, typename ... T, std::size_t ... I2 >
0049 void
0050 tail_impl( std::tuple< S ... > && s, index_sequence< I1 ... >,
0051 std::tuple< T ... > & t, index_sequence< I2 ... >) {
0052 constexpr std::size_t Idx = (sizeof...(I1)) - (sizeof...(I2));
0053 t = std::tuple< T ... >{ std::get< (Idx + I2) >( std::move( s) ) ... };
0054 }
0055
0056 template< typename ... T >
0057 class tuple_head;
0058
0059 template< typename ... T >
0060 class tuple_head< std::tuple< T ... > > {
0061 private:
0062 std::tuple< T ... > & t_;
0063
0064 public:
0065 tuple_head( std::tuple< T ... > & t) noexcept :
0066 t_( t) {
0067 }
0068
0069 template< typename ... S >
0070 void operator=( std::tuple< S ... > & s) {
0071 static_assert((sizeof...(T)) <= (sizeof...(S)), "invalid tuple size");
0072 head_impl( s,
0073 t_, index_sequence_for< T ... >{} );
0074 }
0075 template< typename ... S >
0076 void operator=( std::tuple< S ... > && s) {
0077 static_assert((sizeof...(T)) <= (sizeof...(S)), "invalid tuple size");
0078 head_impl( std::move( s),
0079 t_, index_sequence_for< T ... >{} );
0080 }
0081 };
0082
0083 template< typename ... T >
0084 class tuple_tail;
0085
0086 template< typename ... T >
0087 class tuple_tail< std::tuple< T ... > > {
0088 private:
0089 std::tuple< T ... > & t_;
0090
0091 public:
0092 tuple_tail( std::tuple< T ... > & t) noexcept :
0093 t_( t) {
0094 }
0095
0096 template< typename ... S >
0097 void operator=( std::tuple< S ... > & s) {
0098 static_assert((sizeof...(T)) <= (sizeof...(S)), "invalid tuple size");
0099 tail_impl( s, index_sequence_for< S ... >{},
0100 t_, index_sequence_for< T ... >{} );
0101 }
0102
0103 template< typename ... S >
0104 void operator=( std::tuple< S ... > && s) {
0105 static_assert((sizeof...(T)) <= (sizeof...(S)), "invalid tuple size");
0106 tail_impl( std::move( s), index_sequence_for< S ... >{},
0107 t_, index_sequence_for< T ... >{} );
0108 }
0109 };
0110
0111 template< typename ... T >
0112 detail::tuple_head< std::tuple< T ... > >
0113 head( std::tuple< T ... > & tpl) {
0114 return tuple_head< std::tuple< T ... > >{ tpl };
0115 }
0116
0117 template< typename ... T >
0118 detail::tuple_tail< std::tuple< T ... > >
0119 tail( std::tuple< T ... > & tpl) {
0120 return tuple_tail< std::tuple< T ... > >{ tpl };
0121 }
0122
0123 }}}
0124
0125 #ifdef BOOST_HAS_ABI_HEADERS
0126 #include BOOST_ABI_SUFFIX
0127 #endif
0128
0129 #endif