Chromium Code Reviews| 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); |