Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / include / __filesystem / path_iterator.h
blob9961b46cf81c0e98b519ad2c110a155989b6c907
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
11 #define _LIBCPP___FILESYSTEM_PATH_ITERATOR_H
13 #include <__assert>
14 #include <__availability>
15 #include <__config>
16 #include <__filesystem/path.h>
17 #include <__iterator/iterator_traits.h>
18 #include <cstddef>
19 #include <string>
20 #include <string_view>
22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23 # pragma GCC system_header
24 #endif
26 #ifndef _LIBCPP_CXX03_LANG
28 _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
30 class _LIBCPP_EXPORTED_FROM_ABI path::iterator {
31 public:
32 enum _ParserState : unsigned char {
33 _Singular,
34 _BeforeBegin,
35 _InRootName,
36 _InRootDir,
37 _InFilenames,
38 _InTrailingSep,
39 _AtEnd
42 public:
43 typedef input_iterator_tag iterator_category;
44 typedef bidirectional_iterator_tag iterator_concept;
46 typedef path value_type;
47 typedef ptrdiff_t difference_type;
48 typedef const path* pointer;
49 typedef path reference;
51 public:
52 _LIBCPP_INLINE_VISIBILITY
53 iterator()
54 : __stashed_elem_(), __path_ptr_(nullptr), __entry_(),
55 __state_(_Singular) {}
57 _LIBCPP_HIDE_FROM_ABI iterator(const iterator&) = default;
58 _LIBCPP_HIDE_FROM_ABI ~iterator() = default;
60 _LIBCPP_HIDE_FROM_ABI iterator& operator=(const iterator&) = default;
62 _LIBCPP_INLINE_VISIBILITY
63 reference operator*() const { return __stashed_elem_; }
65 _LIBCPP_INLINE_VISIBILITY
66 pointer operator->() const { return &__stashed_elem_; }
68 _LIBCPP_INLINE_VISIBILITY
69 iterator& operator++() {
70 _LIBCPP_ASSERT_UNCATEGORIZED(__state_ != _Singular,
71 "attempting to increment a singular iterator");
72 _LIBCPP_ASSERT_UNCATEGORIZED(__state_ != _AtEnd,
73 "attempting to increment the end iterator");
74 return __increment();
77 _LIBCPP_INLINE_VISIBILITY
78 iterator operator++(int) {
79 iterator __it(*this);
80 this->operator++();
81 return __it;
84 _LIBCPP_INLINE_VISIBILITY
85 iterator& operator--() {
86 _LIBCPP_ASSERT_UNCATEGORIZED(__state_ != _Singular,
87 "attempting to decrement a singular iterator");
88 _LIBCPP_ASSERT_UNCATEGORIZED(__entry_.data() != __path_ptr_->native().data(),
89 "attempting to decrement the begin iterator");
90 return __decrement();
93 _LIBCPP_INLINE_VISIBILITY
94 iterator operator--(int) {
95 iterator __it(*this);
96 this->operator--();
97 return __it;
100 private:
101 friend class path;
103 inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&,
104 const iterator&);
106 iterator& __increment();
107 iterator& __decrement();
109 path __stashed_elem_;
110 const path* __path_ptr_;
111 path::__string_view __entry_;
112 _ParserState __state_;
115 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
116 inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs,
117 const path::iterator& __rhs) {
118 return __lhs.__path_ptr_ == __rhs.__path_ptr_ &&
119 __lhs.__entry_.data() == __rhs.__entry_.data();
122 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY
123 inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs,
124 const path::iterator& __rhs) {
125 return !(__lhs == __rhs);
128 _LIBCPP_END_NAMESPACE_FILESYSTEM
130 #endif // _LIBCPP_CXX03_LANG
132 #endif // _LIBCPP___FILESYSTEM_PATH_ITERATOR_H