/* * Copyright 2016-present 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. */ /** * 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 #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 /** * gcc-4.7 warns about use of uninitialized memory around the use of storage_ * even though this is explicitly initialized at each point. */ #if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wuninitialized" #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif // __GNUC__ 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; #ifdef _MSC_VER // MSVC 2015 can't handle the StrictConjunction, so we have // to use std::conjunction instead. template