diff --git a/src/indexer.hh b/src/indexer.hh index e75d39be..e435b39d 100644 --- a/src/indexer.hh +++ b/src/indexer.hh @@ -4,7 +4,6 @@ #pragma once #include "lsp.hh" -#include "maybe.hh" #include "position.hh" #include "serializer.hh" #include "utils.hh" diff --git a/src/maybe.hh b/src/maybe.hh deleted file mode 100644 index f0adf8a7..00000000 --- a/src/maybe.hh +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2017-2018 ccls Authors -// SPDX-License-Identifier: Apache-2.0 - -#pragma once - -#include - -#include - -namespace ccls { -// Like std::optional, but the stored data is responsible for containing the -// empty state. T should define a function `bool T::Valid()`. -template class Maybe { - T storage; - -public: - constexpr Maybe() = default; - Maybe(const Maybe &) = default; - Maybe(std::nullopt_t) {} - Maybe(const T &x) : storage(x) {} - Maybe(T &&x) : storage(std::forward(x)) {} - - Maybe &operator=(const Maybe &) = default; - Maybe &operator=(const T &x) { - storage = x; - return *this; - } - - const T *operator->() const { return &storage; } - T *operator->() { return &storage; } - const T &operator*() const { return storage; } - T &operator*() { return storage; } - - bool Valid() const { return storage.Valid(); } - explicit operator bool() const { return Valid(); } - operator std::optional() const { - if (Valid()) - return storage; - return std::nullopt; - } - - void operator=(std::optional &&o) { storage = o ? *o : T(); } - - // Does not test if has_value() - bool operator==(const Maybe &o) const { return storage == o.storage; } - bool operator!=(const Maybe &o) const { return !(*this == o); } -}; -} // namespace ccls diff --git a/src/position.hh b/src/position.hh index f92d24b7..61a6429c 100644 --- a/src/position.hh +++ b/src/position.hh @@ -3,7 +3,6 @@ #pragma once -#include "maybe.hh" #include "utils.hh" #include diff --git a/src/serializer.hh b/src/serializer.hh index b82da60d..0e68671c 100644 --- a/src/serializer.hh +++ b/src/serializer.hh @@ -3,7 +3,7 @@ #pragma once -#include "maybe.hh" +#include "utils.hh" #include diff --git a/src/utils.hh b/src/utils.hh index 3a5cdbd1..330259c9 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace llvm { @@ -87,4 +88,42 @@ inline void hash_combine(std::size_t &seed, const T &v, Rest... rest) { } std::string GetDefaultResourceDirectory(); + +// Like std::optional, but the stored data is responsible for containing the +// empty state. T should define a function `bool T::Valid()`. +template class Maybe { + T storage; + +public: + constexpr Maybe() = default; + Maybe(const Maybe &) = default; + Maybe(std::nullopt_t) {} + Maybe(const T &x) : storage(x) {} + Maybe(T &&x) : storage(std::forward(x)) {} + + Maybe &operator=(const Maybe &) = default; + Maybe &operator=(const T &x) { + storage = x; + return *this; + } + + const T *operator->() const { return &storage; } + T *operator->() { return &storage; } + const T &operator*() const { return storage; } + T &operator*() { return storage; } + + bool Valid() const { return storage.Valid(); } + explicit operator bool() const { return Valid(); } + operator std::optional() const { + if (Valid()) + return storage; + return std::nullopt; + } + + void operator=(std::optional &&o) { storage = o ? *o : T(); } + + // Does not test if has_value() + bool operator==(const Maybe &o) const { return storage == o.storage; } + bool operator!=(const Maybe &o) const { return !(*this == o); } +}; } // namespace ccls