Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit ea704b2

Browse files
committed
use native optional
1 parent 18aac65 commit ea704b2

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

src/core/optional.h

+3-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
11
#ifndef SUPERSTRING_OPTIONAL_H
22
#define SUPERSTRING_OPTIONAL_H
33

4-
#include <utility>
4+
#include <optional>
5+
using std::optional;
56

6-
template <typename T> class optional {
7-
T value;
8-
bool is_some;
9-
10-
public:
11-
optional(T &&value) : value(std::move(value)), is_some(true) {}
12-
optional(const T &value) : value(value), is_some(true) {}
13-
optional() : value(T()), is_some(false) {}
14-
15-
T &operator*() { return value; }
16-
const T &operator*() const { return value; }
17-
const T *operator->() const { return &value; }
18-
T *operator->() { return &value; }
19-
operator bool() const { return is_some; }
20-
bool operator==(const optional<T> &other) {
21-
if (is_some) {
22-
return other.is_some && value == other.value;
23-
} else {
24-
return !other.is_some;
25-
}
26-
}
27-
};
28-
29-
#endif // SUPERSTRING_OPTIONAL_H
7+
#endif // SUPERSTRING_OPTIONAL_H

0 commit comments

Comments
 (0)