chromium/mojo/public/cpp/bindings/equals_traits.h

// Copyright 2016 The Chromium Authors
// 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_EQUALS_TRAITS_H_
#define MOJO_PUBLIC_CPP_BINDINGS_EQUALS_TRAITS_H_

#include <optional>
#include <type_traits>
#include <utility>
#include <vector>

#include "base/containers/flat_map.h"
#include "mojo/public/cpp/bindings/lib/template_util.h"

namespace mojo {

// EqualsTraits<> allows you to specify comparison functions for mapped mojo
// objects. By default objects can be compared if they implement operator==()
// or have a method named Equals().

template <typename T, typename SFINAE = void>
struct HasEqualsMethod : std::false_type {};

HasEqualsMethod<T, std::void_t<decltype(std::declval<const T &>().Equals(std::declval<const T &>()))>>;

template <typename T>
bool Equals(const T& a, const T& b);

template <typename T>
struct EqualsTraits {};

EqualsTraits<std::optional<T>>;

EqualsTraits<std::vector<T>>;

EqualsTraits<base::flat_map<K, V>>;

template <typename T>
bool Equals(const T& a, const T& b) {}

}  // namespace mojo

#endif  // MOJO_PUBLIC_CPP_BINDINGS_EQUALS_TRAITS_H_