/* * Copyright (c) Facebook, Inc. and its affiliates. * * 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. */ /** * Like folly::Optional, but can store a value *or* an error. * * @author Eric Niebler (eniebler@fb.com) */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define FOLLY_EXPECTED_ID(X) FB_CONCATENATE(FB_CONCATENATE(Folly, X), __LINE__) #define FOLLY_REQUIRES_IMPL(...) \ bool FOLLY_EXPECTED_ID(Requires) = false, \ typename std::enable_if< \ (FOLLY_EXPECTED_ID(Requires) || static_cast(__VA_ARGS__)), \ int>::type = 0 #define FOLLY_REQUIRES_TRAILING(...) , FOLLY_REQUIRES_IMPL(__VA_ARGS__) #define FOLLY_REQUIRES(...) template namespace folly { /** * Forward declarations */ template class Unexpected; template constexpr Unexpected::type> makeUnexpected(Error&&); template class Expected; template constexpr Expected::type, Error> makeExpected( Value&&); /** * Alias for an Expected type's assiciated value_type */ template using ExpectedValueType = typename std::remove_reference::type::value_type; /** * Alias for an Expected type's assiciated error_type */ template using ExpectedErrorType = typename std::remove_reference::type::error_type; // Details... namespace expected_detail { template struct PromiseReturn; template