2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 #ifndef BEAST_HTTP_DETAIL_BASIC_FIELDS_HPP
9 #define BEAST_HTTP_DETAIL_BASIC_FIELDS_HPP
11 #include <beast/core/detail/ci_char_traits.hpp>
12 #include <boost/intrusive/list.hpp>
13 #include <boost/intrusive/set.hpp>
14 #include <boost/utility/string_ref.hpp>
19 template<class Allocator>
24 class basic_fields_base
32 value_type(boost::string_ref const& name_,
33 boost::string_ref const& value_)
53 template<class Allocator>
54 friend class beast::http::basic_fields;
57 : boost::intrusive::set_base_hook <
58 boost::intrusive::link_mode <
59 boost::intrusive::normal_link>>
60 , boost::intrusive::list_base_hook <
61 boost::intrusive::link_mode <
62 boost::intrusive::normal_link>>
66 element(boost::string_ref const& name,
67 boost::string_ref const& value)
73 struct less : private beast::detail::ci_less
75 template<class String>
77 operator()(String const& lhs, element const& rhs) const
79 return ci_less::operator()(lhs, rhs.data.first);
82 template<class String>
84 operator()(element const& lhs, String const& rhs) const
86 return ci_less::operator()(lhs.data.first, rhs);
90 operator()(element const& lhs, element const& rhs) const
92 return ci_less::operator()(
93 lhs.data.first, rhs.data.first);
97 using list_t = boost::intrusive::make_list<element,
98 boost::intrusive::constant_time_size<false>>::type;
100 using set_t = boost::intrusive::make_multiset<element,
101 boost::intrusive::constant_time_size<true>,
102 boost::intrusive::compare<less>>::type;
108 basic_fields_base(set_t&& set, list_t&& list)
109 : set_(std::move(set))
110 , list_(std::move(list))
115 class const_iterator;
117 using iterator = const_iterator;
119 basic_fields_base() = default;
122 //------------------------------------------------------------------------------
124 class basic_fields_base::const_iterator
126 using iter_type = list_t::const_iterator;
130 template<class Allocator>
131 friend class beast::http::basic_fields;
133 friend class basic_fields_base;
135 const_iterator(iter_type it)
142 typename basic_fields_base::value_type;
143 using pointer = value_type const*;
144 using reference = value_type const&;
145 using difference_type = std::ptrdiff_t;
146 using iterator_category =
147 std::bidirectional_iterator_tag;
149 const_iterator() = default;
150 const_iterator(const_iterator&& other) = default;
151 const_iterator(const_iterator const& other) = default;
152 const_iterator& operator=(const_iterator&& other) = default;
153 const_iterator& operator=(const_iterator const& other) = default;
156 operator==(const_iterator const& other) const
158 return it_ == other.it_;
162 operator!=(const_iterator const& other) const
164 return !(*this == other);