HasValue -> HasValueForMaybe_

This commit is contained in:
Jacob Dufault 2018-02-11 13:49:44 -08:00
parent b71cf25186
commit 95f6460e6e
3 changed files with 7 additions and 5 deletions

View File

@ -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<Range, Id<void>, SymbolKind, Role> ToTuple() const {
return std::make_tuple(range, id, kind, role);

View File

@ -4,6 +4,8 @@
#include <utility>
// Like optional, but the stored data is responsible for containing the empty
// state. T should define a function `bool T::HasValueForMaybe_()`.
template <typename T>
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<T>() const {

View File

@ -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;