]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/stl_interfaces/example/node_iterator.cpp
1 // Copyright (C) 2019 T. Zachary Laine
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/stl_interfaces/iterator_interface.hpp>
20 node
* next_
; // == nullptr in the tail node
24 //[ node_iterator_class_head
27 : boost::stl_interfaces::
28 iterator_interface
<node_iterator
<T
>, std::forward_iterator_tag
, T
>
31 //[ node_iterator_ctors
32 constexpr node_iterator() noexcept
: it_(nullptr) {}
33 constexpr node_iterator(node
<T
> * it
) noexcept
: it_(it
) {}
36 //[ node_iterator_user_ops
37 constexpr T
& operator*() const noexcept
{ return it_
->value_
; }
38 constexpr node_iterator
& operator++() noexcept
44 operator==(node_iterator lhs
, node_iterator rhs
) noexcept
46 return lhs
.it_
== rhs
.it_
;
50 //[ node_iterator_using_declaration
51 using base_type
= boost::stl_interfaces::
52 iterator_interface
<node_iterator
<T
>, std::forward_iterator_tag
, T
>;
53 using base_type::operator++;
60 //[ node_iterator_concept_check Equivalent to
61 // static_assert(std::forward_iterator<node_iterator>, ""), or nothing in
63 BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT(node_iterator
, std::forward_iterator
)
69 std::array
<node
<int>, 5> nodes
;
70 std::generate(nodes
.begin(), nodes
.end(), [] {
72 return node
<int>{i
++};
75 nodes
.begin(), nodes
.end(), [](node
<int> & a
, node
<int> & b
) {
79 nodes
.back().next_
= nullptr;
81 //[ node_iterator_usage
82 node_iterator
<int> const first(&nodes
[0]);
83 node_iterator
<int> const last
;
84 for (auto it
= first
; it
!= last
; it
++) {
85 std::cout
<< *it
<< " "; // Prints 0 1 2 3 4