Chromium Code Reviews| Index: mojo/public/cpp/bindings/array.h |
| diff --git a/mojo/public/cpp/bindings/array.h b/mojo/public/cpp/bindings/array.h |
| index faf7398fffd427ea0c969d11a2b8d798e987bd14..67f3fbc1b587c56e95612e54761d1db32ab98c0f 100644 |
| --- a/mojo/public/cpp/bindings/array.h |
| +++ b/mojo/public/cpp/bindings/array.h |
| @@ -14,6 +14,7 @@ |
| #include <vector> |
| #include "base/macros.h" |
| +#include "base/optional.h" |
| #include "mojo/public/cpp/bindings/lib/array_internal.h" |
| #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
| #include "mojo/public/cpp/bindings/lib/clone_equals_util.h" |
| @@ -49,9 +50,15 @@ class Array { |
| // Copies the contents of |other| into this array. |
| Array(const std::vector<T>& other) : vec_(other), is_null_(false) {} |
| + Array(const base::Optional<std::vector<T>>& other) |
|
sky
2016/11/18 00:41:55
Is it typical not to use explicit for this and 58?
yzshen1
2016/11/18 00:48:09
Non-explicit makes the transition easier. Because
|
| + : vec_(other.value_or(std::vector<T>())), is_null_(!other) {} |
| // Moves the contents of |other| into this array. |
| Array(std::vector<T>&& other) : vec_(std::move(other)), is_null_(false) {} |
| + Array(base::Optional<std::vector<T>>&& other) : is_null_(!other) { |
| + if (!is_null_) |
| + vec_ = std::move(other.value()); |
| + } |
| Array(Array&& other) : is_null_(true) { Take(&other); } |
| Array& operator=(std::vector<T>&& other) { |
| @@ -59,6 +66,11 @@ class Array { |
| is_null_ = false; |
| return *this; |
| } |
| + Array& operator=(base::Optional<std::vector<T>>&& other) { |
| + is_null_ = !other; |
| + vec_ = std::move(other).value_or(std::vector<T>()); |
| + return *this; |
| + } |
| Array& operator=(Array&& other) { |
| Take(&other); |
| return *this; |
| @@ -149,6 +161,14 @@ class Array { |
| return std::move(vec_); |
| } |
| + base::Optional<std::vector<T>> PassStorageAsOptional() { |
| + base::Optional<std::vector<T>> result; |
| + if (!is_null_) |
| + result.emplace(std::move(vec_)); |
| + is_null_ = true; |
| + return result; |
| + } |
| + |
| operator const std::vector<T>&() const { return vec_; } |
| void Swap(Array* other) { |