2 * Copyright 2017-present Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <folly/Poly.h>
24 * A `Poly` interface for types that are equality comparable.
26 struct IEqualityComparable : PolyExtends<> {
28 static auto isEqual_(T const& _this, T const& that)
29 -> decltype(std::declval<bool (&)(bool)>()(_this == that)) {
34 using Members = FOLLY_POLY_MEMBERS(&isEqual_<T>);
40 template <class I1, class I2>
41 using Comparable = Conjunction<
42 std::is_same<std::decay_t<I1>, std::decay_t<I2>>,
43 std::is_base_of<poly::IEqualityComparable, std::decay_t<I1>>>;
50 std::enable_if_t<detail::Comparable<I1, I2>::value, int> = 0>
51 bool operator==(Poly<I1> const& _this, Poly<I2> const& that) {
52 return (poly_empty(_this) && poly_empty(that)) ||
53 (poly_type(_this) == poly_type(that) &&
54 ::folly::poly_call<0, poly::IEqualityComparable>(_this, that));
60 std::enable_if_t<detail::Comparable<I1, I2>::value, int> = 0>
61 bool operator!=(Poly<I1> const& _this, Poly<I2> const& that) {
62 return !(_this == that);
67 * A `Poly` interface for types that are move-only.
69 struct IMoveOnly : PolyExtends<> {
71 struct Interface : Base {
72 Interface() = default;
73 Interface(Interface const&) = delete;
74 Interface(Interface&&) = default;
75 Interface& operator=(Interface const&) = delete;
76 Interface& operator=(Interface&&) = default;
82 * A `Poly` interface for types that are copyable and movable.
84 struct ISemiRegular : PolyExtends<> {};
87 * A `Poly` interface for types that are copyable, movable, and equality
90 struct IRegular : PolyExtends<ISemiRegular, IEqualityComparable> {};