File indexing completed on 2025-01-18 09:29:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_DETAIL_TUPLE_HPP
0011 #define BOOST_BEAST_DETAIL_TUPLE_HPP
0012
0013 #include <boost/mp11/integer_sequence.hpp>
0014 #include <boost/mp11/algorithm.hpp>
0015 #include <boost/type_traits/remove_cv.hpp>
0016 #include <boost/type_traits/copy_cv.hpp>
0017 #include <cstdlib>
0018 #include <utility>
0019
0020 namespace boost {
0021 namespace beast {
0022 namespace detail {
0023
0024 template<std::size_t I, class T>
0025 struct tuple_element_impl
0026 {
0027 T t;
0028
0029 tuple_element_impl(T const& t_)
0030 : t(t_)
0031 {
0032 }
0033
0034 tuple_element_impl(T&& t_)
0035 : t(std::move(t_))
0036 {
0037 }
0038 };
0039
0040 template<std::size_t I, class T>
0041 struct tuple_element_impl<I, T&>
0042 {
0043 T& t;
0044
0045 tuple_element_impl(T& t_)
0046 : t(t_)
0047 {
0048 }
0049 };
0050
0051 template<class... Ts>
0052 struct tuple_impl;
0053
0054 template<class... Ts, std::size_t... Is>
0055 struct tuple_impl<
0056 boost::mp11::index_sequence<Is...>, Ts...>
0057 : tuple_element_impl<Is, Ts>...
0058 {
0059 template<class... Us>
0060 explicit tuple_impl(Us&&... us)
0061 : tuple_element_impl<Is, Ts>(
0062 std::forward<Us>(us))...
0063 {
0064 }
0065 };
0066
0067 template<class... Ts>
0068 struct tuple : tuple_impl<
0069 boost::mp11::index_sequence_for<Ts...>, Ts...>
0070 {
0071 template<class... Us>
0072 explicit tuple(Us&&... us)
0073 : tuple_impl<
0074 boost::mp11::index_sequence_for<Ts...>, Ts...>{
0075 std::forward<Us>(us)...}
0076 {
0077 }
0078 };
0079
0080 template<std::size_t I, class T>
0081 T&
0082 get(tuple_element_impl<I, T>& te)
0083 {
0084 return te.t;
0085 }
0086
0087 template<std::size_t I, class T>
0088 T const&
0089 get(tuple_element_impl<I, T> const& te)
0090 {
0091 return te.t;
0092 }
0093
0094 template<std::size_t I, class T>
0095 T&&
0096 get(tuple_element_impl<I, T>&& te)
0097 {
0098 return std::move(te.t);
0099 }
0100
0101 template<std::size_t I, class T>
0102 T&
0103 get(tuple_element_impl<I, T&>&& te)
0104 {
0105 return te.t;
0106 }
0107
0108 template <std::size_t I, class T>
0109 using tuple_element = typename boost::copy_cv<
0110 mp11::mp_at_c<typename remove_cv<T>::type, I>, T>::type;
0111
0112 }
0113 }
0114 }
0115
0116 #endif