--- /dev/null
+/*
+ * Copyright 2017 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <folly/Expected.h>
+
+namespace folly {
+
+namespace expected_detail {
+
+// clang-format off
+[[noreturn]] void throwBadExpectedAccess() {
+ throw BadExpectedAccess();
+}
+// clang-format on
+
+} // namespace expected_detail
+
+} // namespace folly
BadExpectedAccess() : std::logic_error("bad Expected access") {}
};
+namespace expected_detail {
+
+[[noreturn]] void throwBadExpectedAccess();
+
+} // namespace expected_detail
+
/**
* Unexpected - a helper type used to disambiguate the construction of
* Expected objects in the error state.
void swap(Expected& that) noexcept(
expected_detail::StrictAllOf<IsNothrowSwappable, Value, Error>::value) {
if (this->uninitializedByException() || that.uninitializedByException()) {
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
}
using std::swap;
if (*this) {
std::declval<const Base&>(),
std::declval<Fns>()...)) {
if (this->uninitializedByException()) {
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
}
return expected_detail::ExpectedHelper::then_(
base(), static_cast<Fns&&>(fns)...);
std::declval<Base&>(),
std::declval<Fns>()...)) {
if (this->uninitializedByException()) {
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
}
return expected_detail::ExpectedHelper::then_(
base(), static_cast<Fns&&>(fns)...);
std::declval<Base&&>(),
std::declval<Fns>()...)) {
if (this->uninitializedByException()) {
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
}
return expected_detail::ExpectedHelper::then_(
std::move(base()), static_cast<Fns&&>(fns)...);
std::declval<Yes>()(std::declval<const Value&>())) {
using Ret = decltype(std::declval<Yes>()(std::declval<const Value&>()));
if (this->uninitializedByException()) {
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
}
return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
base(), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
std::declval<Yes>()(std::declval<Value&>())) {
using Ret = decltype(std::declval<Yes>()(std::declval<Value&>()));
if (this->uninitializedByException()) {
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
}
return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
base(), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
std::declval<Yes>()(std::declval<Value&&>())) {
using Ret = decltype(std::declval<Yes>()(std::declval<Value&&>()));
if (this->uninitializedByException()) {
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
}
return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
std::move(base()), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
if (LIKELY(hasError())) {
throw typename Unexpected<Error>::BadExpectedAccess(this->error_);
}
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
}
}
void requireError() const {
if (UNLIKELY(!hasError())) {
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
}
}
operator==(
const Expected<Value, Error>& lhs,
const Expected<Value, Error>& rhs) {
- if (UNLIKELY(lhs.which_ != rhs.which_)) {
- return UNLIKELY(lhs.uninitializedByException()) ? false
- : throw BadExpectedAccess();
- }
if (UNLIKELY(lhs.uninitializedByException())) {
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
+ }
+ if (UNLIKELY(lhs.which_ != rhs.which_)) {
+ return false;
}
if (UNLIKELY(lhs.hasError())) {
return true; // All error states are considered equal
const Expected<Value, Error>& rhs) {
if (UNLIKELY(
lhs.uninitializedByException() || rhs.uninitializedByException())) {
- throw BadExpectedAccess();
+ expected_detail::throwBadExpectedAccess();
}
if (UNLIKELY(lhs.hasError())) {
return !rhs.hasError();