|
20 | 20 | #include <cstddef> |
21 | 21 | #include <iterator> |
22 | 22 | #include <list> |
| 23 | +#include <optional> |
23 | 24 | #include <utility> |
24 | 25 | #include <vector> |
25 | 26 |
|
@@ -92,7 +93,7 @@ template <typename KeyType, typename T> class RadixTree { |
92 | 93 | /// If this node does not have a value (i.e., it's an internal node that |
93 | 94 | /// only serves as a path to other values), this iterator will be equal |
94 | 95 | /// to default constructed `ContainerType::iterator()`. |
95 | | - typename ContainerType::iterator Value; |
| 96 | + std::optional<typename ContainerType::iterator> Value; |
96 | 97 |
|
97 | 98 | /// The first character of the Key. Used for fast child lookup. |
98 | 99 | KeyValueType KeyFront; |
@@ -215,7 +216,7 @@ template <typename KeyType, typename T> class RadixTree { |
215 | 216 | KeyConstIteratorType{}}; |
216 | 217 |
|
217 | 218 | void findNextValid() { |
218 | | - while (Curr && Curr->Value == typename ContainerType::iterator()) |
| 219 | + while (Curr && !Curr->Value.has_value()) |
219 | 220 | advance(); |
220 | 221 | } |
221 | 222 |
|
@@ -249,7 +250,7 @@ template <typename KeyType, typename T> class RadixTree { |
249 | 250 | public: |
250 | 251 | IteratorImpl() = default; |
251 | 252 |
|
252 | | - MappedType &operator*() const { return *Curr->Value; } |
| 253 | + MappedType &operator*() const { return **Curr->Value; } |
253 | 254 |
|
254 | 255 | IteratorImpl &operator++() { |
255 | 256 | advance(); |
@@ -315,12 +316,12 @@ template <typename KeyType, typename T> class RadixTree { |
315 | 316 | const value_type &NewValue = KeyValuePairs.emplace_front( |
316 | 317 | std::move(Key), T(std::forward<Ts>(Args)...)); |
317 | 318 | Node &Node = findOrCreate(NewValue.first); |
318 | | - bool HasValue = Node.Value != typename ContainerType::iterator(); |
| 319 | + bool HasValue = Node.Value.has_value(); |
319 | 320 | if (!HasValue) |
320 | 321 | Node.Value = KeyValuePairs.begin(); |
321 | 322 | else |
322 | 323 | KeyValuePairs.pop_front(); |
323 | | - return {Node.Value, !HasValue}; |
| 324 | + return {*Node.Value, !HasValue}; |
324 | 325 | } |
325 | 326 |
|
326 | 327 | /// |
|
0 commit comments