Index: mojo/public/cpp/bindings/lib/serialization_util.h |
diff --git a/mojo/public/cpp/bindings/lib/serialization_util.h b/mojo/public/cpp/bindings/lib/serialization_util.h |
index 9fc08b85228b1d2b40bd0c7f9a294ec4237a504b..926deae72b3b147d7814bcefcb747ff8ef733055 100644 |
--- a/mojo/public/cpp/bindings/lib/serialization_util.h |
+++ b/mojo/public/cpp/bindings/lib/serialization_util.h |
@@ -228,6 +228,18 @@ ReturnType CallWithContext(ReturnType (*f)(ParamType), |
} |
template <typename T, typename MaybeConstUserType> |
+struct HasGetBeginMethod { |
+ template <typename U> |
+ static char Test(decltype(U::GetBegin(std::declval<MaybeConstUserType&>()))*); |
+ template <typename U> |
+ static int Test(...); |
+ static const bool value = sizeof(Test<T>(0)) == sizeof(char); |
+ |
+ private: |
+ EnsureTypeIsComplete<T> check_t_; |
+}; |
+ |
+template <typename T, typename MaybeConstUserType> |
struct HasGetDataMethod { |
yzshen1
2016/06/10 16:21:32
nit: to be consistent with the surrounding code, p
Fady Samuel
2016/06/10 19:05:33
Done.
|
template <typename U> |
static char Test(decltype(U::GetData(std::declval<MaybeConstUserType&>()))*); |
@@ -243,6 +255,25 @@ template < |
typename Traits, |
typename MaybeConstUserType, |
typename std::enable_if< |
+ HasGetBeginMethod<Traits, MaybeConstUserType>::value>::type* = nullptr> |
+decltype(Traits::GetBegin(std::declval<MaybeConstUserType&>())) |
+CallGetBeginIfExists(MaybeConstUserType& input) { |
+ return Traits::GetBegin(input); |
+} |
+ |
+template < |
+ typename Traits, |
+ typename MaybeConstUserType, |
+ typename std::enable_if< |
+ !HasGetBeginMethod<Traits, MaybeConstUserType>::value>::type* = nullptr> |
+size_t CallGetBeginIfExists(MaybeConstUserType& input) { |
+ return 0; |
+} |
+ |
+template < |
+ typename Traits, |
+ typename MaybeConstUserType, |
+ typename std::enable_if< |
HasGetDataMethod<Traits, MaybeConstUserType>::value>::type* = nullptr> |
decltype(Traits::GetData(std::declval<MaybeConstUserType&>())) |
CallGetDataIfExists(MaybeConstUserType& input) { |