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>
20 #include <folly/poly/Regular.h>
25 * A `Poly` interface that can be used to make Poly objects initializable from
26 * `nullptr` (to create an empty `Poly`) and equality comparable to `nullptr`
27 * (to test for emptiness).
29 struct INullablePointer : PolyExtends<IEqualityComparable> {
31 struct Interface : Base {
32 Interface() = default;
35 /* implicit */ Interface(std::nullptr_t) : Base{} {
37 std::is_default_constructible<PolySelf<Base>>::value,
38 "Cannot initialize a non-default constructible Poly with nullptr");
41 PolySelf<Base>& operator=(std::nullptr_t) {
43 std::is_default_constructible<PolySelf<Base>>::value,
44 "Cannot initialize a non-default constructible Poly with nullptr");
45 auto& self = static_cast<PolySelf<Base>&>(*this);
46 self = PolySelf<Base>();
50 friend bool operator==(
52 PolySelf<Base> const& self) noexcept {
53 return poly_empty(self);
55 friend bool operator==(
56 PolySelf<Base> const& self,
57 std::nullptr_t) noexcept {
58 return poly_empty(self);
60 friend bool operator!=(
62 PolySelf<Base> const& self) noexcept {
63 return !poly_empty(self);
65 friend bool operator!=(
66 PolySelf<Base> const& self,
67 std::nullptr_t) noexcept {
68 return !poly_empty(self);
74 * A `Poly` interface that can be used to make `Poly` objects contextually
75 * convertible to `bool` (`true` if and only if non-empty). It also gives
76 * `Poly` objects a unary logical negation operator.
78 struct IBooleanTestable : PolyExtends<> {
80 struct Interface : Base {
81 constexpr bool operator!() const noexcept {
82 return poly_empty(*this);
84 constexpr explicit operator bool() const noexcept {