@@ -3,174 +3,15 @@ namespace winrt::impl
33{
44 namespace wfc = Windows::Foundation::Collections;
55
6- template <typename T>
7- struct fast_iterator
6+ template <typename D, typename T>
7+ auto consume_Windows_Foundation_Collections_IIterable<D, T>::begin() const
88 {
9- using iterator_category = std::input_iterator_tag;
10- using value_type = decltype (std::declval<T>().GetAt(0 ));
11- using difference_type = ptrdiff_t ;
12- using pointer = value_type*;
13- using reference = value_type;
14-
15- fast_iterator () noexcept : m_collection(nullptr ), m_index(0 ) {}
16-
17- fast_iterator (T const & collection, uint32_t const index) noexcept :
18- m_collection (&collection),
19- m_index (index)
20- {}
21-
22- fast_iterator& operator ++() noexcept
23- {
24- ++m_index;
25- return *this ;
26- }
27-
28- fast_iterator operator ++(int ) noexcept
29- {
30- auto previous = *this ;
31- ++m_index;
32- return previous;
33- }
34-
35- fast_iterator& operator --() noexcept
36- {
37- --m_index;
38- return *this ;
39- }
40-
41- fast_iterator operator --(int ) noexcept
42- {
43- auto previous = *this ;
44- --m_index;
45- return previous;
46- }
47-
48- fast_iterator& operator +=(difference_type n) noexcept
49- {
50- m_index += static_cast <uint32_t >(n);
51- return *this ;
52- }
53-
54- fast_iterator operator +(difference_type n) const noexcept
55- {
56- return fast_iterator (*this ) += n;
57- }
58-
59- fast_iterator& operator -=(difference_type n) noexcept
60- {
61- return *this += -n;
62- }
63-
64- fast_iterator operator -(difference_type n) const noexcept
65- {
66- return *this + -n;
67- }
68-
69- difference_type operator -(fast_iterator const & other) const noexcept
70- {
71- return static_cast <difference_type>(m_index) - static_cast <difference_type>(other.m_index );
72- }
73-
74- reference operator *() const
75- {
76- return m_collection->GetAt (m_index);
77- }
78-
79- reference operator [](difference_type n) const
80- {
81- return m_collection->GetAt (m_index + static_cast <uint32_t >(n));
82- }
83-
84- bool operator ==(fast_iterator const & other) const noexcept
85- {
86- WINRT_ASSERT (m_collection == other.m_collection );
87- return m_index == other.m_index ;
88- }
89-
90- bool operator <(fast_iterator const & other) const noexcept
91- {
92- WINRT_ASSERT (m_collection == other.m_collection );
93- return m_index < other.m_index ;
94- }
95-
96- bool operator !=(fast_iterator const & other) const noexcept
97- {
98- return !(*this == other);
99- }
100-
101- bool operator >(fast_iterator const & other) const noexcept
102- {
103- return !(*this < other);
104- }
105-
106- bool operator <=(fast_iterator const & other) const noexcept
107- {
108- return !(*this > other);
109- }
110-
111- bool operator >=(fast_iterator const & other) const noexcept
112- {
113- return !(*this < other);
114- }
115-
116- private:
117-
118- T const * m_collection{};
119- uint32_t m_index{};
120- };
121-
122- template <typename T>
123- class has_GetAt
124- {
125- template <typename U, typename = decltype (std::declval<U>().GetAt(0 ))> static constexpr bool get_value (int ) { return true ; }
126- template <typename > static constexpr bool get_value (...) { return false ; }
127-
128- public:
129-
130- static constexpr bool value = get_value<T>(0 );
131- };
132-
133- template <typename T, std::enable_if_t <!has_GetAt<T>::value, int > = 0 >
134- auto begin (T const & collection) -> decltype(collection.First())
135- {
136- auto result = collection.First ();
137-
138- if (!result.HasCurrent ())
139- {
140- return {};
141- }
142-
143- return result;
144- }
145-
146- template <typename T, std::enable_if_t <!has_GetAt<T>::value, int > = 0 >
147- auto end ([[maybe_unused]] T const & collection) noexcept -> decltype(collection.First())
148- {
149- return {};
9+ return get_begin_iterator (static_cast <D const &>(*this ));
15010 }
151-
152- template <typename T, std::enable_if_t <has_GetAt<T>::value, int > = 0 >
153- fast_iterator<T> begin (T const & collection) noexcept
154- {
155- return { collection, 0 };
156- }
157-
158- template <typename T, std::enable_if_t <has_GetAt<T>::value, int > = 0 >
159- fast_iterator<T> end (T const & collection)
160- {
161- return { collection, collection.Size () };
162- }
163-
164- template <typename T, std::enable_if_t <has_GetAt<T>::value, int > = 0 >
165- auto rbegin (T const & collection)
166- {
167- return std::make_reverse_iterator (end (collection));
168- }
169-
170- template <typename T, std::enable_if_t <has_GetAt<T>::value, int > = 0 >
171- auto rend (T const & collection)
11+ template <typename D, typename T>
12+ auto consume_Windows_Foundation_Collections_IIterable<D, T>::end() const
17213 {
173- return std::make_reverse_iterator ( begin (collection ));
14+ return get_end_iterator ( static_cast <D const &>(* this ));
17415 }
17516
17617 template <typename T>
0 commit comments