diff --git a/src/indexer.h b/src/indexer.h index 6ed84d5b..25757a45 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -63,7 +63,7 @@ struct Id { // Needed for google::dense_hash_map. explicit operator RawId() const { return id; } - bool HasValue() const { return id != RawId(-1); } + bool HasValueForMaybe_() const { return id != RawId(-1); } bool operator==(const Id& o) const { return id == o.id; } bool operator!=(const Id& o) const { return id != o.id; } @@ -112,7 +112,7 @@ struct Reference { SymbolKind kind; Role role; - bool HasValue() const { return range.HasValue(); } + bool HasValueForMaybe_() const { return range.HasValueForMaybe_(); } operator SymbolIdx() const { return {id, kind}; } std::tuple, SymbolKind, Role> ToTuple() const { return std::make_tuple(range, id, kind, role); diff --git a/src/maybe.h b/src/maybe.h index eb482e50..60942f1d 100644 --- a/src/maybe.h +++ b/src/maybe.h @@ -4,6 +4,8 @@ #include +// Like optional, but the stored data is responsible for containing the empty +// state. T should define a function `bool T::HasValueForMaybe_()`. template class Maybe { T storage; @@ -27,7 +29,7 @@ public: T& operator*() { return storage; } bool has_value() const { - return storage.HasValue(); + return storage.HasValueForMaybe_(); } explicit operator bool() const { return has_value(); } operator optional() const { diff --git a/src/position.h b/src/position.h index b01f696e..8d238b55 100644 --- a/src/position.h +++ b/src/position.h @@ -15,7 +15,7 @@ struct Position { Position(int16_t line, int16_t column); explicit Position(const char* encoded); - bool HasValue() const { return line >= 0; } + bool HasValueForMaybe_() const { return line >= 0; } std::string ToString(); std::string ToPrettyString(const std::string& filename); @@ -39,7 +39,7 @@ struct Range { Range(Position start, Position end); explicit Range(const char* encoded); - bool HasValue() const { return start.HasValue(); } + bool HasValueForMaybe_() const { return start.HasValueForMaybe_(); } bool Contains(int line, int column) const; Range RemovePrefix(Position position) const;