File indexing completed on 2025-01-18 09:29:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_DETAIL_BUFFERS_PAIR_HPP
0011 #define BOOST_BEAST_DETAIL_BUFFERS_PAIR_HPP
0012
0013 #include <boost/asio/buffer.hpp>
0014 #include <boost/assert.hpp>
0015 #include <boost/config/workaround.hpp>
0016 #include <type_traits>
0017
0018 namespace boost {
0019 namespace beast {
0020 namespace detail {
0021
0022 #if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
0023 # pragma warning (push)
0024 # pragma warning (disable: 4521)
0025 # pragma warning (disable: 4522)
0026 #endif
0027
0028 template<bool isMutable>
0029 class buffers_pair
0030 {
0031 public:
0032
0033
0034 using value_type = typename
0035 std::conditional<isMutable,
0036 net::mutable_buffer,
0037 net::const_buffer>::type;
0038
0039 using const_iterator = value_type const*;
0040
0041 buffers_pair() = default;
0042
0043 #if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
0044 buffers_pair(buffers_pair const& other)
0045 : buffers_pair(
0046 *other.begin(), *(other.begin() + 1))
0047 {
0048 }
0049
0050 buffers_pair&
0051 operator=(buffers_pair const& other)
0052 {
0053 b_[0] = *other.begin();
0054 b_[1] = *(other.begin() + 1);
0055 return *this;
0056 }
0057 #else
0058 buffers_pair(buffers_pair const& other) = default;
0059 buffers_pair& operator=(buffers_pair const& other) = default;
0060 #endif
0061
0062 template<
0063 bool isMutable_ = isMutable,
0064 class = typename std::enable_if<
0065 ! isMutable_>::type>
0066 buffers_pair(buffers_pair<true> const& other)
0067 : buffers_pair(
0068 *other.begin(), *(other.begin() + 1))
0069 {
0070 }
0071
0072 template<
0073 bool isMutable_ = isMutable,
0074 class = typename std::enable_if<
0075 ! isMutable_>::type>
0076 buffers_pair&
0077 operator=(buffers_pair<true> const& other)
0078 {
0079 b_[0] = *other.begin();
0080 b_[1] = *(other.begin() + 1);
0081 return *this;
0082 }
0083
0084 buffers_pair(value_type b0, value_type b1)
0085 : b_{b0, b1}
0086 {
0087 }
0088
0089 const_iterator
0090 begin() const noexcept
0091 {
0092 return &b_[0];
0093 }
0094
0095 const_iterator
0096 end() const noexcept
0097 {
0098 if(b_[1].size() > 0)
0099 return &b_[2];
0100 return &b_[1];
0101 }
0102
0103 private:
0104 value_type b_[2];
0105 };
0106
0107 #if BOOST_WORKAROUND(BOOST_MSVC, < 1910)
0108 # pragma warning (pop)
0109 #endif
0110
0111 }
0112 }
0113 }
0114
0115 #endif