proxygen
Regular.h
Go to the documentation of this file.
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 {
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 
41  template <class T>
42  static auto isLess_(T const& _this, T const& that)
43  -> decltype(std::declval<bool (&)(bool)>()(_this < that)) {
44  return _this < that;
45  }
46 
47  template <class T>
48  using Members = FOLLY_POLY_MEMBERS(&isLess_<T>);
49 };
50 
51 } // namespace poly
52 
54 namespace detail {
55 template <class I1, class I2>
56 using Comparable = Conjunction<
57  std::is_same<std::decay_t<I1>, std::decay_t<I2>>,
58  std::is_base_of<poly::IEqualityComparable, std::decay_t<I1>>>;
59 
60 template <class I1, class I2>
61 using Orderable = Conjunction<
62  std::is_same<std::decay_t<I1>, std::decay_t<I2>>,
63  std::is_base_of<poly::IStrictlyOrderable, std::decay_t<I1>>>;
64 } // namespace detail
66 
67 template <
68  class I1,
69  class I2,
71 bool operator==(Poly<I1> const& _this, Poly<I2> const& that) {
72  if (poly_empty(_this) != poly_empty(that)) {
73  return false;
74  } else if (poly_empty(_this)) {
75  return true;
76  } else if (poly_type(_this) != poly_type(that)) {
77  throw BadPolyCast();
78  }
79  return ::folly::poly_call<0, poly::IEqualityComparable>(_this, that);
80 }
81 
82 template <
83  class I1,
84  class I2,
85  std::enable_if_t<detail::Comparable<I1, I2>::value, int> = 0>
86 bool operator!=(Poly<I1> const& _this, Poly<I2> const& that) {
87  return !(_this == that);
88 }
89 
90 template <
91  class I1,
92  class I2,
94 bool operator<(Poly<I1> const& _this, Poly<I2> const& that) {
95  if (poly_empty(that)) {
96  return false;
97  } else if (poly_empty(_this)) {
98  return true;
99  } else if (poly_type(_this) != poly_type(that)) {
100  throw BadPolyCast{};
101  }
102  return ::folly::poly_call<0, poly::IStrictlyOrderable>(_this, that);
103 }
104 
105 template <
106  class I1,
107  class I2,
108  std::enable_if_t<detail::Orderable<I1, I2>::value, int> = 0>
109 bool operator>(Poly<I1> const& _this, Poly<I2> const& that) {
110  return that < _this;
111 }
112 
113 template <
114  class I1,
115  class I2,
116  std::enable_if_t<detail::Orderable<I1, I2>::value, int> = 0>
117 bool operator<=(Poly<I1> const& _this, Poly<I2> const& that) {
118  return !(that < _this);
119 }
120 
121 template <
122  class I1,
123  class I2,
124  std::enable_if_t<detail::Orderable<I1, I2>::value, int> = 0>
125 bool operator>=(Poly<I1> const& _this, Poly<I2> const& that) {
126  return !(_this < that);
127 }
128 
129 namespace poly {
133 struct IMoveOnly : PolyExtends<> {
134  template <class Base>
135  struct Interface : Base {
136  Interface() = default;
137  Interface(Interface const&) = delete;
138  Interface(Interface&&) = default;
139  Interface& operator=(Interface const&) = delete;
140  Interface& operator=(Interface&&) = default;
141  using Base::Base;
142  };
143 };
144 
148 struct ISemiRegular : PolyExtends<> {};
149 
154 struct IRegular : PolyExtends<ISemiRegular, IEqualityComparable> {};
155 } // namespace poly
156 } // namespace folly
bool operator>(const Expected< Value, Error > &lhs, const Expected< Value, Error > &rhs)
Definition: Expected.h:1349
FOLLY_POLY_MEMBERS(&isLess_< T >) Members
Definition: Regular.h:48
std::type_info const & poly_type(detail::PolyRoot< I > const &that) noexcept
Definition: Poly.h:358
#define FOLLY_POLY_MEMBERS(...)
Definition: Poly.h:136
folly::std T
static auto isEqual_(T const &_this, T const &that) -> decltype(std::declval< bool(&)(bool)>()(_this==that))
Definition: Regular.h:28
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
bool operator!=(const Unexpected< Error > &lhs, const Unexpected< Error > &rhs)
Definition: Expected.h:766
static auto isLess_(T const &_this, T const &that) -> decltype(std::declval< bool(&)(bool)>()(_this< that))
Definition: Regular.h:42
AtomicCounter< T, DeterministicAtomic > Base
bool poly_empty(detail::PolyRoot< I > const &that) noexcept
Definition: Poly.h:383
static const char *const value
Definition: Conv.cpp:50
bool operator>=(const Expected< Value, Error > &lhs, const Expected< Value, Error > &rhs)
Definition: Expected.h:1358
FOLLY_POLY_MEMBERS(&isEqual_< T >) Members
Definition: Regular.h:34
bool operator==(const Unexpected< Error > &lhs, const Unexpected< Error > &rhs)
Definition: Expected.h:758