Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Unified Diff: mojo/public/cpp/bindings/type_converter.h

Issue 2607063002: Remove mojo::Array. (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/bindings/type_converter.h
diff --git a/mojo/public/cpp/bindings/type_converter.h b/mojo/public/cpp/bindings/type_converter.h
index 1446ab375f55ede0ea3d553513bcd9addcf52375..e17ac861c3ec1c919764e60611b797fec066c2a6 100644
--- a/mojo/public/cpp/bindings/type_converter.h
+++ b/mojo/public/cpp/bindings/type_converter.h
@@ -7,6 +7,8 @@
#include <stdint.h>
+#include <vector>
+
namespace mojo {
// Specialize the following class:
@@ -74,6 +76,9 @@ namespace mojo {
template <typename T, typename U>
struct TypeConverter;
+template <typename T, typename U>
+inline T ConvertTo(const U& obj);
+
// The following specialization is useful when you are converting between
// Array<POD> and std::vector<POD>.
template <typename T>
@@ -81,6 +86,18 @@ struct TypeConverter<T, T> {
static T Convert(const T& obj) { return obj; }
};
+template <typename T, typename Container>
+struct TypeConverter<std::vector<T>, Container> {
dcheng 2017/01/10 05:58:09 I hope we can kill this someday.
+ static std::vector<T> Convert(const Container& container) {
+ std::vector<T> output;
+ output.reserve(container.size());
+ for (const auto& obj : container) {
+ output.push_back(ConvertTo<T>(obj));
+ }
+ return output;
+ }
+};
+
// The following helper function is useful for shorthand. The compiler can infer
// the input type, so you can write:
// OutputType out = ConvertTo<OutputType>(input);

Powered by Google App Engine
This is Rietveld 408576698