-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_iterator.hpp
More file actions
79 lines (53 loc) · 2.29 KB
/
list_iterator.hpp
File metadata and controls
79 lines (53 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) Omar Boukli-Hacene. All rights reserved.
// Distributed under an MIT-style license that can be
// found in the LICENSE file.
// SPDX-License-Identifier: MIT
#ifndef FORFUN_CONTAINER_INTERNAL_LIST_ITERATOR_HPP_
#define FORFUN_CONTAINER_INTERNAL_LIST_ITERATOR_HPP_
#include <cassert>
#include <iterator>
#include "forfun/container/internal/list_iterator_helper.hpp"
#include "forfun/container/internal/list_node.hpp"
namespace forfun::experimental::container::internal {
class list_iterator final : public list_iterator_helper<list_iterator> {
public:
using value_type = int;
using reference = value_type&;
using const_reference = value_type const&;
constexpr explicit list_iterator() noexcept = default;
constexpr explicit list_iterator(list_node* const node) noexcept :
list_iterator_helper{node}
{
}
constexpr list_iterator(list_iterator const& other) noexcept = default;
constexpr list_iterator(list_iterator&& other) noexcept = default;
constexpr ~list_iterator() noexcept = default;
auto operator=(list_iterator const& other) noexcept
-> list_iterator& = default;
auto operator=(list_iterator&& other) noexcept -> list_iterator& = default;
auto operator*() const noexcept -> reference
{
assert(node_ != nullptr);
return node_->value_;
}
};
} // namespace forfun::experimental::container::internal
template <>
struct std::iterator_traits<
forfun::experimental::container::internal::list_iterator> {
using const_reference = forfun::experimental::container::internal::
list_iterator::const_reference;
using difference_type = forfun::experimental::container::internal::
list_iterator::difference_type;
using iterator_category = forfun::experimental::container::internal::
list_iterator::iterator_category;
using iterator_concept = forfun::experimental::container::internal::
list_iterator::iterator_concept;
using pointer
= forfun::experimental::container::internal::list_iterator::pointer;
using reference
= forfun::experimental::container::internal::list_iterator::reference;
using value_type
= forfun::experimental::container::internal::list_iterator::value_type;
};
#endif // FORFUN_CONTAINER_INTERNAL_LIST_ITERATOR_HPP_