From 896816273ca1f349c1d313ae093ffe27df8c926e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Dec 2020 05:12:05 -0600 Subject: [PATCH 1/2] use native optional --- src/core/optional.h | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/src/core/optional.h b/src/core/optional.h index 61280d99..33852e05 100644 --- a/src/core/optional.h +++ b/src/core/optional.h @@ -1,29 +1,7 @@ #ifndef SUPERSTRING_OPTIONAL_H #define SUPERSTRING_OPTIONAL_H -#include +#include +using std::optional; -template class optional { - T value; - bool is_some; - -public: - optional(T &&value) : value(std::move(value)), is_some(true) {} - optional(const T &value) : value(value), is_some(true) {} - optional() : value(T()), is_some(false) {} - - T &operator*() { return value; } - const T &operator*() const { return value; } - const T *operator->() const { return &value; } - T *operator->() { return &value; } - operator bool() const { return is_some; } - bool operator==(const optional &other) { - if (is_some) { - return other.is_some && value == other.value; - } else { - return !other.is_some; - } - } -}; - -#endif // SUPERSTRING_OPTIONAL_H +#endif // SUPERSTRING_OPTIONAL_H From b0702ea0532f203d4b39b28e5802283ebbb547d8 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 3 Dec 2020 06:02:35 -0600 Subject: [PATCH 2/2] remove optional.h and include optional directly --- src/bindings/em/auto-wrap.h | 3 ++- src/bindings/marker-index-wrapper.cc | 3 ++- src/bindings/marker-index-wrapper.h | 3 ++- src/bindings/number-conversion.h | 3 ++- src/bindings/point-wrapper.h | 3 ++- src/bindings/range-wrapper.h | 3 ++- src/bindings/string-conversion.h | 3 ++- src/core/encoding-conversion.h | 3 ++- src/core/optional.h | 7 ------- src/core/patch.cc | 3 ++- src/core/patch.h | 3 ++- src/core/regex.h | 3 ++- src/core/text.h | 3 ++- 13 files changed, 24 insertions(+), 19 deletions(-) delete mode 100644 src/core/optional.h diff --git a/src/bindings/em/auto-wrap.h b/src/bindings/em/auto-wrap.h index ff4ff070..7fd3f938 100644 --- a/src/bindings/em/auto-wrap.h +++ b/src/bindings/em/auto-wrap.h @@ -7,7 +7,8 @@ #include #include "flat_set.h" #include "marker-index.h" -#include "optional.h" +#include +using std::optional; #include "point.h" #include "text.h" diff --git a/src/bindings/marker-index-wrapper.cc b/src/bindings/marker-index-wrapper.cc index f53853e3..138e096d 100644 --- a/src/bindings/marker-index-wrapper.cc +++ b/src/bindings/marker-index-wrapper.cc @@ -3,7 +3,8 @@ #include "marker-index.h" #include "nan.h" #include "noop.h" -#include "optional.h" +#include +using std::optional; #include "point-wrapper.h" #include "range.h" diff --git a/src/bindings/marker-index-wrapper.h b/src/bindings/marker-index-wrapper.h index 2f64cc54..f6eaba13 100644 --- a/src/bindings/marker-index-wrapper.h +++ b/src/bindings/marker-index-wrapper.h @@ -1,6 +1,7 @@ #include "nan.h" #include "marker-index.h" -#include "optional.h" +#include +using std::optional; #include "range.h" class MarkerIndexWrapper : public Nan::ObjectWrap { diff --git a/src/bindings/number-conversion.h b/src/bindings/number-conversion.h index cc063be9..3a3f0fc1 100644 --- a/src/bindings/number-conversion.h +++ b/src/bindings/number-conversion.h @@ -2,7 +2,8 @@ #define SUPERSTRING_NUMBER_CONVERSION_H #include "nan.h" -#include "optional.h" +#include +using std::optional; namespace number_conversion { template diff --git a/src/bindings/point-wrapper.h b/src/bindings/point-wrapper.h index fc06b263..52e500fc 100644 --- a/src/bindings/point-wrapper.h +++ b/src/bindings/point-wrapper.h @@ -2,7 +2,8 @@ #define SUPERSTRING_POINT_WRAPPER_H #include "nan.h" -#include "optional.h" +#include +using std::optional; #include "point.h" class PointWrapper : public Nan::ObjectWrap { diff --git a/src/bindings/range-wrapper.h b/src/bindings/range-wrapper.h index de08dd59..9df83e6f 100644 --- a/src/bindings/range-wrapper.h +++ b/src/bindings/range-wrapper.h @@ -2,7 +2,8 @@ #define SUPERSTRING_RANGE_WRAPPER_H #include "nan.h" -#include "optional.h" +#include +using std::optional; #include "point.h" #include "range.h" diff --git a/src/bindings/string-conversion.h b/src/bindings/string-conversion.h index f8178041..61ebfc64 100644 --- a/src/bindings/string-conversion.h +++ b/src/bindings/string-conversion.h @@ -3,7 +3,8 @@ #include #include "nan.h" -#include "optional.h" +#include +using std::optional; #include "text.h" namespace string_conversion { diff --git a/src/core/encoding-conversion.h b/src/core/encoding-conversion.h index 3b91146a..f24303d5 100644 --- a/src/core/encoding-conversion.h +++ b/src/core/encoding-conversion.h @@ -1,7 +1,8 @@ #ifndef SUPERSTRING_ENCODING_CONVERSION_H_ #define SUPERSTRING_ENCODING_CONVERSION_H_ -#include "optional.h" +#include +using std::optional; #include "text.h" #include diff --git a/src/core/optional.h b/src/core/optional.h deleted file mode 100644 index 33852e05..00000000 --- a/src/core/optional.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef SUPERSTRING_OPTIONAL_H -#define SUPERSTRING_OPTIONAL_H - -#include -using std::optional; - -#endif // SUPERSTRING_OPTIONAL_H diff --git a/src/core/patch.cc b/src/core/patch.cc index 8702f9b3..550f91db 100644 --- a/src/core/patch.cc +++ b/src/core/patch.cc @@ -1,5 +1,6 @@ #include "patch.h" -#include "optional.h" +#include +using std::optional; #include "text.h" #include "text-slice.h" #include diff --git a/src/core/patch.h b/src/core/patch.h index c59021e5..4ddf8aad 100644 --- a/src/core/patch.h +++ b/src/core/patch.h @@ -1,7 +1,8 @@ #ifndef PATCH_H_ #define PATCH_H_ -#include "optional.h" +#include +using std::optional; #include "point.h" #include "serializer.h" #include "text.h" diff --git a/src/core/regex.h b/src/core/regex.h index 10970306..cd8de961 100644 --- a/src/core/regex.h +++ b/src/core/regex.h @@ -1,7 +1,8 @@ #ifndef REGEX_H_ #define REGEX_H_ -#include "optional.h" +#include +using std::optional; #include struct pcre2_real_code_16; diff --git a/src/core/text.h b/src/core/text.h index 0326a902..4f0f9bb5 100644 --- a/src/core/text.h +++ b/src/core/text.h @@ -7,7 +7,8 @@ #include #include "serializer.h" #include "point.h" -#include "optional.h" +#include +using std::optional; class TextSlice;