12 template <
typename Iterator,
typename Allocator>
22 : m_stack(1, base, alloc)
29 while (first != last) m_stack.push_back(first++);
32 Iterator& top()
const {
return const_cast<std::deque<Iterator>&
>(m_stack).front(); }
34 void pop() { m_stack.erase(m_stack.begin()); }
36 void push(Iterator
const& it) { m_stack.push_front(it); }
38 void push(Iterator first, Iterator last)
40 auto pos = m_stack.begin();
41 while (first != last) pos = ++m_stack.insert(pos, first++);
44 bool empty()
const {
return m_stack.empty(); }
47 std::deque<Iterator> m_stack;
54 template <
typename Iterator,
typename Allocator>
64 : m_queue(1, base, alloc)
71 while (first != last) m_queue.push_back(first++);
76 return const_cast<std::deque<Iterator>&
>(m_queue).front();
79 void pop() { m_queue.erase(m_queue.begin()); }
81 void push(Iterator
const& it) { m_queue.push_back(it); }
83 void push(Iterator first, Iterator last)
85 while (first != last) m_queue.push_back(first++);
88 bool empty()
const {
return m_queue.empty(); }
91 std::deque<Iterator> m_queue;
134 template <
typename Iterator,
typename Container,
typename Allocator>
137 template <
typename Iterator1,
typename Container1,
typename Allocator1>
140 template <
typename Iterator1,
typename Container1,
typename Allocator1>
144 using base_type = Iterator;
145 using container = Container;
146 using allocator_type = Allocator;
148 using value_type =
typename std::iterator_traits<base_type>::value_type;
149 using difference_type =
typename std::iterator_traits<base_type>::difference_type;
150 using reference =
typename std::iterator_traits<base_type>::reference;
151 using pointer =
typename std::iterator_traits<base_type>::pointer;
152 using iterator_category = std::input_iterator_tag;
173 basic_tree_iterator(base_type
const& first, base_type
const& last, allocator_type
const& alloc = allocator_type())
174 : m_c(first, last, alloc)
178 basic_tree_iterator(basic_tree_iterator
const&) =
default;
180 basic_tree_iterator(basic_tree_iterator&&) =
default;
182 basic_tree_iterator& operator=(basic_tree_iterator
const& rhs) =
default;
184 basic_tree_iterator& operator=(basic_tree_iterator&& rhs) =
default;
188 base_type
base()
const {
return m_c.top(); }
194 return const_cast<reference
>(*m_c.top());
201 return const_cast<pointer
>(m_c.top().operator->());
210 base_type it = m_c.top();
212 m_c.push(it.begin(), it.end());
224 base_type result = m_c.top();
233 template <
typename Iterator1,
typename Container1,
typename Allocator1>
234 inline bool operator==(basic_tree_iterator<Iterator1, Container1, Allocator1>
const& lhs, basic_tree_iterator<Iterator1, Container1, Allocator1>
const& rhs)
236 return (lhs.m_c.empty() && rhs.m_c.empty())
237 || (!lhs.m_c.empty() && !rhs.m_c.empty() && lhs.base() == rhs.base());
240 template <
typename Iterator1,
typename Container1,
typename Allocator1>
241 inline bool operator!=(basic_tree_iterator<Iterator1, Container1, Allocator1>
const& lhs, basic_tree_iterator<Iterator1, Container1, Allocator1>
const& rhs)
243 return !(lhs == rhs);
246 template <
typename Iterator,
typename Allocator = std::allocator<Iterator>>
247 using tree_iterator = basic_tree_iterator<Iterator, detail::tree_iterator_stack<Iterator, Allocator>, Allocator>;
249 template <
typename Iterator,
typename Allocator = std::allocator<Iterator>>
250 using level_order_tree_iterator = basic_tree_iterator<Iterator, detail::tree_iterator_queue<Iterator, Allocator>, Allocator>;