| Index: mojo/public/cpp/bindings/clone_traits.h
|
| diff --git a/mojo/public/cpp/bindings/lib/clone_equals_util.h b/mojo/public/cpp/bindings/clone_traits.h
|
| similarity index 41%
|
| copy from mojo/public/cpp/bindings/lib/clone_equals_util.h
|
| copy to mojo/public/cpp/bindings/clone_traits.h
|
| index f7bd898c3001c4e8e086d4e8408411061ad9248b..203ab34189a5e138a76b1f36eb17ae112cd816c5 100644
|
| --- a/mojo/public/cpp/bindings/lib/clone_equals_util.h
|
| +++ b/mojo/public/cpp/bindings/clone_traits.h
|
| @@ -1,9 +1,9 @@
|
| -// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_CLONE_EQUALS_UTIL_H_
|
| -#define MOJO_PUBLIC_CPP_BINDINGS_LIB_CLONE_EQUALS_UTIL_H_
|
| +#ifndef MOJO_PUBLIC_CPP_BINDINGS_CLONE_TRAITS_H_
|
| +#define MOJO_PUBLIC_CPP_BINDINGS_CLONE_TRAITS_H_
|
|
|
| #include <type_traits>
|
| #include <unordered_map>
|
| @@ -13,7 +13,6 @@
|
| #include "mojo/public/cpp/bindings/lib/template_util.h"
|
|
|
| namespace mojo {
|
| -namespace internal {
|
|
|
| template <typename T>
|
| struct HasCloneMethod {
|
| @@ -24,7 +23,7 @@ struct HasCloneMethod {
|
| static const bool value = sizeof(Test<T>(0)) == sizeof(char);
|
|
|
| private:
|
| - EnsureTypeIsComplete<T> check_t_;
|
| + internal::EnsureTypeIsComplete<T> check_t_;
|
| };
|
|
|
| template <typename T, bool has_clone_method = HasCloneMethod<T>::value>
|
| @@ -49,7 +48,7 @@ struct CloneTraits<base::Optional<T>, false> {
|
| if (!input)
|
| return base::nullopt;
|
|
|
| - return base::Optional<T>(internal::Clone(*input));
|
| + return base::Optional<T>(mojo::Clone(*input));
|
| }
|
| };
|
|
|
| @@ -59,7 +58,7 @@ struct CloneTraits<std::vector<T>, false> {
|
| std::vector<T> result;
|
| result.reserve(input.size());
|
| for (const auto& element : input)
|
| - result.push_back(internal::Clone(element));
|
| + result.push_back(mojo::Clone(element));
|
|
|
| return result;
|
| }
|
| @@ -70,8 +69,8 @@ struct CloneTraits<std::unordered_map<K, V>, false> {
|
| static std::unordered_map<K, V> Clone(const std::unordered_map<K, V>& input) {
|
| std::unordered_map<K, V> result;
|
| for (const auto& element : input) {
|
| - result.insert(std::make_pair(internal::Clone(element.first),
|
| - internal::Clone(element.second)));
|
| + result.insert(std::make_pair(mojo::Clone(element.first),
|
| + mojo::Clone(element.second)));
|
| }
|
| return result;
|
| }
|
| @@ -82,80 +81,6 @@ T Clone(const T& input) {
|
| return CloneTraits<T>::Clone(input);
|
| };
|
|
|
| -template <typename T>
|
| -struct HasEqualsMethod {
|
| - template <typename U>
|
| - static char Test(decltype(&U::Equals));
|
| - template <typename U>
|
| - static int Test(...);
|
| - static const bool value = sizeof(Test<T>(0)) == sizeof(char);
|
| -
|
| - private:
|
| - EnsureTypeIsComplete<T> check_t_;
|
| -};
|
| -
|
| -template <typename T, bool has_equals_method = HasEqualsMethod<T>::value>
|
| -struct EqualsTraits;
|
| -
|
| -template <typename T>
|
| -bool Equals(const T& a, const T& b);
|
| -
|
| -template <typename T>
|
| -struct EqualsTraits<T, true> {
|
| - static bool Equals(const T& a, const T& b) { return a.Equals(b); }
|
| -};
|
| -
|
| -template <typename T>
|
| -struct EqualsTraits<T, false> {
|
| - static bool Equals(const T& a, const T& b) { return a == b; }
|
| -};
|
| -
|
| -template <typename T>
|
| -struct EqualsTraits<base::Optional<T>, false> {
|
| - static bool Equals(const base::Optional<T>& a, const base::Optional<T>& b) {
|
| - if (!a && !b)
|
| - return true;
|
| - if (!a || !b)
|
| - return false;
|
| -
|
| - return internal::Equals(*a, *b);
|
| - }
|
| -};
|
| -
|
| -template <typename T>
|
| -struct EqualsTraits<std::vector<T>, false> {
|
| - static bool Equals(const std::vector<T>& a, const std::vector<T>& b) {
|
| - if (a.size() != b.size())
|
| - return false;
|
| - for (size_t i = 0; i < a.size(); ++i) {
|
| - if (!internal::Equals(a[i], b[i]))
|
| - return false;
|
| - }
|
| - return true;
|
| - }
|
| -};
|
| -
|
| -template <typename K, typename V>
|
| -struct EqualsTraits<std::unordered_map<K, V>, false> {
|
| - static bool Equals(const std::unordered_map<K, V>& a,
|
| - const std::unordered_map<K, V>& b) {
|
| - if (a.size() != b.size())
|
| - return false;
|
| - for (const auto& element : a) {
|
| - auto iter = b.find(element.first);
|
| - if (iter == b.end() || !internal::Equals(element.second, iter->second))
|
| - return false;
|
| - }
|
| - return true;
|
| - }
|
| -};
|
| -
|
| -template <typename T>
|
| -bool Equals(const T& a, const T& b) {
|
| - return EqualsTraits<T>::Equals(a, b);
|
| -}
|
| -
|
| -} // namespace internal
|
| } // namespace mojo
|
|
|
| -#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CLONE_EQUALS_UTIL_H_
|
| +#endif // MOJO_PUBLIC_CPP_BINDINGS_CLONE_TRAITS_H_
|
|
|