Remove SingletonVault C bindings
[folly.git] / folly / poly / Regular.h
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #pragma once
18
19 #include <folly/Poly.h>
20
21 namespace folly {
22 namespace poly {
23 /**
24  * A `Poly` interface for types that are equality comparable.
25  */
26 struct IEqualityComparable : PolyExtends<> {
27   template <class T>
28   static auto isEqual_(T const& _this, T const& that)
29       -> decltype(std::declval<bool (&)(bool)>()(_this == that)) {
30     return _this == that;
31   }
32
33   template <class T>
34   using Members = FOLLY_POLY_MEMBERS(&isEqual_<T>);
35 };
36 } // namespace poly
37
38 /// \cond
39 namespace detail {
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>>>;
44 } // namespace detail
45 /// \endcond
46
47 template <
48     class I1,
49     class I2,
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));
55 }
56
57 template <
58     class I1,
59     class I2,
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);
63 }
64
65 namespace poly {
66 /**
67  * A `Poly` interface for types that are move-only.
68  */
69 struct IMoveOnly : PolyExtends<> {
70   template <class Base>
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;
77     using Base::Base;
78   };
79 };
80
81 /**
82  * A `Poly` interface for types that are copyable and movable.
83  */
84 struct ISemiRegular : PolyExtends<> {};
85
86 /**
87  * A `Poly` interface for types that are copyable, movable, and equality
88  * comparable.
89  */
90 struct IRegular : PolyExtends<ISemiRegular, IEqualityComparable> {};
91 } // namespace poly
92 } // namespace folly