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 3c9482ce6fb1a29480a70eaba7ac4ffdcb157d7e..9fc08b85228b1d2b40bd0c7f9a294ec4237a504b 100644 |
--- a/mojo/public/cpp/bindings/lib/serialization_util.h |
+++ b/mojo/public/cpp/bindings/lib/serialization_util.h |
@@ -227,6 +227,37 @@ ReturnType CallWithContext(ReturnType (*f)(ParamType), |
return f(std::forward<InputUserType>(input)); |
} |
+template <typename T, typename MaybeConstUserType> |
+struct HasGetDataMethod { |
+ template <typename U> |
+ static char Test(decltype(U::GetData(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 Traits, |
+ typename MaybeConstUserType, |
+ typename std::enable_if< |
+ HasGetDataMethod<Traits, MaybeConstUserType>::value>::type* = nullptr> |
+decltype(Traits::GetData(std::declval<MaybeConstUserType&>())) |
+CallGetDataIfExists(MaybeConstUserType& input) { |
+ return Traits::GetData(input); |
+} |
+ |
+template < |
+ typename Traits, |
+ typename MaybeConstUserType, |
+ typename std::enable_if< |
+ !HasGetDataMethod<Traits, MaybeConstUserType>::value>::type* = nullptr> |
+void* CallGetDataIfExists(MaybeConstUserType& input) { |
+ return nullptr; |
+} |
+ |
} // namespace internal |
} // namespace mojo |