Commit f576902c authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

Add support of Maybe<void> as a template specialization.

Blink wants to use Maybe<T> as a return type of (author) callback
functions, where T can be type void.  So, this patch adds support
of Maybe<void>.

Bug: chromium:778580, chromium:779036
Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng
Change-Id: Id654bafc5ceac8ef6f755902418f250c353a8837
Reviewed-on: https://chromium-review.googlesource.com/771730
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49416}
parent 0a12eaea
...@@ -8423,18 +8423,45 @@ class Maybe { ...@@ -8423,18 +8423,45 @@ class Maybe {
friend Maybe<U> Just(const U& u); friend Maybe<U> Just(const U& u);
}; };
template <class T> template <class T>
inline Maybe<T> Nothing() { inline Maybe<T> Nothing() {
return Maybe<T>(); return Maybe<T>();
} }
template <class T> template <class T>
inline Maybe<T> Just(const T& t) { inline Maybe<T> Just(const T& t) {
return Maybe<T>(t); return Maybe<T>(t);
} }
// A template specialization of Maybe<T> for the case of T = void.
template <>
class Maybe<void> {
public:
V8_INLINE bool IsNothing() const { return !is_valid_; }
V8_INLINE bool IsJust() const { return is_valid_; }
V8_INLINE bool operator==(const Maybe& other) const {
return IsJust() == other.IsJust();
}
V8_INLINE bool operator!=(const Maybe& other) const {
return !operator==(other);
}
private:
struct JustTag {};
Maybe() : is_valid_(false) {}
explicit Maybe(JustTag) : is_valid_(true) {}
bool is_valid_;
template <class U>
friend Maybe<U> Nothing();
friend Maybe<void> JustVoid();
};
inline Maybe<void> JustVoid() { return Maybe<void>(Maybe<void>::JustTag()); }
/** /**
* An external exception handler. * An external exception handler.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment