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: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49416}
This commit is contained in:
Yuki Shiino 2017-11-16 22:54:38 +09:00 committed by Commit Bot
parent 0a12eaea45
commit f576902c99

View File

@ -8423,18 +8423,45 @@ class Maybe {
friend Maybe<U> Just(const U& u);
};
template <class T>
inline Maybe<T> Nothing() {
return Maybe<T>();
}
template <class T>
inline Maybe<T> Just(const 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.