react-native-windows 0.81.34 → 0.81.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Directory.Build.props +1 -16
- package/Folly/ThreadNameStub.cpp +4 -6
- package/Microsoft.ReactNative/Fabric/Composition/BorderPrimitive.cpp +1 -1
- package/Microsoft.ReactNative/Fabric/Composition/CompositionEventHandler.cpp +27 -4
- package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +8 -4
- package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +7 -3
- package/Microsoft.ReactNative/Fabric/Composition/TooltipService.cpp +48 -2
- package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +40 -13
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +1 -7
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +0 -3
- package/PropertySheets/Generated/PackageVersion.g.props +3 -3
- package/PropertySheets/React.Cpp.props +3 -3
- package/ReactCommon/ReactCommon.vcxproj +0 -10
- package/ReactCommon/packages.lock.win32.json +0 -10
- package/Scripts/Tfs/Layout-Desktop-Headers.ps1 +4 -37
- package/Scripts/creaternwlib.cmd +2 -2
- package/Shared/Shared.vcxitems +2 -0
- package/{Folly → external}/.clang-format +0 -1
- package/external/External.vcxitems +10 -0
- package/external/fast-float/.syncignore +10 -0
- package/external/fast-float/LICENSE-APACHE +190 -0
- package/external/fast-float/LICENSE-BOOST +23 -0
- package/external/fast-float/LICENSE-MIT +27 -0
- package/external/fast-float/README.md +545 -0
- package/external/fast-float/cgmanifest.json +15 -0
- package/external/fast-float/fast-float.vcxitems +14 -0
- package/external/fast-float/include/fast_float/ascii_number.h +588 -0
- package/external/fast-float/include/fast_float/bigint.h +638 -0
- package/external/fast-float/include/fast_float/constexpr_feature_detect.h +46 -0
- package/external/fast-float/include/fast_float/decimal_to_binary.h +212 -0
- package/external/fast-float/include/fast_float/digit_comparison.h +457 -0
- package/external/fast-float/include/fast_float/fast_float.h +59 -0
- package/external/fast-float/include/fast_float/fast_table.h +708 -0
- package/external/fast-float/include/fast_float/float_common.h +1240 -0
- package/external/fast-float/include/fast_float/parse_number.h +399 -0
- package/external/fast-float/sync-config.json +8 -0
- package/external/fmt/.syncignore +10 -0
- package/external/fmt/CONTRIBUTING.md +20 -0
- package/external/fmt/LICENSE +27 -0
- package/external/fmt/README.md +484 -0
- package/{fmt → external/fmt}/cgmanifest.json +1 -1
- package/external/fmt/doc/ChangeLog-old.md +3290 -0
- package/external/fmt/doc/api.md +650 -0
- package/external/fmt/doc/fmt.css +61 -0
- package/external/fmt/doc/fmt.js +4 -0
- package/external/fmt/doc/get-started.md +222 -0
- package/external/fmt/doc/index.md +151 -0
- package/external/fmt/doc/perf.svg +1 -0
- package/external/fmt/doc/python-license.txt +290 -0
- package/external/fmt/doc/syntax.md +887 -0
- package/external/fmt/fmt.vcxitems +28 -0
- package/external/fmt/include/fmt/args.h +228 -0
- package/{fmt/TEMP_UntilFmtUpdate/core.h → external/fmt/include/fmt/base.h} +1188 -1036
- package/external/fmt/include/fmt/chrono.h +2432 -0
- package/external/fmt/include/fmt/color.h +612 -0
- package/external/fmt/include/fmt/compile.h +529 -0
- package/external/fmt/include/fmt/core.h +5 -0
- package/external/fmt/include/fmt/format-inl.h +1928 -0
- package/external/fmt/include/fmt/format.h +4427 -0
- package/external/fmt/include/fmt/os.h +439 -0
- package/external/fmt/include/fmt/ostream.h +211 -0
- package/external/fmt/include/fmt/printf.h +656 -0
- package/external/fmt/include/fmt/ranges.h +882 -0
- package/external/fmt/include/fmt/std.h +699 -0
- package/external/fmt/include/fmt/xchar.h +322 -0
- package/external/fmt/src/fmt.cc +135 -0
- package/external/fmt/src/format.cc +43 -0
- package/external/fmt/src/os.cc +403 -0
- package/external/fmt/sync-config.json +8 -0
- package/external/folly/.syncignore +60 -0
- package/external/folly/LICENSE +200 -0
- package/external/folly/README.md +263 -0
- package/{fmt → external/folly/folly}/.clang-format +0 -1
- package/external/folly/folly/AtomicHashArray-inl.h +546 -0
- package/external/folly/folly/AtomicHashArray.h +431 -0
- package/external/folly/folly/AtomicHashMap-inl.h +653 -0
- package/external/folly/folly/AtomicHashMap.h +484 -0
- package/external/folly/folly/AtomicIntrusiveLinkedList.h +206 -0
- package/external/folly/folly/AtomicLinkedList.h +110 -0
- package/external/folly/folly/AtomicUnorderedMap.h +522 -0
- package/external/folly/folly/BUCK +1631 -0
- package/external/folly/folly/BUILD_MODE.bzl +72 -0
- package/external/folly/folly/Benchmark.cpp +986 -0
- package/external/folly/folly/Benchmark.h +680 -0
- package/external/folly/folly/BenchmarkUtil.h +47 -0
- package/external/folly/folly/Bits.h +17 -0
- package/external/folly/folly/CMakeLists.txt +110 -0
- package/external/folly/folly/CPortability.h +338 -0
- package/external/folly/folly/CancellationToken-inl.h +449 -0
- package/external/folly/folly/CancellationToken.cpp +250 -0
- package/external/folly/folly/CancellationToken.h +365 -0
- package/external/folly/folly/Chrono.h +132 -0
- package/external/folly/folly/ClockGettimeWrappers.cpp +93 -0
- package/external/folly/folly/ClockGettimeWrappers.h +29 -0
- package/external/folly/folly/ConcurrentBitSet.h +157 -0
- package/external/folly/folly/ConcurrentLazy.h +74 -0
- package/external/folly/folly/ConcurrentSkipList-inl.h +341 -0
- package/external/folly/folly/ConcurrentSkipList.h +824 -0
- package/external/folly/folly/ConstructorCallbackList.h +158 -0
- package/external/folly/folly/Conv.h +2026 -0
- package/external/folly/folly/CppAttributes.h +170 -0
- package/external/folly/folly/CpuId.h +297 -0
- package/external/folly/folly/DefaultKeepAliveExecutor.h +172 -0
- package/external/folly/folly/Demangle.cpp +255 -0
- package/external/folly/folly/Demangle.h +73 -0
- package/external/folly/folly/DiscriminatedPtr.h +236 -0
- package/external/folly/folly/DynamicConverter.h +17 -0
- package/external/folly/folly/Exception.h +150 -0
- package/external/folly/folly/ExceptionString.cpp +51 -0
- package/external/folly/folly/ExceptionString.h +33 -0
- package/external/folly/folly/ExceptionWrapper-inl.h +264 -0
- package/external/folly/folly/ExceptionWrapper.cpp +37 -0
- package/external/folly/folly/ExceptionWrapper.h +377 -0
- package/external/folly/folly/Executor.cpp +111 -0
- package/external/folly/folly/Executor.h +351 -0
- package/external/folly/folly/Expected.h +1725 -0
- package/external/folly/folly/FBString.h +2888 -0
- package/external/folly/folly/FBVector.h +17 -0
- package/external/folly/folly/File.cpp +180 -0
- package/external/folly/folly/File.h +177 -0
- package/external/folly/folly/FileUtil.cpp +378 -0
- package/external/folly/folly/FileUtil.h +332 -0
- package/external/folly/folly/Fingerprint.cpp +135 -0
- package/external/folly/folly/Fingerprint.h +289 -0
- package/external/folly/folly/FixedString.h +2965 -0
- package/external/folly/folly/FollyMemcpy.cpp +30 -0
- package/external/folly/folly/FollyMemcpy.h +23 -0
- package/external/folly/folly/FollyMemset.cpp +29 -0
- package/external/folly/folly/FollyMemset.h +25 -0
- package/external/folly/folly/Format-inl.h +1152 -0
- package/external/folly/folly/Format.cpp +429 -0
- package/external/folly/folly/Format.h +463 -0
- package/external/folly/folly/FormatArg.h +285 -0
- package/external/folly/folly/FormatTraits.h +65 -0
- package/external/folly/folly/Function.h +1159 -0
- package/external/folly/folly/GLog.h +85 -0
- package/external/folly/folly/GroupVarint.cpp +153 -0
- package/external/folly/folly/GroupVarint.h +630 -0
- package/external/folly/folly/Hash.h +20 -0
- package/external/folly/folly/IPAddress.cpp +490 -0
- package/external/folly/folly/IPAddress.h +667 -0
- package/external/folly/folly/IPAddressException.h +82 -0
- package/external/folly/folly/IPAddressV4.cpp +305 -0
- package/external/folly/folly/IPAddressV4.h +495 -0
- package/external/folly/folly/IPAddressV6.cpp +541 -0
- package/external/folly/folly/IPAddressV6.h +627 -0
- package/external/folly/folly/Indestructible.h +164 -0
- package/external/folly/folly/IndexedMemPool.h +550 -0
- package/external/folly/folly/IntrusiveList.h +17 -0
- package/external/folly/folly/Lazy.h +142 -0
- package/external/folly/folly/Likely.h +76 -0
- package/external/folly/folly/MPMCPipeline.h +280 -0
- package/external/folly/folly/MPMCQueue.h +1556 -0
- package/external/folly/folly/MacAddress.cpp +188 -0
- package/external/folly/folly/MacAddress.h +260 -0
- package/external/folly/folly/MapUtil.h +17 -0
- package/external/folly/folly/Math.h +258 -0
- package/external/folly/folly/MaybeManagedPtr.h +120 -0
- package/external/folly/folly/Memory.h +900 -0
- package/external/folly/folly/MicroLock.cpp +76 -0
- package/external/folly/folly/MicroLock.h +354 -0
- package/external/folly/folly/MicroSpinLock.h +17 -0
- package/external/folly/folly/MoveWrapper.h +76 -0
- package/external/folly/folly/ObserverContainer.h +1026 -0
- package/external/folly/folly/Optional.h +743 -0
- package/external/folly/folly/Overload.h +325 -0
- package/external/folly/folly/PackedSyncPtr.h +147 -0
- package/external/folly/folly/Padded.h +464 -0
- package/external/folly/folly/Poly-inl.h +230 -0
- package/external/folly/folly/Poly.h +1095 -0
- package/external/folly/folly/PolyException.h +43 -0
- package/external/folly/folly/Portability.h +644 -0
- package/external/folly/folly/Preprocessor.h +236 -0
- package/external/folly/folly/ProducerConsumerQueue.h +182 -0
- package/external/folly/folly/RWSpinLock.h +17 -0
- package/external/folly/folly/Random-inl.h +86 -0
- package/external/folly/folly/Random.cpp +184 -0
- package/external/folly/folly/Random.h +434 -0
- package/external/folly/folly/Range.h +1772 -0
- package/external/folly/folly/Replaceable.h +636 -0
- package/external/folly/folly/ScopeGuard.cpp +29 -0
- package/external/folly/folly/ScopeGuard.h +420 -0
- package/external/folly/folly/SharedMutex.cpp +81 -0
- package/external/folly/folly/SharedMutex.h +1751 -0
- package/external/folly/folly/Singleton-inl.h +332 -0
- package/external/folly/folly/Singleton.cpp +512 -0
- package/external/folly/folly/Singleton.h +891 -0
- package/external/folly/folly/SingletonThreadLocal.cpp +53 -0
- package/external/folly/folly/SingletonThreadLocal.h +263 -0
- package/external/folly/folly/SocketAddress.cpp +786 -0
- package/external/folly/folly/SocketAddress.h +768 -0
- package/external/folly/folly/SpinLock.h +55 -0
- package/external/folly/folly/String-inl.h +668 -0
- package/external/folly/folly/String.cpp +777 -0
- package/external/folly/folly/String.h +767 -0
- package/external/folly/folly/Subprocess.cpp +1142 -0
- package/external/folly/folly/Subprocess.h +1055 -0
- package/external/folly/folly/Synchronized.h +1833 -0
- package/external/folly/folly/SynchronizedPtr.h +106 -0
- package/external/folly/folly/ThreadCachedInt.h +175 -0
- package/external/folly/folly/ThreadLocal.h +478 -0
- package/external/folly/folly/TimeoutQueue.cpp +78 -0
- package/external/folly/folly/TimeoutQueue.h +123 -0
- package/external/folly/folly/TokenBucket.h +673 -0
- package/external/folly/folly/Traits.h +1442 -0
- package/external/folly/folly/Try-inl.h +372 -0
- package/external/folly/folly/Try.cpp +23 -0
- package/external/folly/folly/Try.h +728 -0
- package/external/folly/folly/UTF8String.h +56 -0
- package/external/folly/folly/Unicode.cpp +201 -0
- package/external/folly/folly/Unicode.h +94 -0
- package/external/folly/folly/Unit.h +65 -0
- package/external/folly/folly/Uri-inl.h +101 -0
- package/external/folly/folly/Uri.cpp +190 -0
- package/external/folly/folly/Uri.h +142 -0
- package/external/folly/folly/Utility.h +932 -0
- package/external/folly/folly/VERSION +1 -0
- package/external/folly/folly/Varint.h +230 -0
- package/external/folly/folly/VirtualExecutor.h +17 -0
- package/external/folly/folly/algorithm/simd/BUCK +47 -0
- package/external/folly/folly/algorithm/simd/Contains.cpp +42 -0
- package/external/folly/folly/algorithm/simd/Contains.h +116 -0
- package/external/folly/folly/algorithm/simd/FindFixed.h +301 -0
- package/external/folly/folly/algorithm/simd/Ignore.h +52 -0
- package/external/folly/folly/algorithm/simd/Movemask.h +207 -0
- package/external/folly/folly/algorithm/simd/detail/BUCK +70 -0
- package/external/folly/folly/algorithm/simd/detail/ContainsImpl.h +91 -0
- package/external/folly/folly/algorithm/simd/detail/SimdAnyOf.h +83 -0
- package/external/folly/folly/algorithm/simd/detail/SimdForEach.h +209 -0
- package/external/folly/folly/algorithm/simd/detail/SimdPlatform.h +445 -0
- package/external/folly/folly/algorithm/simd/detail/Traits.h +125 -0
- package/external/folly/folly/algorithm/simd/detail/UnrollUtils.h +126 -0
- package/external/folly/folly/base64.h +264 -0
- package/external/folly/folly/chrono/BUCK +29 -0
- package/external/folly/folly/chrono/Clock.h +65 -0
- package/external/folly/folly/chrono/Conv.h +712 -0
- package/external/folly/folly/chrono/test/BUCK +26 -0
- package/external/folly/folly/chrono/test/ClockTest.cpp +68 -0
- package/external/folly/folly/chrono/test/ConvTest.cpp +652 -0
- package/external/folly/folly/concurrency/AtomicSharedPtr.h +387 -0
- package/external/folly/folly/concurrency/BUCK +170 -0
- package/external/folly/folly/concurrency/CacheLocality.h +460 -0
- package/external/folly/folly/concurrency/ConcurrentHashMap.h +822 -0
- package/external/folly/folly/concurrency/CoreCachedSharedPtr.h +232 -0
- package/external/folly/folly/concurrency/DeadlockDetector.cpp +27 -0
- package/external/folly/folly/concurrency/DeadlockDetector.h +44 -0
- package/external/folly/folly/concurrency/DynamicBoundedQueue.h +751 -0
- package/external/folly/folly/concurrency/PriorityUnboundedQueueSet.h +207 -0
- package/external/folly/folly/concurrency/ProcessLocalUniqueId.cpp +46 -0
- package/external/folly/folly/concurrency/ProcessLocalUniqueId.h +38 -0
- package/external/folly/folly/concurrency/SingletonRelaxedCounter.h +325 -0
- package/external/folly/folly/concurrency/ThreadCachedSynchronized.h +227 -0
- package/external/folly/folly/concurrency/UnboundedQueue.h +891 -0
- package/external/folly/folly/concurrency/container/BUCK +77 -0
- package/external/folly/folly/concurrency/container/FlatCombiningPriorityQueue.h +426 -0
- package/external/folly/folly/concurrency/container/LockFreeRingBuffer.h +306 -0
- package/external/folly/folly/concurrency/container/RelaxedConcurrentPriorityQueue.h +1212 -0
- package/external/folly/folly/concurrency/container/SingleWriterFixedHashMap.h +322 -0
- package/external/folly/folly/concurrency/container/atomic_grow_array.h +564 -0
- package/external/folly/folly/concurrency/container/test/BUCK +75 -0
- package/external/folly/folly/concurrency/container/test/FlatCombiningPriorityQueueTest.cpp +570 -0
- package/external/folly/folly/concurrency/container/test/LockFreeRingBufferTest.cpp +276 -0
- package/external/folly/folly/concurrency/container/test/RelaxedConcurrentPriorityQueueTest.cpp +1570 -0
- package/external/folly/folly/concurrency/container/test/SingleWriterFixedHashMapTest.cpp +401 -0
- package/external/folly/folly/concurrency/container/test/atomic_grow_array_test.cpp +187 -0
- package/external/folly/folly/concurrency/detail/AtomicSharedPtr-detail.h +212 -0
- package/external/folly/folly/concurrency/detail/ConcurrentHashMap-detail.h +1911 -0
- package/external/folly/folly/concurrency/memory/AtomicReadMostlyMainPtr.cpp +43 -0
- package/external/folly/folly/concurrency/memory/AtomicReadMostlyMainPtr.h +190 -0
- package/external/folly/folly/concurrency/memory/BUCK +53 -0
- package/external/folly/folly/concurrency/memory/PrimaryPtr.h +338 -0
- package/external/folly/folly/concurrency/memory/ReadMostlySharedPtr.h +511 -0
- package/external/folly/folly/concurrency/memory/TLRefCount.h +228 -0
- package/external/folly/folly/concurrency/memory/test/AtomicReadMostlyMainPtrBenchmark.cpp +56 -0
- package/external/folly/folly/concurrency/memory/test/AtomicReadMostlyMainPtrTest.cpp +454 -0
- package/external/folly/folly/concurrency/memory/test/BUCK +95 -0
- package/external/folly/folly/concurrency/memory/test/PrimaryPtrTest.cpp +303 -0
- package/external/folly/folly/concurrency/memory/test/ReadMostlySharedPtrBenchmark.cpp +138 -0
- package/external/folly/folly/concurrency/memory/test/ReadMostlySharedPtrStressTest.cpp +75 -0
- package/external/folly/folly/concurrency/memory/test/ReadMostlySharedPtrTest.cpp +378 -0
- package/external/folly/folly/concurrency/memory/test/RefCountBenchmark.cpp +90 -0
- package/external/folly/folly/concurrency/memory/test/RefCountTest.cpp +168 -0
- package/external/folly/folly/concurrency/test/AtomicSharedPtrCounted.h +156 -0
- package/external/folly/folly/concurrency/test/AtomicSharedPtrPerformance.cpp +255 -0
- package/external/folly/folly/concurrency/test/AtomicSharedPtrTest.cpp +257 -0
- package/external/folly/folly/concurrency/test/BUCK +229 -0
- package/external/folly/folly/concurrency/test/CacheLocalityBenchmark.cpp +392 -0
- package/external/folly/folly/concurrency/test/CacheLocalityTest.cpp +1229 -0
- package/external/folly/folly/concurrency/test/ConcurrentHashMapBench.cpp +260 -0
- package/external/folly/folly/concurrency/test/ConcurrentHashMapTest.cpp +1242 -0
- package/external/folly/folly/concurrency/test/CoreCachedSharedPtrTest.cpp +408 -0
- package/external/folly/folly/concurrency/test/DynamicBoundedQueueTest.cpp +984 -0
- package/external/folly/folly/concurrency/test/PriorityUnboundedQueueSetTest.cpp +73 -0
- package/external/folly/folly/concurrency/test/ProcessLocalUniqueIdTest.cpp +66 -0
- package/external/folly/folly/concurrency/test/SingletonRelaxedCounterBench.cpp +101 -0
- package/external/folly/folly/concurrency/test/SingletonRelaxedCounterTest.cpp +185 -0
- package/external/folly/folly/concurrency/test/ThreadCachedSynchronizedBench.cpp +76 -0
- package/external/folly/folly/concurrency/test/ThreadCachedSynchronizedTest.cpp +93 -0
- package/external/folly/folly/concurrency/test/UnboundedQueueTest.cpp +1302 -0
- package/external/folly/folly/container/Access.h +57 -0
- package/external/folly/folly/container/Array.h +87 -0
- package/external/folly/folly/container/BUCK +353 -0
- package/external/folly/folly/container/BitIterator.h +203 -0
- package/external/folly/folly/container/Enumerate.h +162 -0
- package/external/folly/folly/container/EvictingCacheMap.h +730 -0
- package/external/folly/folly/container/F14.md +300 -0
- package/external/folly/folly/container/F14Map-fwd.h +113 -0
- package/external/folly/folly/container/F14Map.h +2108 -0
- package/external/folly/folly/container/F14Set-fwd.h +95 -0
- package/external/folly/folly/container/F14Set.h +1603 -0
- package/external/folly/folly/container/FBVector.h +1711 -0
- package/external/folly/folly/container/Foreach-inl.h +316 -0
- package/external/folly/folly/container/Foreach.h +209 -0
- package/external/folly/folly/container/HeterogeneousAccess-fwd.h +33 -0
- package/external/folly/folly/container/HeterogeneousAccess.h +171 -0
- package/external/folly/folly/container/IntrusiveHeap.h +268 -0
- package/external/folly/folly/container/IntrusiveList.h +131 -0
- package/external/folly/folly/container/Iterator.h +843 -0
- package/external/folly/folly/container/MapUtil.h +376 -0
- package/external/folly/folly/container/Merge.h +90 -0
- package/external/folly/folly/container/RegexMatchCache.cpp +521 -0
- package/external/folly/folly/container/RegexMatchCache.h +699 -0
- package/external/folly/folly/container/Reserve.h +109 -0
- package/external/folly/folly/container/SparseByteSet.h +123 -0
- package/external/folly/folly/container/View.h +81 -0
- package/external/folly/folly/container/WeightedEvictingCacheMap.h +651 -0
- package/external/folly/folly/container/detail/BUCK +115 -0
- package/external/folly/folly/container/detail/BitIteratorDetail.h +87 -0
- package/external/folly/folly/container/detail/F14Defaults.h +34 -0
- package/external/folly/folly/container/detail/F14IntrinsicsAvailability.h +67 -0
- package/external/folly/folly/container/detail/F14MapFallback.h +717 -0
- package/external/folly/folly/container/detail/F14Mask.h +235 -0
- package/external/folly/folly/container/detail/F14Policy.h +1523 -0
- package/external/folly/folly/container/detail/F14SetFallback.h +528 -0
- package/external/folly/folly/container/detail/F14Table.cpp +71 -0
- package/external/folly/folly/container/detail/F14Table.h +2680 -0
- package/external/folly/folly/container/detail/Util.h +303 -0
- package/external/folly/folly/container/detail/tape_detail.h +135 -0
- package/external/folly/folly/container/detail/test/BUCK +14 -0
- package/external/folly/folly/container/detail/test/F14DetailTest.cpp +47 -0
- package/external/folly/folly/container/heap_vector_types.h +1683 -0
- package/external/folly/folly/container/range_traits.h +81 -0
- package/external/folly/folly/container/small_vector.h +1476 -0
- package/external/folly/folly/container/sorted_vector_types.h +1652 -0
- package/external/folly/folly/container/span.h +408 -0
- package/external/folly/folly/container/tape.h +608 -0
- package/external/folly/folly/container/test/.clang-tidy +12 -0
- package/external/folly/folly/container/test/AccessTest.cpp +138 -0
- package/external/folly/folly/container/test/ArrayTest.cpp +84 -0
- package/external/folly/folly/container/test/BUCK +568 -0
- package/external/folly/folly/container/test/BitIteratorBench.cpp +112 -0
- package/external/folly/folly/container/test/BitIteratorTest.cpp +109 -0
- package/external/folly/folly/container/test/EnumerateTest.cpp +294 -0
- package/external/folly/folly/container/test/EvictingCacheMapBench.cpp +80 -0
- package/external/folly/folly/container/test/EvictingCacheMapTest.cpp +842 -0
- package/external/folly/folly/container/test/F14AsanSupportTest.cpp +143 -0
- package/external/folly/folly/container/test/F14FwdTest.cpp +37 -0
- package/external/folly/folly/container/test/F14InterprocessTest.cpp +404 -0
- package/external/folly/folly/container/test/F14MapTest.cpp +2543 -0
- package/external/folly/folly/container/test/F14PolicyTest.cpp +49 -0
- package/external/folly/folly/container/test/F14SetTest.cpp +1738 -0
- package/external/folly/folly/container/test/F14SmallOverheads.cpp +215 -0
- package/external/folly/folly/container/test/F14TestUtil.h +117 -0
- package/external/folly/folly/container/test/FBVectorBenchmark.cpp +380 -0
- package/external/folly/folly/container/test/FBVectorBenchmarks.cpp.h +100 -0
- package/external/folly/folly/container/test/FBVectorTest.cpp +326 -0
- package/external/folly/folly/container/test/FBVectorTests.cpp.h +304 -0
- package/external/folly/folly/container/test/ForeachBenchmark.cpp +388 -0
- package/external/folly/folly/container/test/ForeachTest.cpp +338 -0
- package/external/folly/folly/container/test/HashMapsBench.cpp +458 -0
- package/external/folly/folly/container/test/HeterogeneousAccessTest.cpp +242 -0
- package/external/folly/folly/container/test/IntrusiveHeapTest.cpp +262 -0
- package/external/folly/folly/container/test/IteratorTest.cpp +989 -0
- package/external/folly/folly/container/test/MapUtilTest.cpp +365 -0
- package/external/folly/folly/container/test/MergeTest.cpp +66 -0
- package/external/folly/folly/container/test/RegexMatchCacheTest.cpp +634 -0
- package/external/folly/folly/container/test/ReserveTest.cpp +173 -0
- package/external/folly/folly/container/test/SparseByteSetBenchmark.cpp +153 -0
- package/external/folly/folly/container/test/SparseByteSetTest.cpp +117 -0
- package/external/folly/folly/container/test/TrackingTypes.h +584 -0
- package/external/folly/folly/container/test/UtilTest.cpp +609 -0
- package/external/folly/folly/container/test/WeightedEvictingCacheMapTest.cpp +800 -0
- package/external/folly/folly/container/test/heap_vector_types_test.cpp +1774 -0
- package/external/folly/folly/container/test/range_traits_test.cpp +59 -0
- package/external/folly/folly/container/test/small_vector_test.cpp +1571 -0
- package/external/folly/folly/container/test/sorted_vector_test.cpp +1589 -0
- package/external/folly/folly/container/test/span_test.cpp +520 -0
- package/external/folly/folly/container/test/tape_bench.cpp +200 -0
- package/external/folly/folly/container/test/tape_test.cpp +590 -0
- package/external/folly/folly/defs.bzl +238 -0
- package/external/folly/folly/detail/AsyncTrace.cpp +36 -0
- package/external/folly/folly/detail/AsyncTrace.h +44 -0
- package/external/folly/folly/detail/AtomicHashUtils.h +42 -0
- package/external/folly/folly/detail/AtomicUnorderedMapUtils.h +80 -0
- package/external/folly/folly/detail/BUCK +406 -0
- package/external/folly/folly/detail/DiscriminatedPtrDetail.h +172 -0
- package/external/folly/folly/detail/FileUtilDetail.cpp +63 -0
- package/external/folly/folly/detail/FileUtilDetail.h +85 -0
- package/external/folly/folly/detail/FileUtilVectorDetail.h +81 -0
- package/external/folly/folly/detail/FingerprintPolynomial.h +132 -0
- package/external/folly/folly/detail/Futex-inl.h +123 -0
- package/external/folly/folly/detail/Futex.cpp +273 -0
- package/external/folly/folly/detail/Futex.h +109 -0
- package/external/folly/folly/detail/GroupVarintDetail.h +101 -0
- package/external/folly/folly/detail/IPAddress.cpp +37 -0
- package/external/folly/folly/detail/IPAddress.h +57 -0
- package/external/folly/folly/detail/IPAddressSource.h +278 -0
- package/external/folly/folly/detail/Iterators.h +156 -0
- package/external/folly/folly/detail/MPMCPipelineDetail.h +122 -0
- package/external/folly/folly/detail/MemoryIdler.cpp +233 -0
- package/external/folly/folly/detail/MemoryIdler.h +216 -0
- package/external/folly/folly/detail/PerfScoped.cpp +112 -0
- package/external/folly/folly/detail/PerfScoped.h +70 -0
- package/external/folly/folly/detail/PolyDetail.h +921 -0
- package/external/folly/folly/detail/RangeCommon.cpp +55 -0
- package/external/folly/folly/detail/RangeCommon.h +93 -0
- package/external/folly/folly/detail/RangeSse42.cpp +198 -0
- package/external/folly/folly/detail/RangeSse42.h +30 -0
- package/external/folly/folly/detail/SimpleSimdStringUtils.cpp +31 -0
- package/external/folly/folly/detail/SimpleSimdStringUtils.h +27 -0
- package/external/folly/folly/detail/SimpleSimdStringUtilsImpl.h +63 -0
- package/external/folly/folly/detail/Singleton.h +34 -0
- package/external/folly/folly/detail/SlowFingerprint.h +90 -0
- package/external/folly/folly/detail/SocketFastOpen.cpp +175 -0
- package/external/folly/folly/detail/SocketFastOpen.h +89 -0
- package/external/folly/folly/detail/SplitStringSimd.cpp +84 -0
- package/external/folly/folly/detail/SplitStringSimd.h +151 -0
- package/external/folly/folly/detail/SplitStringSimdImpl.h +149 -0
- package/external/folly/folly/detail/Sse.cpp +35 -0
- package/external/folly/folly/detail/Sse.h +45 -0
- package/external/folly/folly/detail/StaticSingletonManager.cpp +119 -0
- package/external/folly/folly/detail/StaticSingletonManager.h +298 -0
- package/external/folly/folly/detail/ThreadLocalDetail.cpp +492 -0
- package/external/folly/folly/detail/ThreadLocalDetail.h +800 -0
- package/external/folly/folly/detail/TrapOnAvx512.cpp +41 -0
- package/external/folly/folly/detail/TrapOnAvx512.h +21 -0
- package/external/folly/folly/detail/TurnSequencer.h +295 -0
- package/external/folly/folly/detail/TypeList.h +551 -0
- package/external/folly/folly/detail/UniqueInstance.cpp +136 -0
- package/external/folly/folly/detail/UniqueInstance.h +68 -0
- package/external/folly/folly/detail/base64_detail/BUCK +102 -0
- package/external/folly/folly/detail/base64_detail/Base64Api.cpp +40 -0
- package/external/folly/folly/detail/base64_detail/Base64Api.h +101 -0
- package/external/folly/folly/detail/base64_detail/Base64Common.h +80 -0
- package/external/folly/folly/detail/base64_detail/Base64Constants.h +79 -0
- package/external/folly/folly/detail/base64_detail/Base64HiddenConstants.h +129 -0
- package/external/folly/folly/detail/base64_detail/Base64SWAR.cpp +161 -0
- package/external/folly/folly/detail/base64_detail/Base64SWAR.h +32 -0
- package/external/folly/folly/detail/base64_detail/Base64Scalar.h +262 -0
- package/external/folly/folly/detail/base64_detail/Base64Simd.h +102 -0
- package/external/folly/folly/detail/base64_detail/Base64_SSE4_2.cpp +42 -0
- package/external/folly/folly/detail/base64_detail/Base64_SSE4_2.h +33 -0
- package/external/folly/folly/detail/base64_detail/Base64_SSE4_2_Platform.h +167 -0
- package/external/folly/folly/detail/base64_detail/README.md +392 -0
- package/external/folly/folly/detail/base64_detail/tests/BUCK +36 -0
- package/external/folly/folly/detail/base64_detail/tests/Base64AgainstScalarTest.cpp +141 -0
- package/external/folly/folly/detail/base64_detail/tests/Base64PlatformTest.cpp +273 -0
- package/external/folly/folly/detail/base64_detail/tests/Base64SpecialCasesTest.cpp +555 -0
- package/external/folly/folly/detail/test/AsyncTraceTest.cpp +43 -0
- package/external/folly/folly/detail/test/BUCK +118 -0
- package/external/folly/folly/detail/test/FileUtilDetailTest.cpp +56 -0
- package/external/folly/folly/detail/test/PerfScopedTest.cpp +107 -0
- package/external/folly/folly/detail/test/SimpleSimdStringUtilsTest.cpp +92 -0
- package/external/folly/folly/detail/test/SplitStringSimdTest.cpp +242 -0
- package/external/folly/folly/detail/test/StaticSingletonManagerTest.cpp +121 -0
- package/external/folly/folly/detail/test/ThreadLocalBenchmark.cpp +116 -0
- package/external/folly/folly/detail/test/ThreadLocalDetailTest.cpp +194 -0
- package/external/folly/folly/detail/test/TrapOnAvx512TestNegative.cpp +29 -0
- package/external/folly/folly/detail/test/UniqueInstanceTest.cpp +60 -0
- package/external/folly/folly/detail/thread_local_globals.cpp +69 -0
- package/external/folly/folly/detail/thread_local_globals.h +36 -0
- package/external/folly/folly/docs/AtomicHashMap.md +134 -0
- package/external/folly/folly/docs/Benchmark.md +310 -0
- package/external/folly/folly/docs/Conv.md +291 -0
- package/external/folly/folly/docs/Dynamic.md +220 -0
- package/external/folly/folly/docs/DynamicConverter.md +71 -0
- package/external/folly/folly/docs/Executors.md +63 -0
- package/external/folly/folly/docs/FBString.md +46 -0
- package/external/folly/folly/docs/FBVector.md +200 -0
- package/external/folly/folly/docs/Fbvector--graphical_solutions.png +0 -0
- package/external/folly/folly/docs/Format.md +177 -0
- package/external/folly/folly/docs/Function.md +92 -0
- package/external/folly/folly/docs/Futures.md +263 -0
- package/external/folly/folly/docs/GroupVarint.md +46 -0
- package/external/folly/folly/docs/Histogram.md +104 -0
- package/external/folly/folly/docs/MapUtils.md +80 -0
- package/external/folly/folly/docs/Overview.md +263 -0
- package/external/folly/folly/docs/PackedSyncPtr.md +77 -0
- package/external/folly/folly/docs/Poly.md +500 -0
- package/external/folly/folly/docs/ProducerConsumerQueue.md +82 -0
- package/external/folly/folly/docs/Rcu.md +218 -0
- package/external/folly/folly/docs/SmallLocks.md +24 -0
- package/external/folly/folly/docs/Synchronized.md +793 -0
- package/external/folly/folly/docs/ThreadCachedInt.md +98 -0
- package/external/folly/folly/docs/ThreadLocal.md +105 -0
- package/external/folly/folly/docs/Traits.md +161 -0
- package/external/folly/folly/docs/small_vector.md +64 -0
- package/external/folly/folly/docs/style.css +23 -0
- package/external/folly/folly/dynamic-inl.h +17 -0
- package/external/folly/folly/dynamic.h +17 -0
- package/external/folly/folly/folly_extended_library.bzl +28 -0
- package/external/folly/folly/functional/ApplyTuple.h +204 -0
- package/external/folly/folly/functional/BUCK +57 -0
- package/external/folly/folly/functional/Invoke.h +880 -0
- package/external/folly/folly/functional/Partial.h +130 -0
- package/external/folly/folly/functional/protocol.h +203 -0
- package/external/folly/folly/functional/test/ApplyTupleTest.cpp +549 -0
- package/external/folly/folly/functional/test/BUCK +57 -0
- package/external/folly/folly/functional/test/InvokeTest.cpp +483 -0
- package/external/folly/folly/functional/test/PartialTest.cpp +141 -0
- package/external/folly/folly/functional/test/protocol_test.cpp +177 -0
- package/external/folly/folly/functional/test/traits_test.cpp +551 -0
- package/external/folly/folly/functional/traits.h +675 -0
- package/external/folly/folly/hash/BUCK +86 -0
- package/external/folly/folly/hash/Checksum.cpp +275 -0
- package/external/folly/folly/hash/Checksum.h +94 -0
- package/external/folly/folly/hash/FarmHash.h +46 -0
- package/external/folly/folly/hash/Hash.h +1045 -0
- package/external/folly/folly/hash/MurmurHash.h +86 -0
- package/external/folly/folly/hash/SpookyHashV1.cpp +391 -0
- package/external/folly/folly/hash/SpookyHashV1.h +307 -0
- package/external/folly/folly/hash/SpookyHashV2.cpp +392 -0
- package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/hash/SpookyHashV2.h +6 -1
- package/external/folly/folly/hash/detail/BUCK +26 -0
- package/external/folly/folly/hash/detail/ChecksumDetail.cpp +296 -0
- package/external/folly/folly/hash/detail/ChecksumDetail.h +137 -0
- package/external/folly/folly/hash/detail/Crc32CombineDetail.cpp +191 -0
- package/external/folly/folly/hash/detail/Crc32cDetail.cpp +303 -0
- package/external/folly/folly/hash/test/BUCK +132 -0
- package/external/folly/folly/hash/test/ChecksumBenchmark.cpp +91 -0
- package/external/folly/folly/hash/test/ChecksumTest.cpp +587 -0
- package/external/folly/folly/hash/test/FarmHashTest.cpp +41 -0
- package/external/folly/folly/hash/test/HashBenchmark.cpp +238 -0
- package/external/folly/folly/hash/test/HashTest.cpp +997 -0
- package/external/folly/folly/hash/test/MurmurHashTest.cpp +76 -0
- package/external/folly/folly/hash/test/SpookyHashV1Test.cpp +559 -0
- package/external/folly/folly/hash/test/SpookyHashV2Test.cpp +549 -0
- package/external/folly/folly/hash/test/traits_test.cpp +69 -0
- package/external/folly/folly/hash/traits.h +115 -0
- package/external/folly/folly/json/BUCK +155 -0
- package/external/folly/folly/json/DynamicConverter.h +464 -0
- package/external/folly/folly/json/DynamicParser-inl.h +316 -0
- package/external/folly/folly/json/DynamicParser.cpp +198 -0
- package/external/folly/folly/json/DynamicParser.h +394 -0
- package/external/folly/folly/json/JSONSchema.cpp +1030 -0
- package/external/folly/folly/json/JSONSchema.h +73 -0
- package/external/folly/folly/json/JsonMockUtil.h +73 -0
- package/external/folly/folly/json/JsonTestUtil.cpp +167 -0
- package/external/folly/folly/json/JsonTestUtil.h +88 -0
- package/external/folly/folly/json/bser/BUCK +24 -0
- package/external/folly/folly/json/bser/Bser.h +107 -0
- package/external/folly/folly/json/bser/Dump.cpp +253 -0
- package/external/folly/folly/json/bser/Load.cpp +246 -0
- package/external/folly/folly/json/bser/test/BUCK +14 -0
- package/external/folly/folly/json/bser/test/BserTest.cpp +149 -0
- package/external/folly/folly/json/dynamic.cpp +552 -0
- package/external/folly/folly/json/dynamic.h +1346 -0
- package/external/folly/folly/json/json.h +238 -0
- package/external/folly/folly/json/json_patch.cpp +325 -0
- package/external/folly/folly/json/json_patch.h +126 -0
- package/external/folly/folly/json/json_pointer.cpp +114 -0
- package/external/folly/folly/json/json_pointer.h +87 -0
- package/external/folly/folly/json/test/BUCK +147 -0
- package/external/folly/folly/json/test/DynamicBenchmark.cpp +146 -0
- package/external/folly/folly/json/test/DynamicConverterTest.cpp +518 -0
- package/external/folly/folly/json/test/DynamicOtherTest.cpp +344 -0
- package/external/folly/folly/json/test/DynamicParserTest.cpp +443 -0
- package/external/folly/folly/json/test/DynamicTest.cpp +1647 -0
- package/external/folly/folly/json/test/JSONSchemaTest.cpp +450 -0
- package/external/folly/folly/json/test/JsonBenchmark.cpp +264 -0
- package/external/folly/folly/json/test/JsonOtherTest.cpp +51 -0
- package/external/folly/folly/json/test/JsonTest.cpp +1153 -0
- package/external/folly/folly/json/test/JsonTestUtilTest.cpp +97 -0
- package/external/folly/folly/json/test/json_patch_test.cpp +361 -0
- package/external/folly/folly/json/test/json_pointer_test.cpp +58 -0
- package/external/folly/folly/json/tool/BUCK +13 -0
- package/external/folly/folly/json/tool/JSONSchemaTester.cpp +58 -0
- package/external/folly/folly/json.h +17 -0
- package/external/folly/folly/json_patch.h +17 -0
- package/external/folly/folly/json_pointer.h +17 -0
- package/external/folly/folly/lang/Access.h +29 -0
- package/external/folly/folly/lang/Align.h +240 -0
- package/external/folly/folly/lang/Aligned.h +92 -0
- package/external/folly/folly/lang/Assume.h +82 -0
- package/external/folly/folly/lang/BUCK +287 -0
- package/external/folly/folly/lang/Badge.h +108 -0
- package/external/folly/folly/lang/Bits.h +570 -0
- package/external/folly/folly/lang/BitsClass.h +312 -0
- package/external/folly/folly/lang/Builtin.h +74 -0
- package/external/folly/folly/lang/CArray.h +34 -0
- package/external/folly/folly/lang/CString.cpp +86 -0
- package/external/folly/folly/lang/CString.h +55 -0
- package/external/folly/folly/lang/Cast.h +51 -0
- package/external/folly/folly/lang/CheckedMath.h +253 -0
- package/external/folly/folly/lang/CustomizationPoint.h +58 -0
- package/external/folly/folly/lang/Exception.cpp +822 -0
- package/external/folly/folly/lang/Exception.h +716 -0
- package/external/folly/folly/lang/Extern.h +55 -0
- package/external/folly/folly/lang/Hint-inl.h +144 -0
- package/external/folly/folly/lang/Hint.h +238 -0
- package/external/folly/folly/lang/Keep.h +98 -0
- package/external/folly/folly/lang/New.h +124 -0
- package/external/folly/folly/lang/Ordering.h +140 -0
- package/external/folly/folly/lang/Pretty.h +159 -0
- package/external/folly/folly/lang/PropagateConst.h +413 -0
- package/external/folly/folly/lang/RValueReferenceWrapper.h +152 -0
- package/external/folly/folly/lang/SafeAssert.cpp +589 -0
- package/external/folly/folly/lang/StaticConst.h +33 -0
- package/external/folly/folly/lang/Thunk.h +100 -0
- package/external/folly/folly/lang/TypeInfo.h +58 -0
- package/external/folly/folly/lang/UncaughtExceptions.cpp +17 -0
- package/external/folly/folly/lang/UncaughtExceptions.h +19 -0
- package/external/folly/folly/lang/test/AlignTest.cpp +87 -0
- package/external/folly/folly/lang/test/AlignedTest.cpp +130 -0
- package/external/folly/folly/lang/test/BUCK +258 -0
- package/external/folly/folly/lang/test/BadgeTest.cpp +89 -0
- package/external/folly/folly/lang/test/BitsBenchmark.cpp +164 -0
- package/external/folly/folly/lang/test/BitsClassBenchmark.cpp +122 -0
- package/external/folly/folly/lang/test/BitsClassTest.cpp +379 -0
- package/external/folly/folly/lang/test/BitsTest.cpp +577 -0
- package/external/folly/folly/lang/test/CStringTest.cpp +60 -0
- package/external/folly/folly/lang/test/CastTest.cpp +47 -0
- package/external/folly/folly/lang/test/CheckedMathTest.cpp +394 -0
- package/external/folly/folly/lang/test/ExceptionBench.cpp +427 -0
- package/external/folly/folly/lang/test/ExceptionTest.cpp +413 -0
- package/external/folly/folly/lang/test/ExternTest.cpp +39 -0
- package/external/folly/folly/lang/test/HintTest.cpp +100 -0
- package/external/folly/folly/lang/test/NewTest.cpp +38 -0
- package/external/folly/folly/lang/test/OrderingTest.cpp +105 -0
- package/external/folly/folly/lang/test/PrettyTest.cpp +44 -0
- package/external/folly/folly/lang/test/PropagateConstTest.cpp +356 -0
- package/external/folly/folly/lang/test/RValueReferenceWrapperTest.cpp +85 -0
- package/external/folly/folly/lang/test/SafeAssertTest.cpp +75 -0
- package/external/folly/folly/lang/test/ThunkTest.cpp +105 -0
- package/external/folly/folly/lang/test/ToAsciiBench.cpp +466 -0
- package/external/folly/folly/lang/test/ToAsciiTest.cpp +266 -0
- package/external/folly/folly/lang/test/TypeInfoTest.cpp +56 -0
- package/external/folly/folly/memcpy.S +292 -0
- package/external/folly/folly/memcpy_select_aarch64.cpp +145 -0
- package/external/folly/folly/memory/Arena-inl.h +83 -0
- package/external/folly/folly/memory/Arena.h +325 -0
- package/external/folly/folly/memory/BUCK +191 -0
- package/external/folly/folly/memory/JemallocHugePageAllocator.cpp +449 -0
- package/external/folly/folly/memory/JemallocHugePageAllocator.h +105 -0
- package/external/folly/folly/memory/JemallocHugePageAllocatorTest.cpp +341 -0
- package/external/folly/folly/memory/JemallocNodumpAllocator.cpp +176 -0
- package/external/folly/folly/memory/JemallocNodumpAllocator.h +119 -0
- package/external/folly/folly/memory/JemallocNodumpAllocatorTest.cpp +61 -0
- package/external/folly/folly/memory/MallctlHelper.cpp +37 -0
- package/external/folly/folly/memory/MallctlHelper.h +167 -0
- package/external/folly/folly/memory/Malloc.h +551 -0
- package/external/folly/folly/memory/MemoryResource.h +57 -0
- package/external/folly/folly/memory/ReentrantAllocator.cpp +162 -0
- package/external/folly/folly/memory/ReentrantAllocator.h +261 -0
- package/external/folly/folly/memory/SanitizeAddress.cpp +75 -0
- package/external/folly/folly/memory/SanitizeAddress.h +117 -0
- package/external/folly/folly/memory/SanitizeLeak.cpp +119 -0
- package/external/folly/folly/memory/SanitizeLeak.h +108 -0
- package/external/folly/folly/memory/ThreadCachedArena.cpp +53 -0
- package/external/folly/folly/memory/ThreadCachedArena.h +90 -0
- package/external/folly/folly/memory/UninitializedMemoryHacks.h +426 -0
- package/external/folly/folly/memory/detail/BUCK +10 -0
- package/external/folly/folly/memory/detail/MallocImpl.cpp +52 -0
- package/external/folly/folly/memory/detail/MallocImpl.h +97 -0
- package/external/folly/folly/memory/not_null-inl.h +522 -0
- package/external/folly/folly/memory/not_null.h +449 -0
- package/external/folly/folly/memory/test/ArenaTest.cpp +354 -0
- package/external/folly/folly/memory/test/BUCK +146 -0
- package/external/folly/folly/memory/test/MallctlHelperTest.cpp +169 -0
- package/external/folly/folly/memory/test/MallocBenchmark.cpp +91 -0
- package/external/folly/folly/memory/test/MallocTest.cpp +78 -0
- package/external/folly/folly/memory/test/MemoryResourceTest.cpp +31 -0
- package/external/folly/folly/memory/test/ReentrantAllocatorTest.cpp +144 -0
- package/external/folly/folly/memory/test/SanitizeAddressTest.cpp +67 -0
- package/external/folly/folly/memory/test/SanitizeLeakTest.cpp +139 -0
- package/external/folly/folly/memory/test/ThreadCachedArenaTest.cpp +276 -0
- package/external/folly/folly/memory/test/UninitializedMemoryHacksODR.cpp +21 -0
- package/external/folly/folly/memory/test/UninitializedMemoryHacksTest.cpp +327 -0
- package/external/folly/folly/memory/test/not_null_test.cpp +608 -0
- package/external/folly/folly/memset.S +245 -0
- package/external/folly/folly/memset_select_aarch64.cpp +72 -0
- package/external/folly/folly/portability/Asm.h +50 -0
- package/external/folly/folly/portability/Atomic.h +31 -0
- package/external/folly/folly/portability/BUCK +456 -0
- package/external/folly/folly/portability/Builtins.cpp +31 -0
- package/external/folly/folly/portability/Builtins.h +161 -0
- package/external/folly/folly/portability/Config.h +43 -0
- package/external/folly/folly/portability/Constexpr.h +145 -0
- package/external/folly/folly/portability/Dirent.cpp +140 -0
- package/external/folly/folly/portability/Dirent.h +41 -0
- package/external/folly/folly/portability/Event.h +44 -0
- package/external/folly/folly/portability/Fcntl.cpp +120 -0
- package/external/folly/folly/portability/Fcntl.h +67 -0
- package/external/folly/folly/portability/Filesystem.cpp +67 -0
- package/external/folly/folly/portability/Filesystem.h +114 -0
- package/external/folly/folly/portability/FmtCompile.h +40 -0
- package/external/folly/folly/portability/GFlags.h +139 -0
- package/external/folly/folly/portability/GMock.h +35 -0
- package/external/folly/folly/portability/GTest.h +35 -0
- package/external/folly/folly/portability/IOVec.h +34 -0
- package/external/folly/folly/portability/Libgen.cpp +59 -0
- package/external/folly/folly/portability/Libgen.h +29 -0
- package/external/folly/folly/portability/Libunwind.h +21 -0
- package/external/folly/folly/portability/Malloc.cpp +31 -0
- package/external/folly/folly/portability/Malloc.h +53 -0
- package/external/folly/folly/portability/Math.h +90 -0
- package/external/folly/folly/portability/Memory.h +26 -0
- package/external/folly/folly/portability/OpenSSL.cpp +17 -0
- package/external/folly/folly/portability/OpenSSL.h +102 -0
- package/external/folly/folly/portability/PThread.cpp +697 -0
- package/external/folly/folly/portability/PThread.h +148 -0
- package/external/folly/folly/portability/README.md +21 -0
- package/external/folly/folly/portability/Sched.cpp +41 -0
- package/external/folly/folly/portability/Sched.h +45 -0
- package/external/folly/folly/portability/Sockets.cpp +245 -0
- package/external/folly/folly/portability/Sockets.h +155 -0
- package/external/folly/folly/portability/SourceLocation.h +49 -0
- package/external/folly/folly/portability/Stdio.cpp +77 -0
- package/external/folly/folly/portability/Stdio.h +32 -0
- package/external/folly/folly/portability/Stdlib.cpp +172 -0
- package/external/folly/folly/portability/Stdlib.h +64 -0
- package/external/folly/folly/portability/String.cpp +53 -0
- package/external/folly/folly/portability/String.h +39 -0
- package/external/folly/folly/portability/SysFile.cpp +46 -0
- package/external/folly/folly/portability/SysFile.h +27 -0
- package/external/folly/folly/portability/SysMembarrier.cpp +104 -0
- package/external/folly/folly/portability/SysMembarrier.h +26 -0
- package/external/folly/folly/portability/SysMman.cpp +242 -0
- package/external/folly/folly/portability/SysMman.h +68 -0
- package/external/folly/folly/portability/SysResource.cpp +108 -0
- package/external/folly/folly/portability/SysResource.h +71 -0
- package/external/folly/folly/portability/SysStat.cpp +66 -0
- package/external/folly/folly/portability/SysStat.h +52 -0
- package/external/folly/folly/portability/SysSyscall.h +73 -0
- package/external/folly/folly/portability/SysTime.cpp +62 -0
- package/external/folly/folly/portability/SysTime.h +50 -0
- package/external/folly/folly/portability/SysTypes.h +44 -0
- package/external/folly/folly/portability/SysUio.cpp +179 -0
- package/external/folly/folly/portability/SysUio.h +51 -0
- package/external/folly/folly/portability/Syslog.h +39 -0
- package/external/folly/folly/portability/Time.cpp +357 -0
- package/external/folly/folly/portability/Time.h +74 -0
- package/external/folly/folly/portability/Unistd.h +111 -0
- package/external/folly/folly/portability/Windows.h +108 -0
- package/external/folly/folly/portability/openat2.c +30 -0
- package/external/folly/folly/portability/openat2.h +39 -0
- package/external/folly/folly/portability/test/BUCK +59 -0
- package/external/folly/folly/portability/test/ConstexprTest.cpp +102 -0
- package/external/folly/folly/portability/test/FilesystemTest.cpp +35 -0
- package/external/folly/folly/portability/test/LibgenTest.cpp +35 -0
- package/external/folly/folly/portability/test/OpenSSLPortabilityTest.cpp +108 -0
- package/external/folly/folly/portability/test/PThreadTest.cpp +80 -0
- package/external/folly/folly/portability/test/TimeTest.cpp +90 -0
- package/external/folly/folly/small_vector.h +17 -0
- package/external/folly/folly/somerge_defs.bzl +399 -0
- package/external/folly/folly/sorted_vector_types.h +17 -0
- package/external/folly/folly/stop_watch.h +317 -0
- package/external/folly/folly/synchronization/AsymmetricThreadFence.cpp +91 -0
- package/external/folly/folly/synchronization/AsymmetricThreadFence.h +60 -0
- package/external/folly/folly/synchronization/AtomicNotification-inl.h +146 -0
- package/external/folly/folly/synchronization/AtomicNotification.cpp +34 -0
- package/external/folly/folly/synchronization/AtomicNotification.h +117 -0
- package/external/folly/folly/synchronization/AtomicRef.h +181 -0
- package/external/folly/folly/synchronization/AtomicStruct.h +150 -0
- package/external/folly/folly/synchronization/AtomicUtil-inl.h +482 -0
- package/external/folly/folly/synchronization/AtomicUtil.h +179 -0
- package/external/folly/folly/synchronization/BUCK +418 -0
- package/external/folly/folly/synchronization/Baton.h +419 -0
- package/external/folly/folly/synchronization/CallOnce.h +263 -0
- package/external/folly/folly/synchronization/DelayedInit.h +179 -0
- package/external/folly/folly/synchronization/DistributedMutex-inl.h +1744 -0
- package/external/folly/folly/synchronization/DistributedMutex.cpp +27 -0
- package/external/folly/folly/synchronization/DistributedMutex.h +342 -0
- package/external/folly/folly/synchronization/EventCount.h +200 -0
- package/external/folly/folly/synchronization/FlatCombining.h +629 -0
- package/external/folly/folly/synchronization/Hazptr-fwd.h +217 -0
- package/external/folly/folly/synchronization/Hazptr.cpp +36 -0
- package/external/folly/folly/synchronization/Hazptr.h +209 -0
- package/external/folly/folly/synchronization/HazptrDomain.cpp +68 -0
- package/external/folly/folly/synchronization/HazptrDomain.h +832 -0
- package/external/folly/folly/synchronization/HazptrHolder.h +431 -0
- package/external/folly/folly/synchronization/HazptrObj.h +533 -0
- package/external/folly/folly/synchronization/HazptrObjLinked.h +315 -0
- package/external/folly/folly/synchronization/HazptrRec.h +68 -0
- package/external/folly/folly/synchronization/HazptrThrLocal.h +180 -0
- package/external/folly/folly/synchronization/HazptrThreadPoolExecutor.cpp +46 -0
- package/external/folly/folly/synchronization/HazptrThreadPoolExecutor.h +25 -0
- package/external/folly/folly/synchronization/Latch.h +160 -0
- package/external/folly/folly/synchronization/LifoSem.h +767 -0
- package/external/folly/folly/synchronization/Lock.h +887 -0
- package/external/folly/folly/synchronization/MicroSpinLock.h +154 -0
- package/external/folly/folly/synchronization/NativeSemaphore.h +187 -0
- package/external/folly/folly/synchronization/ParkingLot.cpp +37 -0
- package/external/folly/folly/synchronization/ParkingLot.h +330 -0
- package/external/folly/folly/synchronization/PicoSpinLock.h +167 -0
- package/external/folly/folly/synchronization/RWSpinLock.h +549 -0
- package/external/folly/folly/synchronization/Rcu.cpp +26 -0
- package/external/folly/folly/synchronization/Rcu.h +553 -0
- package/external/folly/folly/synchronization/RelaxedAtomic.h +336 -0
- package/external/folly/folly/synchronization/SanitizeThread.cpp +141 -0
- package/external/folly/folly/synchronization/SanitizeThread.h +166 -0
- package/external/folly/folly/synchronization/SaturatingSemaphore.h +324 -0
- package/external/folly/folly/synchronization/SmallLocks.h +36 -0
- package/external/folly/folly/synchronization/ThrottledLifoSem.h +362 -0
- package/external/folly/folly/synchronization/WaitOptions.cpp +25 -0
- package/external/folly/folly/synchronization/WaitOptions.h +75 -0
- package/external/folly/folly/synchronization/detail/AtomicUtils.h +59 -0
- package/external/folly/folly/synchronization/detail/BUCK +104 -0
- package/external/folly/folly/synchronization/detail/Hardware.cpp +192 -0
- package/external/folly/folly/synchronization/detail/Hardware.h +75 -0
- package/external/folly/folly/synchronization/detail/HazptrUtils.h +339 -0
- package/external/folly/folly/synchronization/detail/InlineFunctionRef.h +229 -0
- package/external/folly/folly/synchronization/detail/Sleeper.cpp +27 -0
- package/external/folly/folly/synchronization/detail/Sleeper.h +62 -0
- package/external/folly/folly/synchronization/detail/Spin.h +96 -0
- package/external/folly/folly/synchronization/detail/ThreadCachedLists.h +174 -0
- package/external/folly/folly/synchronization/detail/ThreadCachedReaders.h +189 -0
- package/external/folly/folly/synchronization/detail/ThreadCachedTag.h +26 -0
- package/external/folly/folly/synchronization/detail/test/BUCK +28 -0
- package/external/folly/folly/synchronization/detail/test/HardwareTest.cpp +74 -0
- package/external/folly/folly/synchronization/detail/test/InlineFunctionRefTest.cpp +286 -0
- package/external/folly/folly/synchronization/example/BUCK +27 -0
- package/external/folly/folly/synchronization/example/HazptrLockFreeLIFO.h +88 -0
- package/external/folly/folly/synchronization/example/HazptrSWMRSet.h +133 -0
- package/external/folly/folly/synchronization/example/HazptrWideCAS.h +62 -0
- package/external/folly/folly/synchronization/test/AtomicNotificationTest.cpp +236 -0
- package/external/folly/folly/synchronization/test/AtomicRefTest.cpp +170 -0
- package/external/folly/folly/synchronization/test/AtomicStructTest.cpp +65 -0
- package/external/folly/folly/synchronization/test/AtomicUtilBench.cpp +457 -0
- package/external/folly/folly/synchronization/test/AtomicUtilTest.cpp +650 -0
- package/external/folly/folly/synchronization/test/BUCK +495 -0
- package/external/folly/folly/synchronization/test/Barrier.h +52 -0
- package/external/folly/folly/synchronization/test/BarrierTest.cpp +56 -0
- package/external/folly/folly/synchronization/test/BatonBenchmark.cpp +77 -0
- package/external/folly/folly/synchronization/test/BatonTest.cpp +164 -0
- package/external/folly/folly/synchronization/test/BatonTestHelpers.h +118 -0
- package/external/folly/folly/synchronization/test/CallOnceBenchmark.cpp +72 -0
- package/external/folly/folly/synchronization/test/CallOnceTest.cpp +153 -0
- package/external/folly/folly/synchronization/test/DelayedInitTest.cpp +281 -0
- package/external/folly/folly/synchronization/test/DistributedMutexTest.cpp +2074 -0
- package/external/folly/folly/synchronization/test/EventCountTest.cpp +124 -0
- package/external/folly/folly/synchronization/test/FlatCombiningBenchmark.cpp +1789 -0
- package/external/folly/folly/synchronization/test/FlatCombiningExamples.h +222 -0
- package/external/folly/folly/synchronization/test/FlatCombiningTest.cpp +121 -0
- package/external/folly/folly/synchronization/test/FlatCombiningTestHelpers.h +227 -0
- package/external/folly/folly/synchronization/test/HazptrTest.cpp +1689 -0
- package/external/folly/folly/synchronization/test/LatchTest.cpp +224 -0
- package/external/folly/folly/synchronization/test/LifoSemBench.cpp +185 -0
- package/external/folly/folly/synchronization/test/LifoSemTests.cpp +353 -0
- package/external/folly/folly/synchronization/test/LockTest.cpp +1239 -0
- package/external/folly/folly/synchronization/test/NativeSemaphoreTest.cpp +37 -0
- package/external/folly/folly/synchronization/test/ParkingLotBenchmark.cpp +239 -0
- package/external/folly/folly/synchronization/test/ParkingLotTest.cpp +170 -0
- package/external/folly/folly/synchronization/test/RWSpinLockTest.cpp +235 -0
- package/external/folly/folly/synchronization/test/RcuBench.cpp +66 -0
- package/external/folly/folly/synchronization/test/RcuTest.cpp +330 -0
- package/external/folly/folly/synchronization/test/RelaxedAtomicTest.cpp +389 -0
- package/external/folly/folly/synchronization/test/SaturatingSemaphoreTest.cpp +166 -0
- package/external/folly/folly/synchronization/test/Semaphore.h +242 -0
- package/external/folly/folly/synchronization/test/SemaphoreTest.cpp +271 -0
- package/external/folly/folly/synchronization/test/SmallLocksBenchmark.cpp +1296 -0
- package/external/folly/folly/synchronization/test/SmallLocksTest.cpp +510 -0
- package/external/folly/folly/synchronization/test/ThreadCachedEpochBench.h +67 -0
- package/external/folly/folly/synchronization/test/ThreadCachedReadersBench.cpp +42 -0
- package/external/folly/folly/synchronization/test/ThreadCachedReadersTest.cpp +52 -0
- package/external/folly/folly/synchronization/test/ThrottledLifoSemTest.cpp +243 -0
- package/external/folly/folly/system/AtFork.cpp +205 -0
- package/external/folly/folly/system/AtFork.h +116 -0
- package/external/folly/folly/system/AuxVector.h +198 -0
- package/external/folly/folly/system/BUCK +144 -0
- package/external/folly/folly/system/EnvUtil.cpp +93 -0
- package/external/folly/folly/system/EnvUtil.h +113 -0
- package/external/folly/folly/system/HardwareConcurrency.cpp +39 -0
- package/external/folly/folly/system/HardwareConcurrency.h +23 -0
- package/external/folly/folly/system/MemoryMapping.cpp +477 -0
- package/external/folly/folly/system/MemoryMapping.h +287 -0
- package/external/folly/folly/system/Pid.cpp +87 -0
- package/external/folly/folly/system/Pid.h +34 -0
- package/external/folly/folly/system/Shell.cpp +33 -0
- package/external/folly/folly/system/Shell.h +93 -0
- package/external/folly/folly/system/ThreadId.cpp +89 -0
- package/external/folly/folly/system/ThreadId.h +62 -0
- package/external/folly/folly/system/ThreadName.cpp +330 -0
- package/external/folly/folly/system/ThreadName.h +72 -0
- package/external/folly/folly/system/test/AtForkTest.cpp +309 -0
- package/external/folly/folly/system/test/AuxVectorTest.cpp +55 -0
- package/external/folly/folly/system/test/BUCK +120 -0
- package/external/folly/folly/system/test/EnvUtilSubprocess.cpp +26 -0
- package/external/folly/folly/system/test/EnvUtilTest.cpp +197 -0
- package/external/folly/folly/system/test/MemoryMappingTest.cpp +179 -0
- package/external/folly/folly/system/test/PidTest.cpp +46 -0
- package/external/folly/folly/system/test/ShellTest.cpp +66 -0
- package/external/folly/folly/system/test/ThreadIdTest.cpp +114 -0
- package/external/folly/folly/system/test/ThreadNameTest.cpp +85 -0
- package/external/folly/folly.vcxitems +164 -0
- package/external/folly/static/logo.svg +1 -0
- package/external/folly/sync-config.json +8 -0
- package/package.json +3 -3
- package/template/cpp-app/proj/MyApp.sln +0 -33
- package/template/cpp-lib/proj/MyLib.sln +0 -33
- package/template/cs-app/proj/MyApp.sln +0 -33
- package/template/cs-lib/proj/MyLib.sln +0 -33
- package/templates/cpp-app/windows/MyApp.sln +0 -33
- package/templates/cpp-lib/example/metro.config.js +31 -6
- package/templates/cpp-lib/windows/MyLib.sln +0 -33
- package/Folly/Folly.vcxproj +0 -383
- package/Folly/Folly.vcxproj.filters +0 -558
- package/Folly/Folly.win32.vcxproj +0 -11
- package/Folly/packages.lock.win32.json +0 -20
- package/Scripts/Warm-RnwFeedCache.ps1 +0 -413
- package/fmt/fmt.vcxproj +0 -163
- package/fmt/fmt.vcxproj.filters +0 -59
- package/fmt/fmt.win32.vcxproj +0 -10
- package/fmt/pch.cpp +0 -4
- package/fmt/pch.h +0 -2
- /package/{Folly → external/folly}/Folly.natvis +0 -0
- /package/{Folly → external/folly}/cgmanifest.json +0 -0
- /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/ConstexprMath.h +0 -0
- /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/Conv.cpp +0 -0
- /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/chrono/Hardware.h +0 -0
- /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/concurrency/CacheLocality.cpp +0 -0
- /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/json/dynamic-inl.h +0 -0
- /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/json/json.cpp +0 -0
- /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/lang/SafeAssert.h +0 -0
- /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/lang/ToAscii.cpp +0 -0
- /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/lang/ToAscii.h +0 -0
- /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/portability/Unistd.cpp +0 -0
|
@@ -0,0 +1,1725 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
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
|
+
/**
|
|
18
|
+
* Like folly::Optional, but can store a value *or* an error.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#pragma once
|
|
22
|
+
|
|
23
|
+
#include <cassert>
|
|
24
|
+
#include <cstddef>
|
|
25
|
+
#include <initializer_list>
|
|
26
|
+
#include <new>
|
|
27
|
+
#include <stdexcept>
|
|
28
|
+
#include <type_traits>
|
|
29
|
+
#include <utility>
|
|
30
|
+
|
|
31
|
+
#include <folly/CPortability.h>
|
|
32
|
+
#include <folly/CppAttributes.h>
|
|
33
|
+
#include <folly/Likely.h>
|
|
34
|
+
#include <folly/Portability.h>
|
|
35
|
+
#include <folly/Preprocessor.h>
|
|
36
|
+
#include <folly/Traits.h>
|
|
37
|
+
#include <folly/Unit.h>
|
|
38
|
+
#include <folly/Utility.h>
|
|
39
|
+
#include <folly/lang/Exception.h>
|
|
40
|
+
#include <folly/lang/Hint.h>
|
|
41
|
+
|
|
42
|
+
#define FOLLY_EXPECTED_ID(X) FB_CONCATENATE(FB_CONCATENATE(Folly, X), __LINE__)
|
|
43
|
+
|
|
44
|
+
#define FOLLY_REQUIRES_IMPL(...) \
|
|
45
|
+
bool FOLLY_EXPECTED_ID(Requires) = false, \
|
|
46
|
+
typename std::enable_if< \
|
|
47
|
+
(FOLLY_EXPECTED_ID(Requires) || static_cast<bool>(__VA_ARGS__)), \
|
|
48
|
+
int>::type = 0
|
|
49
|
+
|
|
50
|
+
#define FOLLY_REQUIRES_TRAILING(...) , FOLLY_REQUIRES_IMPL(__VA_ARGS__)
|
|
51
|
+
|
|
52
|
+
#define FOLLY_REQUIRES(...) template <FOLLY_REQUIRES_IMPL(__VA_ARGS__)>
|
|
53
|
+
|
|
54
|
+
namespace folly {
|
|
55
|
+
|
|
56
|
+
namespace expected_detail {
|
|
57
|
+
namespace expected_detail_ExpectedHelper {
|
|
58
|
+
struct ExpectedHelper;
|
|
59
|
+
}
|
|
60
|
+
/* using override */ using expected_detail_ExpectedHelper::ExpectedHelper;
|
|
61
|
+
} // namespace expected_detail
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Unexpected - a helper type used to disambiguate the construction of
|
|
65
|
+
* Expected objects in the error state.
|
|
66
|
+
*/
|
|
67
|
+
template <class Error>
|
|
68
|
+
class FOLLY_NODISCARD Unexpected final {
|
|
69
|
+
template <class E>
|
|
70
|
+
friend class Unexpected;
|
|
71
|
+
template <class V, class E>
|
|
72
|
+
friend class Expected;
|
|
73
|
+
friend struct expected_detail::ExpectedHelper;
|
|
74
|
+
|
|
75
|
+
public:
|
|
76
|
+
/**
|
|
77
|
+
* Constructors
|
|
78
|
+
*/
|
|
79
|
+
Unexpected() = default;
|
|
80
|
+
Unexpected(const Unexpected&) = default;
|
|
81
|
+
Unexpected(Unexpected&&) = default;
|
|
82
|
+
Unexpected& operator=(const Unexpected&) = default;
|
|
83
|
+
Unexpected& operator=(Unexpected&&) = default;
|
|
84
|
+
[[FOLLY_ATTR_GNU_COLD]] constexpr /* implicit */ Unexpected(const Error& err)
|
|
85
|
+
: error_(err) {}
|
|
86
|
+
[[FOLLY_ATTR_GNU_COLD]] constexpr /* implicit */ Unexpected(Error&& err)
|
|
87
|
+
: error_(std::move(err)) {}
|
|
88
|
+
|
|
89
|
+
template <class Other FOLLY_REQUIRES_TRAILING(
|
|
90
|
+
std::is_constructible<Error, Other&&>::value)>
|
|
91
|
+
constexpr /* implicit */ Unexpected(Unexpected<Other> that)
|
|
92
|
+
: error_(std::move(that.error())) {}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Assignment
|
|
96
|
+
*/
|
|
97
|
+
template <class Other FOLLY_REQUIRES_TRAILING(
|
|
98
|
+
std::is_assignable<Error&, Other&&>::value)>
|
|
99
|
+
Unexpected& operator=(Unexpected<Other> that) {
|
|
100
|
+
error_ = std::move(that.error());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Observers
|
|
105
|
+
*/
|
|
106
|
+
Error& error() & { return error_; }
|
|
107
|
+
const Error& error() const& { return error_; }
|
|
108
|
+
Error&& error() && { return std::move(error_); }
|
|
109
|
+
const Error&& error() const&& { return std::move(error_); }
|
|
110
|
+
|
|
111
|
+
private:
|
|
112
|
+
Error error_;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
template <
|
|
116
|
+
class Error FOLLY_REQUIRES_TRAILING(IsEqualityComparable<Error>::value)>
|
|
117
|
+
inline bool operator==(
|
|
118
|
+
const Unexpected<Error>& lhs, const Unexpected<Error>& rhs) {
|
|
119
|
+
return lhs.error() == rhs.error();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
template <
|
|
123
|
+
class Error FOLLY_REQUIRES_TRAILING(IsEqualityComparable<Error>::value)>
|
|
124
|
+
inline bool operator!=(
|
|
125
|
+
const Unexpected<Error>& lhs, const Unexpected<Error>& rhs) {
|
|
126
|
+
return !(lhs == rhs);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* For constructing an Unexpected object from an error code. Unexpected objects
|
|
131
|
+
* are implicitly convertible to Expected object in the error state. Usage is
|
|
132
|
+
* as follows:
|
|
133
|
+
*
|
|
134
|
+
* enum class MyErrorCode { BAD_ERROR, WORSE_ERROR };
|
|
135
|
+
* Expected<int, MyErrorCode> myAPI() {
|
|
136
|
+
* int i = // ...;
|
|
137
|
+
* return i ? makeExpected<MyErrorCode>(i)
|
|
138
|
+
* : makeUnexpected(MyErrorCode::BAD_ERROR);
|
|
139
|
+
* }
|
|
140
|
+
*/
|
|
141
|
+
template <class Error>
|
|
142
|
+
constexpr Unexpected<typename std::decay<Error>::type> makeUnexpected(
|
|
143
|
+
Error&& err) {
|
|
144
|
+
return Unexpected<typename std::decay<Error>::type>{
|
|
145
|
+
static_cast<Error&&>(err)};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
template <class Error>
|
|
149
|
+
class FOLLY_EXPORT BadExpectedAccess;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A common base type for exceptions thrown by Expected when the caller
|
|
153
|
+
* erroneously requests a value.
|
|
154
|
+
*/
|
|
155
|
+
template <>
|
|
156
|
+
class FOLLY_EXPORT BadExpectedAccess<void> : public std::exception {
|
|
157
|
+
public:
|
|
158
|
+
explicit BadExpectedAccess() noexcept = default;
|
|
159
|
+
BadExpectedAccess(BadExpectedAccess const&) {}
|
|
160
|
+
BadExpectedAccess& operator=(BadExpectedAccess const&) { return *this; }
|
|
161
|
+
|
|
162
|
+
char const* what() const noexcept override { return "bad expected access"; }
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* An exception type thrown by Expected on catastrophic logic errors, i.e., when
|
|
167
|
+
* the caller tries to access the value within an Expected but when the Expected
|
|
168
|
+
* instead contains an error.
|
|
169
|
+
*/
|
|
170
|
+
template <class Error>
|
|
171
|
+
class FOLLY_EXPORT BadExpectedAccess : public BadExpectedAccess<void> {
|
|
172
|
+
public:
|
|
173
|
+
explicit BadExpectedAccess(Error error)
|
|
174
|
+
: error_{static_cast<Error&&>(error)} {}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The error code that was held by the Expected object when the caller
|
|
178
|
+
* erroneously requested the value.
|
|
179
|
+
*/
|
|
180
|
+
Error& error() & { return error_; }
|
|
181
|
+
Error const& error() const& { return error_; }
|
|
182
|
+
Error&& error() && { return static_cast<Error&&>(error_); }
|
|
183
|
+
Error const&& error() const&& { return static_cast<Error const&&>(error_); }
|
|
184
|
+
|
|
185
|
+
private:
|
|
186
|
+
Error error_;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Forward declarations
|
|
191
|
+
*/
|
|
192
|
+
template <class Value, class Error>
|
|
193
|
+
class Expected;
|
|
194
|
+
|
|
195
|
+
template <class Error, class Value>
|
|
196
|
+
FOLLY_NODISCARD constexpr Expected<typename std::decay<Value>::type, Error>
|
|
197
|
+
makeExpected(Value&&);
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Alias for an Expected type's associated value_type
|
|
201
|
+
*/
|
|
202
|
+
template <class Expected>
|
|
203
|
+
using ExpectedValueType =
|
|
204
|
+
typename std::remove_reference<Expected>::type::value_type;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Alias for an Expected type's associated error_type
|
|
208
|
+
*/
|
|
209
|
+
template <class Expected>
|
|
210
|
+
using ExpectedErrorType =
|
|
211
|
+
typename std::remove_reference<Expected>::type::error_type;
|
|
212
|
+
|
|
213
|
+
// Details...
|
|
214
|
+
namespace expected_detail {
|
|
215
|
+
|
|
216
|
+
template <typename Value, typename Error>
|
|
217
|
+
struct Promise;
|
|
218
|
+
template <typename Value, typename Error>
|
|
219
|
+
struct PromiseReturn;
|
|
220
|
+
|
|
221
|
+
template <template <class...> class Trait, class... Ts>
|
|
222
|
+
using StrictAllOf = StrictConjunction<Trait<Ts>...>;
|
|
223
|
+
|
|
224
|
+
template <class T>
|
|
225
|
+
using IsCopyable = StrictConjunction<
|
|
226
|
+
std::is_copy_constructible<T>,
|
|
227
|
+
std::is_copy_assignable<T>>;
|
|
228
|
+
|
|
229
|
+
template <class T>
|
|
230
|
+
using IsMovable = StrictConjunction<
|
|
231
|
+
std::is_move_constructible<T>,
|
|
232
|
+
std::is_move_assignable<T>>;
|
|
233
|
+
|
|
234
|
+
template <class T>
|
|
235
|
+
using IsNothrowCopyable = StrictConjunction<
|
|
236
|
+
std::is_nothrow_copy_constructible<T>,
|
|
237
|
+
std::is_nothrow_copy_assignable<T>>;
|
|
238
|
+
|
|
239
|
+
template <class T>
|
|
240
|
+
using IsNothrowMovable = StrictConjunction<
|
|
241
|
+
std::is_nothrow_move_constructible<T>,
|
|
242
|
+
std::is_nothrow_move_assignable<T>>;
|
|
243
|
+
|
|
244
|
+
template <class From, class To>
|
|
245
|
+
using IsConvertible = StrictConjunction<
|
|
246
|
+
std::is_constructible<To, From>,
|
|
247
|
+
std::is_assignable<To&, From>>;
|
|
248
|
+
|
|
249
|
+
template <class T, class U>
|
|
250
|
+
auto doEmplaceAssign(int, T& t, U&& u)
|
|
251
|
+
-> decltype(void(t = static_cast<U&&>(u))) {
|
|
252
|
+
t = static_cast<U&&>(u);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
template <class T, class U>
|
|
256
|
+
auto doEmplaceAssign(long, T& t, U&& u)
|
|
257
|
+
-> decltype(void(T(static_cast<U&&>(u)))) {
|
|
258
|
+
auto addr = const_cast<void*>(static_cast<void const*>(std::addressof(t)));
|
|
259
|
+
t.~T();
|
|
260
|
+
::new (addr) T(static_cast<U&&>(u));
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
template <class T, class... Us>
|
|
264
|
+
auto doEmplaceAssign(int, T& t, Us&&... us)
|
|
265
|
+
-> decltype(void(t = T(static_cast<Us&&>(us)...))) {
|
|
266
|
+
t = T(static_cast<Us&&>(us)...);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
template <class T, class... Us>
|
|
270
|
+
auto doEmplaceAssign(long, T& t, Us&&... us)
|
|
271
|
+
-> decltype(void(T(static_cast<Us&&>(us)...))) {
|
|
272
|
+
auto addr = const_cast<void*>(static_cast<void const*>(std::addressof(t)));
|
|
273
|
+
t.~T();
|
|
274
|
+
::new (addr) T(static_cast<Us&&>(us)...);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
struct EmptyTag {};
|
|
278
|
+
struct ValueTag {};
|
|
279
|
+
struct ErrorTag {};
|
|
280
|
+
enum class Which : unsigned char { eEmpty, eValue, eError };
|
|
281
|
+
enum class StorageType { ePODStruct, ePODUnion, eUnion };
|
|
282
|
+
|
|
283
|
+
template <class Value, class Error>
|
|
284
|
+
constexpr StorageType getStorageType() {
|
|
285
|
+
return StrictAllOf<std::is_trivially_copyable, Value, Error>::value
|
|
286
|
+
? (sizeof(std::pair<Value, Error>) <= sizeof(void* [2]) &&
|
|
287
|
+
StrictAllOf<std::is_trivial, Value, Error>::value
|
|
288
|
+
? StorageType::ePODStruct
|
|
289
|
+
: StorageType::ePODUnion)
|
|
290
|
+
: StorageType::eUnion;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
template <
|
|
294
|
+
class Value,
|
|
295
|
+
class Error,
|
|
296
|
+
StorageType = expected_detail::getStorageType<Value, Error>()> // ePODUnion
|
|
297
|
+
struct ExpectedStorage {
|
|
298
|
+
using value_type = Value;
|
|
299
|
+
using error_type = Error;
|
|
300
|
+
union {
|
|
301
|
+
Value value_;
|
|
302
|
+
Error error_;
|
|
303
|
+
char ch_;
|
|
304
|
+
};
|
|
305
|
+
Which which_;
|
|
306
|
+
|
|
307
|
+
template <class E = Error, class = decltype(E{})>
|
|
308
|
+
constexpr ExpectedStorage() noexcept(noexcept(E{}))
|
|
309
|
+
: error_{}, which_(Which::eError) {}
|
|
310
|
+
explicit constexpr ExpectedStorage(EmptyTag) noexcept
|
|
311
|
+
: ch_{unsafe_default_initialized}, which_(Which::eEmpty) {}
|
|
312
|
+
template <class... Vs>
|
|
313
|
+
explicit constexpr ExpectedStorage(ValueTag, Vs&&... vs) noexcept(
|
|
314
|
+
noexcept(Value(static_cast<Vs&&>(vs)...)))
|
|
315
|
+
: value_(static_cast<Vs&&>(vs)...), which_(Which::eValue) {}
|
|
316
|
+
template <class... Es>
|
|
317
|
+
explicit constexpr ExpectedStorage(ErrorTag, Es&&... es) noexcept(
|
|
318
|
+
noexcept(Error(static_cast<Es&&>(es)...)))
|
|
319
|
+
: error_(static_cast<Es&&>(es)...), which_(Which::eError) {}
|
|
320
|
+
void clear() noexcept {}
|
|
321
|
+
static constexpr bool uninitializedByException() noexcept {
|
|
322
|
+
// Although which_ may temporarily be eEmpty during construction, it
|
|
323
|
+
// is always either eValue or eError for a fully-constructed Expected.
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
template <class... Vs>
|
|
327
|
+
void assignValue(Vs&&... vs) {
|
|
328
|
+
expected_detail::doEmplaceAssign(0, value_, static_cast<Vs&&>(vs)...);
|
|
329
|
+
which_ = Which::eValue;
|
|
330
|
+
}
|
|
331
|
+
template <class... Es>
|
|
332
|
+
void assignError(Es&&... es) {
|
|
333
|
+
expected_detail::doEmplaceAssign(0, error_, static_cast<Es&&>(es)...);
|
|
334
|
+
which_ = Which::eError;
|
|
335
|
+
}
|
|
336
|
+
template <class Other>
|
|
337
|
+
void assign(Other&& that) {
|
|
338
|
+
switch (that.which_) {
|
|
339
|
+
case Which::eValue:
|
|
340
|
+
this->assignValue(static_cast<Other&&>(that).value());
|
|
341
|
+
break;
|
|
342
|
+
case Which::eError:
|
|
343
|
+
this->assignError(static_cast<Other&&>(that).error());
|
|
344
|
+
break;
|
|
345
|
+
case Which::eEmpty:
|
|
346
|
+
default:
|
|
347
|
+
this->clear();
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
Value& value() & { return value_; }
|
|
352
|
+
const Value& value() const& { return value_; }
|
|
353
|
+
Value&& value() && { return std::move(value_); }
|
|
354
|
+
const Value&& value() const&& { return std::move(value_); }
|
|
355
|
+
Error& error() & { return error_; }
|
|
356
|
+
const Error& error() const& { return error_; }
|
|
357
|
+
Error&& error() && { return std::move(error_); }
|
|
358
|
+
const Error&& error() const&& { return std::move(error_); }
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
template <class Value, class Error>
|
|
362
|
+
struct ExpectedUnion {
|
|
363
|
+
union {
|
|
364
|
+
Value value_;
|
|
365
|
+
Error error_;
|
|
366
|
+
char ch_ = unsafe_default_initialized;
|
|
367
|
+
};
|
|
368
|
+
Which which_ = Which::eEmpty;
|
|
369
|
+
|
|
370
|
+
explicit constexpr ExpectedUnion(EmptyTag) noexcept {}
|
|
371
|
+
template <class... Vs>
|
|
372
|
+
explicit constexpr ExpectedUnion(ValueTag, Vs&&... vs) noexcept(
|
|
373
|
+
noexcept(Value(static_cast<Vs&&>(vs)...)))
|
|
374
|
+
: value_(static_cast<Vs&&>(vs)...), which_(Which::eValue) {}
|
|
375
|
+
template <class... Es>
|
|
376
|
+
explicit constexpr ExpectedUnion(ErrorTag, Es&&... es) noexcept(
|
|
377
|
+
noexcept(Error(static_cast<Es&&>(es)...)))
|
|
378
|
+
: error_(static_cast<Es&&>(es)...), which_(Which::eError) {}
|
|
379
|
+
ExpectedUnion(const ExpectedUnion&) {}
|
|
380
|
+
ExpectedUnion(ExpectedUnion&&) noexcept {}
|
|
381
|
+
ExpectedUnion& operator=(const ExpectedUnion&) { return *this; }
|
|
382
|
+
ExpectedUnion& operator=(ExpectedUnion&&) noexcept { return *this; }
|
|
383
|
+
~ExpectedUnion() {}
|
|
384
|
+
Value& value() & { return value_; }
|
|
385
|
+
const Value& value() const& { return value_; }
|
|
386
|
+
Value&& value() && { return std::move(value_); }
|
|
387
|
+
const Value&& value() const&& { return std::move(value_); }
|
|
388
|
+
Error& error() & { return error_; }
|
|
389
|
+
const Error& error() const& { return error_; }
|
|
390
|
+
Error&& error() && { return std::move(error_); }
|
|
391
|
+
const Error&& error() const&& { return std::move(error_); }
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
template <class Derived, bool, bool Noexcept>
|
|
395
|
+
struct CopyConstructible {
|
|
396
|
+
constexpr CopyConstructible() = default;
|
|
397
|
+
CopyConstructible(const CopyConstructible& that) noexcept(Noexcept) {
|
|
398
|
+
static_cast<Derived*>(this)->assign(static_cast<const Derived&>(that));
|
|
399
|
+
}
|
|
400
|
+
constexpr CopyConstructible(CopyConstructible&&) = default;
|
|
401
|
+
CopyConstructible& operator=(const CopyConstructible&) = default;
|
|
402
|
+
CopyConstructible& operator=(CopyConstructible&&) = default;
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
template <class Derived, bool Noexcept>
|
|
406
|
+
struct CopyConstructible<Derived, false, Noexcept> {
|
|
407
|
+
constexpr CopyConstructible() = default;
|
|
408
|
+
CopyConstructible(const CopyConstructible&) = delete;
|
|
409
|
+
constexpr CopyConstructible(CopyConstructible&&) = default;
|
|
410
|
+
CopyConstructible& operator=(const CopyConstructible&) = default;
|
|
411
|
+
CopyConstructible& operator=(CopyConstructible&&) = default;
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
template <class Derived, bool, bool Noexcept>
|
|
415
|
+
struct MoveConstructible {
|
|
416
|
+
constexpr MoveConstructible() = default;
|
|
417
|
+
constexpr MoveConstructible(const MoveConstructible&) = default;
|
|
418
|
+
MoveConstructible(MoveConstructible&& that) noexcept(Noexcept) {
|
|
419
|
+
static_cast<Derived*>(this)->assign(std::move(static_cast<Derived&>(that)));
|
|
420
|
+
}
|
|
421
|
+
MoveConstructible& operator=(const MoveConstructible&) = default;
|
|
422
|
+
MoveConstructible& operator=(MoveConstructible&&) = default;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
template <class Derived, bool Noexcept>
|
|
426
|
+
struct MoveConstructible<Derived, false, Noexcept> {
|
|
427
|
+
constexpr MoveConstructible() = default;
|
|
428
|
+
constexpr MoveConstructible(const MoveConstructible&) = default;
|
|
429
|
+
MoveConstructible(MoveConstructible&&) = delete;
|
|
430
|
+
MoveConstructible& operator=(const MoveConstructible&) = default;
|
|
431
|
+
MoveConstructible& operator=(MoveConstructible&&) = default;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
template <class Derived, bool, bool Noexcept>
|
|
435
|
+
struct CopyAssignable {
|
|
436
|
+
constexpr CopyAssignable() = default;
|
|
437
|
+
constexpr CopyAssignable(const CopyAssignable&) = default;
|
|
438
|
+
constexpr CopyAssignable(CopyAssignable&&) = default;
|
|
439
|
+
CopyAssignable& operator=(const CopyAssignable& that) noexcept(Noexcept) {
|
|
440
|
+
static_cast<Derived*>(this)->assign(static_cast<const Derived&>(that));
|
|
441
|
+
return *this;
|
|
442
|
+
}
|
|
443
|
+
CopyAssignable& operator=(CopyAssignable&&) = default;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
template <class Derived, bool Noexcept>
|
|
447
|
+
struct CopyAssignable<Derived, false, Noexcept> {
|
|
448
|
+
constexpr CopyAssignable() = default;
|
|
449
|
+
constexpr CopyAssignable(const CopyAssignable&) = default;
|
|
450
|
+
constexpr CopyAssignable(CopyAssignable&&) = default;
|
|
451
|
+
CopyAssignable& operator=(const CopyAssignable&) = delete;
|
|
452
|
+
CopyAssignable& operator=(CopyAssignable&&) = default;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
template <class Derived, bool, bool Noexcept>
|
|
456
|
+
struct MoveAssignable {
|
|
457
|
+
constexpr MoveAssignable() = default;
|
|
458
|
+
constexpr MoveAssignable(const MoveAssignable&) = default;
|
|
459
|
+
constexpr MoveAssignable(MoveAssignable&&) = default;
|
|
460
|
+
MoveAssignable& operator=(const MoveAssignable&) = default;
|
|
461
|
+
MoveAssignable& operator=(MoveAssignable&& that) noexcept(Noexcept) {
|
|
462
|
+
static_cast<Derived*>(this)->assign(std::move(static_cast<Derived&>(that)));
|
|
463
|
+
return *this;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
template <class Derived, bool Noexcept>
|
|
468
|
+
struct MoveAssignable<Derived, false, Noexcept> {
|
|
469
|
+
constexpr MoveAssignable() = default;
|
|
470
|
+
constexpr MoveAssignable(const MoveAssignable&) = default;
|
|
471
|
+
constexpr MoveAssignable(MoveAssignable&&) = default;
|
|
472
|
+
MoveAssignable& operator=(const MoveAssignable&) = default;
|
|
473
|
+
MoveAssignable& operator=(MoveAssignable&& that) = delete;
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
template <class Value, class Error>
|
|
477
|
+
struct ExpectedStorage<Value, Error, StorageType::eUnion>
|
|
478
|
+
: ExpectedUnion<Value, Error>,
|
|
479
|
+
CopyConstructible<
|
|
480
|
+
ExpectedStorage<Value, Error, StorageType::eUnion>,
|
|
481
|
+
StrictAllOf<std::is_copy_constructible, Value, Error>::value,
|
|
482
|
+
StrictAllOf<std::is_nothrow_copy_constructible, Value, Error>::value>,
|
|
483
|
+
MoveConstructible<
|
|
484
|
+
ExpectedStorage<Value, Error, StorageType::eUnion>,
|
|
485
|
+
StrictAllOf<std::is_move_constructible, Value, Error>::value,
|
|
486
|
+
StrictAllOf<std::is_nothrow_move_constructible, Value, Error>::value>,
|
|
487
|
+
CopyAssignable<
|
|
488
|
+
ExpectedStorage<Value, Error, StorageType::eUnion>,
|
|
489
|
+
StrictAllOf<IsCopyable, Value, Error>::value,
|
|
490
|
+
StrictAllOf<IsNothrowCopyable, Value, Error>::value>,
|
|
491
|
+
MoveAssignable<
|
|
492
|
+
ExpectedStorage<Value, Error, StorageType::eUnion>,
|
|
493
|
+
StrictAllOf<IsMovable, Value, Error>::value,
|
|
494
|
+
StrictAllOf<IsNothrowMovable, Value, Error>::value> {
|
|
495
|
+
using value_type = Value;
|
|
496
|
+
using error_type = Error;
|
|
497
|
+
using Base = ExpectedUnion<Value, Error>;
|
|
498
|
+
template <class E = Error, class = decltype(E{})>
|
|
499
|
+
constexpr ExpectedStorage() noexcept(noexcept(E{})) : Base{ErrorTag{}} {}
|
|
500
|
+
ExpectedStorage(const ExpectedStorage&) = default;
|
|
501
|
+
ExpectedStorage(ExpectedStorage&&) = default;
|
|
502
|
+
ExpectedStorage& operator=(const ExpectedStorage&) = default;
|
|
503
|
+
ExpectedStorage& operator=(ExpectedStorage&&) = default;
|
|
504
|
+
using ExpectedUnion<Value, Error>::ExpectedUnion;
|
|
505
|
+
~ExpectedStorage() { clear(); }
|
|
506
|
+
void clear() noexcept {
|
|
507
|
+
switch (this->which_) {
|
|
508
|
+
case Which::eValue:
|
|
509
|
+
this->value().~Value();
|
|
510
|
+
break;
|
|
511
|
+
case Which::eError:
|
|
512
|
+
this->error().~Error();
|
|
513
|
+
break;
|
|
514
|
+
case Which::eEmpty:
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
this->which_ = Which::eEmpty;
|
|
518
|
+
}
|
|
519
|
+
bool uninitializedByException() const noexcept {
|
|
520
|
+
return this->which_ == Which::eEmpty;
|
|
521
|
+
}
|
|
522
|
+
template <class... Vs>
|
|
523
|
+
void assignValue(Vs&&... vs) {
|
|
524
|
+
auto& val = this->value();
|
|
525
|
+
if (this->which_ == Which::eValue) {
|
|
526
|
+
expected_detail::doEmplaceAssign(0, val, static_cast<Vs&&>(vs)...);
|
|
527
|
+
} else {
|
|
528
|
+
this->clear();
|
|
529
|
+
auto addr =
|
|
530
|
+
const_cast<void*>(static_cast<void const*>(std::addressof(val)));
|
|
531
|
+
::new (addr) Value(static_cast<Vs&&>(vs)...);
|
|
532
|
+
this->which_ = Which::eValue;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
template <class... Es>
|
|
536
|
+
void assignError(Es&&... es) {
|
|
537
|
+
if (this->which_ == Which::eError) {
|
|
538
|
+
expected_detail::doEmplaceAssign(
|
|
539
|
+
0, this->error(), static_cast<Es&&>(es)...);
|
|
540
|
+
} else {
|
|
541
|
+
this->clear();
|
|
542
|
+
::new ((void*)std::addressof(this->error()))
|
|
543
|
+
Error(static_cast<Es&&>(es)...);
|
|
544
|
+
this->which_ = Which::eError;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
bool isSelfAssign(const ExpectedStorage* that) const { return this == that; }
|
|
548
|
+
constexpr bool isSelfAssign(const void*) const { return false; }
|
|
549
|
+
template <class Other>
|
|
550
|
+
void assign(Other&& that) {
|
|
551
|
+
if (isSelfAssign(&that)) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
switch (that.which_) {
|
|
555
|
+
case Which::eValue:
|
|
556
|
+
this->assignValue(static_cast<Other&&>(that).value());
|
|
557
|
+
break;
|
|
558
|
+
case Which::eError:
|
|
559
|
+
this->assignError(static_cast<Other&&>(that).error());
|
|
560
|
+
break;
|
|
561
|
+
case Which::eEmpty:
|
|
562
|
+
default:
|
|
563
|
+
this->clear();
|
|
564
|
+
break;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
|
|
569
|
+
// For small (pointer-sized) trivial types, a struct is faster than a union.
|
|
570
|
+
template <class Value, class Error>
|
|
571
|
+
struct ExpectedStorage<Value, Error, StorageType::ePODStruct> {
|
|
572
|
+
using value_type = Value;
|
|
573
|
+
using error_type = Error;
|
|
574
|
+
Which which_;
|
|
575
|
+
Error error_;
|
|
576
|
+
Value value_;
|
|
577
|
+
|
|
578
|
+
constexpr ExpectedStorage() noexcept
|
|
579
|
+
: which_(Which::eError), error_{}, value_{} {}
|
|
580
|
+
explicit constexpr ExpectedStorage(EmptyTag) noexcept
|
|
581
|
+
: which_(Which::eEmpty), error_{}, value_{} {}
|
|
582
|
+
template <class... Vs>
|
|
583
|
+
explicit constexpr ExpectedStorage(ValueTag, Vs&&... vs) noexcept(
|
|
584
|
+
noexcept(Value(static_cast<Vs&&>(vs)...)))
|
|
585
|
+
: which_(Which::eValue), error_{}, value_(static_cast<Vs&&>(vs)...) {}
|
|
586
|
+
template <class... Es>
|
|
587
|
+
explicit constexpr ExpectedStorage(ErrorTag, Es&&... es) noexcept(
|
|
588
|
+
noexcept(Error(static_cast<Es&&>(es)...)))
|
|
589
|
+
: which_(Which::eError), error_(static_cast<Es&&>(es)...), value_{} {}
|
|
590
|
+
void clear() noexcept {}
|
|
591
|
+
constexpr static bool uninitializedByException() noexcept { return false; }
|
|
592
|
+
template <class... Vs>
|
|
593
|
+
void assignValue(Vs&&... vs) {
|
|
594
|
+
expected_detail::doEmplaceAssign(0, value_, static_cast<Vs&&>(vs)...);
|
|
595
|
+
which_ = Which::eValue;
|
|
596
|
+
}
|
|
597
|
+
template <class... Es>
|
|
598
|
+
void assignError(Es&&... es) {
|
|
599
|
+
expected_detail::doEmplaceAssign(0, error_, static_cast<Es&&>(es)...);
|
|
600
|
+
which_ = Which::eError;
|
|
601
|
+
}
|
|
602
|
+
template <class Other>
|
|
603
|
+
void assign(Other&& that) {
|
|
604
|
+
switch (that.which_) {
|
|
605
|
+
case Which::eValue:
|
|
606
|
+
this->assignValue(static_cast<Other&&>(that).value());
|
|
607
|
+
break;
|
|
608
|
+
case Which::eError:
|
|
609
|
+
this->assignError(static_cast<Other&&>(that).error());
|
|
610
|
+
break;
|
|
611
|
+
case Which::eEmpty:
|
|
612
|
+
default:
|
|
613
|
+
this->clear();
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
Value& value() & { return value_; }
|
|
618
|
+
const Value& value() const& { return value_; }
|
|
619
|
+
Value&& value() && { return std::move(value_); }
|
|
620
|
+
const Value&& value() const&& { return std::move(value_); }
|
|
621
|
+
Error& error() & { return error_; }
|
|
622
|
+
const Error& error() const& { return error_; }
|
|
623
|
+
Error&& error() && { return std::move(error_); }
|
|
624
|
+
const Error&& error() const&& { return std::move(error_); }
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
namespace expected_detail_ExpectedHelper {
|
|
628
|
+
// Tricky hack so that Expected::then can handle lambdas that return void
|
|
629
|
+
template <class T>
|
|
630
|
+
inline T&& operator,(T&& t, Unit) noexcept {
|
|
631
|
+
return static_cast<T&&>(t);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
struct ExpectedHelper {
|
|
635
|
+
template <typename V, typename E>
|
|
636
|
+
FOLLY_ERASE static void assume_empty(Expected<V, E> const& x) {
|
|
637
|
+
compiler_may_unsafely_assume(x.which_ == Which::eEmpty);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
template <class Error, class T>
|
|
641
|
+
static constexpr Expected<typename std::decay<T>::type, Error> return_(
|
|
642
|
+
T&& t) {
|
|
643
|
+
return folly::makeExpected<Error>(static_cast<T&&>(t));
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
template <
|
|
647
|
+
class Error,
|
|
648
|
+
class T,
|
|
649
|
+
class U FOLLY_REQUIRES_TRAILING(
|
|
650
|
+
expected_detail::IsConvertible<U&&, Error>::value)>
|
|
651
|
+
static constexpr Expected<T, Error> return_(Expected<T, U>&& t) {
|
|
652
|
+
return Expected<T, Error>(static_cast<Expected<T, U>&&>(t));
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
template <class This>
|
|
656
|
+
static typename std::decay<This>::type then_(This&& ex) {
|
|
657
|
+
return static_cast<This&&>(ex);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
FOLLY_PUSH_WARNING
|
|
661
|
+
// Don't warn about not using the overloaded comma operator.
|
|
662
|
+
FOLLY_MSVC_DISABLE_WARNING(4913)
|
|
663
|
+
// On MSVC in optimized builds, the following functions can throw warning 4702
|
|
664
|
+
// Unreachable Code which will block builds which treat warnings as error.
|
|
665
|
+
FOLLY_MSVC_DISABLE_WARNING(4702)
|
|
666
|
+
template <
|
|
667
|
+
class This,
|
|
668
|
+
class Fn,
|
|
669
|
+
class... Fns,
|
|
670
|
+
class E = ExpectedErrorType<This>,
|
|
671
|
+
class T = ExpectedHelper>
|
|
672
|
+
static auto then_(This&& ex, Fn&& fn, Fns&&... fns)
|
|
673
|
+
-> decltype(T::then_(
|
|
674
|
+
T::template return_<E>(
|
|
675
|
+
(std::declval<Fn>()(std::declval<This>().value()), unit)),
|
|
676
|
+
std::declval<Fns>()...)) {
|
|
677
|
+
if (FOLLY_LIKELY(ex.which_ == expected_detail::Which::eValue)) {
|
|
678
|
+
return T::then_(
|
|
679
|
+
T::template return_<E>(
|
|
680
|
+
// Uses the comma operator defined above IFF the lambda
|
|
681
|
+
// returns non-void.
|
|
682
|
+
(static_cast<Fn&&>(fn)(static_cast<This&&>(ex).value()), unit)),
|
|
683
|
+
static_cast<Fns&&>(fns)...);
|
|
684
|
+
}
|
|
685
|
+
return makeUnexpected(static_cast<This&&>(ex).error());
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
template <
|
|
689
|
+
class This,
|
|
690
|
+
class Yes,
|
|
691
|
+
class No,
|
|
692
|
+
class Ret = decltype(std::declval<Yes>()(std::declval<This>().value())),
|
|
693
|
+
class Err = decltype(std::declval<No>()(std::declval<This>().error()))
|
|
694
|
+
FOLLY_REQUIRES_TRAILING(!std::is_void<Err>::value)>
|
|
695
|
+
static Ret thenOrThrow_(This&& ex, Yes&& yes, No&& no) {
|
|
696
|
+
if (FOLLY_LIKELY(ex.which_ == expected_detail::Which::eValue)) {
|
|
697
|
+
return Ret(static_cast<Yes&&>(yes)(static_cast<This&&>(ex).value()));
|
|
698
|
+
}
|
|
699
|
+
throw_exception(static_cast<No&&>(no)(static_cast<This&&>(ex).error()));
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
template <
|
|
703
|
+
class This,
|
|
704
|
+
class Yes,
|
|
705
|
+
class No,
|
|
706
|
+
class Ret = decltype(std::declval<Yes>()(std::declval<This>().value())),
|
|
707
|
+
class Err = decltype(std::declval<No>()(std::declval<This&>().error()))
|
|
708
|
+
FOLLY_REQUIRES_TRAILING(std::is_void<Err>::value)>
|
|
709
|
+
static Ret thenOrThrow_(This&& ex, Yes&& yes, No&& no) {
|
|
710
|
+
if (FOLLY_LIKELY(ex.which_ == expected_detail::Which::eValue)) {
|
|
711
|
+
return Ret(static_cast<Yes&&>(yes)(static_cast<This&&>(ex).value()));
|
|
712
|
+
}
|
|
713
|
+
static_cast<No&&>(no)(ex.error());
|
|
714
|
+
throw_exception<BadExpectedAccess<ExpectedErrorType<This>>>(
|
|
715
|
+
static_cast<This&&>(ex).error());
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Note: the condition for specialization is easy to miss here - this is for
|
|
720
|
+
* where Err fails is_void, AND the else chain is not void returning. Invoked
|
|
721
|
+
* when orElse handles a chain.
|
|
722
|
+
*/
|
|
723
|
+
template <
|
|
724
|
+
class This,
|
|
725
|
+
class No,
|
|
726
|
+
class... AndFns,
|
|
727
|
+
class E = ExpectedErrorType<This>,
|
|
728
|
+
class V = ExpectedValueType<This>,
|
|
729
|
+
class T = ExpectedHelper,
|
|
730
|
+
class RetValue = decltype(T::then_(
|
|
731
|
+
T::template return_<E>((std::declval<No>()(
|
|
732
|
+
std::declval<This>().error()))),
|
|
733
|
+
std::declval<AndFns>()...)
|
|
734
|
+
.value()),
|
|
735
|
+
typename std::enable_if<!std::is_same<
|
|
736
|
+
std::remove_reference<RetValue>,
|
|
737
|
+
std::remove_reference<folly::Unit&&>>::value>::type* = nullptr,
|
|
738
|
+
class Err = decltype(std::declval<No>()(std::declval<This&>().error()))
|
|
739
|
+
FOLLY_REQUIRES_TRAILING(!std::is_void<Err>::value)>
|
|
740
|
+
static auto orElse_(This&& ex, No&& no, AndFns&&... fns) -> Expected<V, E> {
|
|
741
|
+
// Note - this basically decays into then_ once the first type (No) is
|
|
742
|
+
// called for the error.
|
|
743
|
+
if (FOLLY_LIKELY(ex.which_ == expected_detail::Which::eValue)) {
|
|
744
|
+
return T::template return_<E>((T::then_(T::template return_<E>(
|
|
745
|
+
// Uses the comma operator defined above IFF the lambda
|
|
746
|
+
// returns non-void.
|
|
747
|
+
static_cast<decltype(ex)&&>(ex).value()))));
|
|
748
|
+
}
|
|
749
|
+
return T::then_(
|
|
750
|
+
T::template return_<E>(
|
|
751
|
+
(static_cast<No&&>(no)(static_cast<This&&>(ex).error()))),
|
|
752
|
+
static_cast<AndFns&&>(fns)...);
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Note: the condition for specialization is easy to miss here - this is for
|
|
757
|
+
* where Err fails is_void AND the else chain is void returning. Invoked when
|
|
758
|
+
* orElse handles a chain.
|
|
759
|
+
*/
|
|
760
|
+
template <
|
|
761
|
+
class This,
|
|
762
|
+
class No,
|
|
763
|
+
class... AndFns,
|
|
764
|
+
class E = ExpectedErrorType<This>,
|
|
765
|
+
class T = ExpectedHelper,
|
|
766
|
+
class RetValue = decltype(T::then_(
|
|
767
|
+
T::template return_<E>((std::declval<No>()(
|
|
768
|
+
std::declval<This>().error()))),
|
|
769
|
+
std::declval<AndFns>()...)
|
|
770
|
+
.value()),
|
|
771
|
+
typename std::enable_if<std::is_same<
|
|
772
|
+
std::remove_reference<RetValue>,
|
|
773
|
+
std::remove_reference<folly::Unit&&>>::value>::type* = nullptr,
|
|
774
|
+
class Err = decltype(std::declval<No>()(std::declval<This&>().error()))
|
|
775
|
+
FOLLY_REQUIRES_TRAILING(!std::is_void<Err>::value)>
|
|
776
|
+
static auto orElse_(This&& ex, No&& no, AndFns&&... fns)
|
|
777
|
+
-> Expected<folly::Unit, E> {
|
|
778
|
+
// Note - this basically decays into then_ once the first type (No) is
|
|
779
|
+
// called for the error.
|
|
780
|
+
if (std::forward<This>(ex).which_ == expected_detail::Which::eValue) {
|
|
781
|
+
// Void returning method on else must either throw, or be replaced with a
|
|
782
|
+
// chain that ends in a valid result.""
|
|
783
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
784
|
+
}
|
|
785
|
+
return T::then_(
|
|
786
|
+
T::template return_<E>(
|
|
787
|
+
(static_cast<No&&>(no)(static_cast<This&&>(ex).error()))),
|
|
788
|
+
static_cast<AndFns&&>(fns)...);
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Note: the condition for specialization is easy to miss here - this is for
|
|
793
|
+
* where Err passes is_void. Invoked when orElse handles a void returning
|
|
794
|
+
* func.
|
|
795
|
+
*/
|
|
796
|
+
template <
|
|
797
|
+
class This,
|
|
798
|
+
class No,
|
|
799
|
+
class... AndFns,
|
|
800
|
+
class E = ExpectedErrorType<This>,
|
|
801
|
+
class V = ExpectedValueType<This>,
|
|
802
|
+
class T = ExpectedHelper,
|
|
803
|
+
class Err = decltype(std::declval<No>()(std::declval<This&>().error()))
|
|
804
|
+
FOLLY_REQUIRES_TRAILING(std::is_void<Err>::value)>
|
|
805
|
+
static auto orElse_(This&& ex, No&& no, AndFns&&...) -> Expected<V, E> {
|
|
806
|
+
if (FOLLY_LIKELY(ex.which_ == expected_detail::Which::eValue)) {
|
|
807
|
+
return return_<E>(static_cast<decltype(ex)&&>(ex).value());
|
|
808
|
+
}
|
|
809
|
+
static_cast<No&&>(no)(static_cast<This&&>(ex).error());
|
|
810
|
+
return makeUnexpected(static_cast<decltype(ex)&&>(ex).error());
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
template <
|
|
814
|
+
class This,
|
|
815
|
+
class OnError,
|
|
816
|
+
class Err =
|
|
817
|
+
decltype(std::declval<OnError>()(std::declval<This>().error()))
|
|
818
|
+
FOLLY_REQUIRES_TRAILING(std::is_void<Err>::value)>
|
|
819
|
+
static This onError_(This&& ex, OnError&& onError) {
|
|
820
|
+
if (UNLIKELY(ex.which_ == expected_detail::Which::eError)) {
|
|
821
|
+
static_cast<OnError&&>(onError)(static_cast<This&&>(ex).error());
|
|
822
|
+
}
|
|
823
|
+
return ex;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
FOLLY_POP_WARNING
|
|
827
|
+
};
|
|
828
|
+
} // namespace expected_detail_ExpectedHelper
|
|
829
|
+
|
|
830
|
+
struct UnexpectedTag {};
|
|
831
|
+
|
|
832
|
+
} // namespace expected_detail
|
|
833
|
+
|
|
834
|
+
using unexpected_t =
|
|
835
|
+
expected_detail::UnexpectedTag (&)(expected_detail::UnexpectedTag);
|
|
836
|
+
|
|
837
|
+
inline expected_detail::UnexpectedTag unexpected(
|
|
838
|
+
expected_detail::UnexpectedTag = {}) {
|
|
839
|
+
return {};
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
namespace expected_detail {
|
|
843
|
+
// empty
|
|
844
|
+
} // namespace expected_detail
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* Expected - For holding a value or an error. Useful as an alternative to
|
|
848
|
+
* exceptions, for APIs where throwing on failure would be too expensive.
|
|
849
|
+
*
|
|
850
|
+
* Expected<Value, Error> is a variant over the types Value and Error.
|
|
851
|
+
*
|
|
852
|
+
* Expected does not offer support for references. Use
|
|
853
|
+
* Expected<std::reference_wrapper<T>, Error> if your API needs to return a
|
|
854
|
+
* reference or an error.
|
|
855
|
+
*
|
|
856
|
+
* Expected offers a continuation-based interface to reduce the boilerplate
|
|
857
|
+
* of checking error codes. The Expected::then member function takes a lambda
|
|
858
|
+
* that is to execute should the Expected object contain a value. The return
|
|
859
|
+
* value of the lambda is wrapped in an Expected and returned. If the lambda is
|
|
860
|
+
* not executed because the Expected contains an error, the error is returned
|
|
861
|
+
* immediately in a new Expected object.
|
|
862
|
+
*
|
|
863
|
+
* Expected<int, Error> funcTheFirst();
|
|
864
|
+
* Expected<std::string, Error> funcTheSecond() {
|
|
865
|
+
* return funcTheFirst().then([](int i) { return std::to_string(i); });
|
|
866
|
+
* }
|
|
867
|
+
*
|
|
868
|
+
* The above line of code could more verbosely written as:
|
|
869
|
+
*
|
|
870
|
+
* Expected<std::string, Error> funcTheSecond() {
|
|
871
|
+
* if (auto ex = funcTheFirst()) {
|
|
872
|
+
* return std::to_string(*ex);
|
|
873
|
+
* }
|
|
874
|
+
* return makeUnexpected(ex.error());
|
|
875
|
+
* }
|
|
876
|
+
*
|
|
877
|
+
* Continuations can chain, like:
|
|
878
|
+
*
|
|
879
|
+
* Expected<D, Error> maybeD = someFunc()
|
|
880
|
+
* .then([](A a){return B(a);})
|
|
881
|
+
* .then([](B b){return C(b);})
|
|
882
|
+
* .then([](C c){return D(c);});
|
|
883
|
+
*
|
|
884
|
+
* To avoid the redundant error checking that would happen if a call at the
|
|
885
|
+
* front of the chain returns an error, these call chains can be collaped into
|
|
886
|
+
* a single call to .then:
|
|
887
|
+
*
|
|
888
|
+
* Expected<D, Error> maybeD = someFunc()
|
|
889
|
+
* .then([](A a){return B(a);},
|
|
890
|
+
* [](B b){return C(b);},
|
|
891
|
+
* [](C c){return D(c);});
|
|
892
|
+
*
|
|
893
|
+
* The result of .then() is wrapped into Expected< ~, Error > if it isn't
|
|
894
|
+
* of that form already. Consider the following code:
|
|
895
|
+
*
|
|
896
|
+
* extern Expected<std::string, Error> readLineFromIO();
|
|
897
|
+
* extern Expected<int, Error> parseInt(std::string);
|
|
898
|
+
* extern int increment(int);
|
|
899
|
+
*
|
|
900
|
+
* Expected<int, Error> x = readLineFromIO().then(parseInt).then(increment);
|
|
901
|
+
*
|
|
902
|
+
* From the code above, we see that .then() works both with functions that
|
|
903
|
+
* return an Expected< ~, Error > (like parseInt) and with ones that return
|
|
904
|
+
* a plain value (like increment). In the case of parseInt, .then() returns
|
|
905
|
+
* the result of parseInt as-is. In the case of increment, it wraps the int
|
|
906
|
+
* that increment returns into an Expected< int, Error >.
|
|
907
|
+
*
|
|
908
|
+
* Sometimes when using a continuation you would prefer an exception to be
|
|
909
|
+
* thrown for a value-less Expected. For that you can use .thenOrThrow, as
|
|
910
|
+
* follows:
|
|
911
|
+
*
|
|
912
|
+
* B b = someFunc()
|
|
913
|
+
* .thenOrThrow([](A a){return B(a);});
|
|
914
|
+
*
|
|
915
|
+
* The above call to thenOrThrow will invoke the lambda if the Expected returned
|
|
916
|
+
* by someFunc() contains a value. Otherwise, it will throw an exception of type
|
|
917
|
+
* Unexpected<Error>::BadExpectedAccess. If you prefer it throw an exception of
|
|
918
|
+
* a different type, you can pass a second lambda to thenOrThrow:
|
|
919
|
+
*
|
|
920
|
+
* B b = someFunc()
|
|
921
|
+
* .thenOrThrow([](A a){return B(a);},
|
|
922
|
+
* [](Error e) {throw MyException(e);});
|
|
923
|
+
*
|
|
924
|
+
* Like C++17's std::variant, Expected offers the almost-never-empty guarantee;
|
|
925
|
+
* that is, an Expected<Value, Error> almost always contains either a Value or
|
|
926
|
+
* and Error. Partially-formed Expected objects occur when an assignment to
|
|
927
|
+
* an Expected object that would change the type of the contained object (Value-
|
|
928
|
+
* to-Error or vice versa) throws. Trying to access either the contained value
|
|
929
|
+
* or error object causes Expected to throw folly::BadExpectedAccess.
|
|
930
|
+
*
|
|
931
|
+
* Expected models OptionalPointee, so calling 'get_pointer(ex)' will return a
|
|
932
|
+
* pointer to nullptr if the 'ex' is in the error state, and a pointer to the
|
|
933
|
+
* value otherwise:
|
|
934
|
+
*
|
|
935
|
+
* Expected<int, Error> maybeInt = ...;
|
|
936
|
+
* if (int* v = get_pointer(maybeInt)) {
|
|
937
|
+
* cout << *v << endl;
|
|
938
|
+
* }
|
|
939
|
+
*/
|
|
940
|
+
template <class Value, class Error>
|
|
941
|
+
class Expected final : expected_detail::ExpectedStorage<Value, Error> {
|
|
942
|
+
template <class, class>
|
|
943
|
+
friend class Expected;
|
|
944
|
+
template <class, class, expected_detail::StorageType>
|
|
945
|
+
friend struct expected_detail::ExpectedStorage;
|
|
946
|
+
friend struct expected_detail::ExpectedHelper;
|
|
947
|
+
using Base = expected_detail::ExpectedStorage<Value, Error>;
|
|
948
|
+
Base& base() & { return *this; }
|
|
949
|
+
const Base& base() const& { return *this; }
|
|
950
|
+
Base&& base() && { return std::move(*this); }
|
|
951
|
+
|
|
952
|
+
struct MakeBadExpectedAccess {
|
|
953
|
+
template <class E>
|
|
954
|
+
auto operator()(E&& e) {
|
|
955
|
+
return BadExpectedAccess<Error>(static_cast<E&&>(e));
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
public:
|
|
960
|
+
using value_type = Value;
|
|
961
|
+
using error_type = Error;
|
|
962
|
+
|
|
963
|
+
template <class U>
|
|
964
|
+
using rebind = Expected<U, Error>;
|
|
965
|
+
|
|
966
|
+
using promise_type = expected_detail::Promise<Value, Error>;
|
|
967
|
+
|
|
968
|
+
static_assert(
|
|
969
|
+
!std::is_reference<Value>::value,
|
|
970
|
+
"Expected may not be used with reference types");
|
|
971
|
+
static_assert(
|
|
972
|
+
!std::is_abstract<Value>::value,
|
|
973
|
+
"Expected may not be used with abstract types");
|
|
974
|
+
|
|
975
|
+
/*
|
|
976
|
+
* Constructors
|
|
977
|
+
*/
|
|
978
|
+
template <class B = Base, class = decltype(B{})>
|
|
979
|
+
Expected() noexcept(noexcept(B{})) : Base{} {}
|
|
980
|
+
Expected(const Expected& that) = default;
|
|
981
|
+
Expected(Expected&& that) = default;
|
|
982
|
+
|
|
983
|
+
template <
|
|
984
|
+
class V,
|
|
985
|
+
class E FOLLY_REQUIRES_TRAILING(
|
|
986
|
+
!std::is_same<Expected<V, E>, Expected>::value &&
|
|
987
|
+
std::is_constructible<Value, V&&>::value &&
|
|
988
|
+
std::is_constructible<Error, E&&>::value)>
|
|
989
|
+
Expected(Expected<V, E> that) : Base{expected_detail::EmptyTag{}} {
|
|
990
|
+
this->assign(std::move(that));
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
FOLLY_REQUIRES(std::is_copy_constructible<Value>::value)
|
|
994
|
+
constexpr /* implicit */ Expected(const Value& val) noexcept(
|
|
995
|
+
noexcept(Value(val)))
|
|
996
|
+
: Base{expected_detail::ValueTag{}, val} {}
|
|
997
|
+
|
|
998
|
+
FOLLY_REQUIRES(std::is_move_constructible<Value>::value)
|
|
999
|
+
constexpr /* implicit */ Expected(Value&& val) noexcept(
|
|
1000
|
+
noexcept(Value(std::move(val))))
|
|
1001
|
+
: Base{expected_detail::ValueTag{}, std::move(val)} {}
|
|
1002
|
+
|
|
1003
|
+
template <class T FOLLY_REQUIRES_TRAILING(
|
|
1004
|
+
std::is_convertible<T, Value>::value &&
|
|
1005
|
+
!std::is_convertible<T, Error>::value)>
|
|
1006
|
+
constexpr /* implicit */ Expected(T&& val) noexcept(
|
|
1007
|
+
noexcept(Value(static_cast<T&&>(val))))
|
|
1008
|
+
: Base{expected_detail::ValueTag{}, static_cast<T&&>(val)} {}
|
|
1009
|
+
|
|
1010
|
+
template <class... Ts FOLLY_REQUIRES_TRAILING(
|
|
1011
|
+
std::is_constructible<Value, Ts&&...>::value)>
|
|
1012
|
+
explicit constexpr Expected(std::in_place_t, Ts&&... ts) noexcept(
|
|
1013
|
+
noexcept(Value(std::declval<Ts>()...)))
|
|
1014
|
+
: Base{expected_detail::ValueTag{}, static_cast<Ts&&>(ts)...} {}
|
|
1015
|
+
|
|
1016
|
+
template <
|
|
1017
|
+
class U,
|
|
1018
|
+
class... Ts FOLLY_REQUIRES_TRAILING(
|
|
1019
|
+
std::is_constructible<Value, std::initializer_list<U>&, Ts&&...>::
|
|
1020
|
+
value)>
|
|
1021
|
+
explicit constexpr Expected(
|
|
1022
|
+
std::in_place_t,
|
|
1023
|
+
std::initializer_list<U> il,
|
|
1024
|
+
Ts&&... ts) noexcept(noexcept(Value(std::declval<Ts>()...)))
|
|
1025
|
+
: Base{expected_detail::ValueTag{}, il, static_cast<Ts&&>(ts)...} {}
|
|
1026
|
+
|
|
1027
|
+
// If overload resolution selects one of these deleted functions, that
|
|
1028
|
+
// means you need to use makeUnexpected
|
|
1029
|
+
/* implicit */ Expected(const Error&) = delete;
|
|
1030
|
+
/* implicit */ Expected(Error&&) = delete;
|
|
1031
|
+
|
|
1032
|
+
FOLLY_REQUIRES(std::is_copy_constructible<Error>::value)
|
|
1033
|
+
constexpr Expected(unexpected_t, const Error& err) noexcept(
|
|
1034
|
+
noexcept(Error(err)))
|
|
1035
|
+
: Base{expected_detail::ErrorTag{}, err} {}
|
|
1036
|
+
|
|
1037
|
+
FOLLY_REQUIRES(std::is_move_constructible<Error>::value)
|
|
1038
|
+
constexpr Expected(unexpected_t, Error&& err) noexcept(
|
|
1039
|
+
noexcept(Error(std::move(err))))
|
|
1040
|
+
: Base{expected_detail::ErrorTag{}, std::move(err)} {}
|
|
1041
|
+
|
|
1042
|
+
FOLLY_REQUIRES(std::is_copy_constructible<Error>::value)
|
|
1043
|
+
constexpr /* implicit */ Expected(const Unexpected<Error>& err) noexcept(
|
|
1044
|
+
noexcept(Error(err.error())))
|
|
1045
|
+
: Base{expected_detail::ErrorTag{}, err.error()} {}
|
|
1046
|
+
|
|
1047
|
+
FOLLY_REQUIRES(std::is_move_constructible<Error>::value)
|
|
1048
|
+
constexpr /* implicit */ Expected(Unexpected<Error>&& err) noexcept(
|
|
1049
|
+
noexcept(Error(std::move(err.error()))))
|
|
1050
|
+
: Base{expected_detail::ErrorTag{}, std::move(err.error())} {}
|
|
1051
|
+
|
|
1052
|
+
template <class OtherError FOLLY_REQUIRES_TRAILING(
|
|
1053
|
+
std::is_convertible<const OtherError&, Error>::value)>
|
|
1054
|
+
constexpr /* implicit */ Expected(const Unexpected<OtherError>& err) noexcept(
|
|
1055
|
+
noexcept(Error(err.error())))
|
|
1056
|
+
: Base{expected_detail::ErrorTag{}, Error(err.error())} {}
|
|
1057
|
+
|
|
1058
|
+
template <class OtherError FOLLY_REQUIRES_TRAILING(
|
|
1059
|
+
std::is_convertible<OtherError&&, Error>::value)>
|
|
1060
|
+
constexpr /* implicit */ Expected(Unexpected<OtherError>&& err) noexcept(
|
|
1061
|
+
noexcept(Error(std::move(err.error()))))
|
|
1062
|
+
: Base{expected_detail::ErrorTag{}, Error(std::move(err.error()))} {}
|
|
1063
|
+
|
|
1064
|
+
/*
|
|
1065
|
+
* Assignment operators
|
|
1066
|
+
*/
|
|
1067
|
+
Expected& operator=(const Expected& that) = default;
|
|
1068
|
+
Expected& operator=(Expected&& that) = default;
|
|
1069
|
+
|
|
1070
|
+
template <
|
|
1071
|
+
class V,
|
|
1072
|
+
class E FOLLY_REQUIRES_TRAILING(
|
|
1073
|
+
!std::is_same<Expected<V, E>, Expected>::value &&
|
|
1074
|
+
expected_detail::IsConvertible<V&&, Value>::value &&
|
|
1075
|
+
expected_detail::IsConvertible<E&&, Error>::value)>
|
|
1076
|
+
Expected& operator=(Expected<V, E> that) {
|
|
1077
|
+
this->assign(std::move(that));
|
|
1078
|
+
return *this;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
FOLLY_REQUIRES(expected_detail::IsCopyable<Value>::value)
|
|
1082
|
+
Expected& operator=(const Value& val) noexcept(
|
|
1083
|
+
expected_detail::IsNothrowCopyable<Value>::value) {
|
|
1084
|
+
this->assignValue(val);
|
|
1085
|
+
return *this;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
FOLLY_REQUIRES(expected_detail::IsMovable<Value>::value)
|
|
1089
|
+
Expected& operator=(Value&& val) noexcept(
|
|
1090
|
+
expected_detail::IsNothrowMovable<Value>::value) {
|
|
1091
|
+
this->assignValue(std::move(val));
|
|
1092
|
+
return *this;
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
template <class T FOLLY_REQUIRES_TRAILING(
|
|
1096
|
+
std::is_convertible<T, Value>::value &&
|
|
1097
|
+
!std::is_convertible<T, Error>::value)>
|
|
1098
|
+
Expected& operator=(T&& val) {
|
|
1099
|
+
this->assignValue(static_cast<T&&>(val));
|
|
1100
|
+
return *this;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
FOLLY_REQUIRES(expected_detail::IsCopyable<Error>::value)
|
|
1104
|
+
Expected& operator=(const Unexpected<Error>& err) noexcept(
|
|
1105
|
+
expected_detail::IsNothrowCopyable<Error>::value) {
|
|
1106
|
+
this->assignError(err.error());
|
|
1107
|
+
return *this;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
FOLLY_REQUIRES(expected_detail::IsMovable<Error>::value)
|
|
1111
|
+
Expected& operator=(Unexpected<Error>&& err) noexcept(
|
|
1112
|
+
expected_detail::IsNothrowMovable<Error>::value) {
|
|
1113
|
+
this->assignError(std::move(err.error()));
|
|
1114
|
+
return *this;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
template <class... Ts FOLLY_REQUIRES_TRAILING(
|
|
1118
|
+
std::is_constructible<Value, Ts&&...>::value)>
|
|
1119
|
+
void emplace(Ts&&... ts) {
|
|
1120
|
+
this->assignValue(static_cast<Ts&&>(ts)...);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* swap
|
|
1125
|
+
*/
|
|
1126
|
+
void swap(Expected& that) noexcept(
|
|
1127
|
+
std::is_nothrow_swappable_v<Value> &&
|
|
1128
|
+
std::is_nothrow_swappable_v<Error>) {
|
|
1129
|
+
if (this->uninitializedByException() || that.uninitializedByException()) {
|
|
1130
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1131
|
+
}
|
|
1132
|
+
using std::swap;
|
|
1133
|
+
if (*this) {
|
|
1134
|
+
if (that) {
|
|
1135
|
+
swap(this->value_, that.value_);
|
|
1136
|
+
} else {
|
|
1137
|
+
Error e(std::move(that.error_));
|
|
1138
|
+
that.assignValue(std::move(this->value_));
|
|
1139
|
+
this->assignError(std::move(e));
|
|
1140
|
+
}
|
|
1141
|
+
} else {
|
|
1142
|
+
if (!that) {
|
|
1143
|
+
swap(this->error_, that.error_);
|
|
1144
|
+
} else {
|
|
1145
|
+
Error e(std::move(this->error_));
|
|
1146
|
+
this->assignValue(std::move(that.value_));
|
|
1147
|
+
that.assignError(std::move(e));
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// If overload resolution selects one of these deleted functions, that
|
|
1153
|
+
// means you need to use makeUnexpected
|
|
1154
|
+
/* implicit */ Expected& operator=(const Error&) = delete;
|
|
1155
|
+
/* implicit */ Expected& operator=(Error&&) = delete;
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* Relational Operators
|
|
1159
|
+
*/
|
|
1160
|
+
template <class Val, class Err>
|
|
1161
|
+
friend typename std::enable_if<IsEqualityComparable<Val>::value, bool>::type
|
|
1162
|
+
operator==(const Expected<Val, Err>& lhs, const Expected<Val, Err>& rhs);
|
|
1163
|
+
template <class Val, class Err>
|
|
1164
|
+
friend typename std::enable_if<IsLessThanComparable<Val>::value, bool>::type
|
|
1165
|
+
operator<(const Expected<Val, Err>& lhs, const Expected<Val, Err>& rhs);
|
|
1166
|
+
|
|
1167
|
+
/*
|
|
1168
|
+
* Accessors
|
|
1169
|
+
*/
|
|
1170
|
+
constexpr bool hasValue() const noexcept {
|
|
1171
|
+
return FOLLY_LIKELY(expected_detail::Which::eValue == this->which_);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
constexpr bool hasError() const noexcept {
|
|
1175
|
+
return FOLLY_UNLIKELY(expected_detail::Which::eError == this->which_);
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
using Base::uninitializedByException;
|
|
1179
|
+
|
|
1180
|
+
const Value& value() const& {
|
|
1181
|
+
requireValue();
|
|
1182
|
+
return this->Base::value();
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
Value& value() & {
|
|
1186
|
+
requireValue();
|
|
1187
|
+
return this->Base::value();
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
const Value&& value() const&& {
|
|
1191
|
+
requireValueMove();
|
|
1192
|
+
return std::move(this->Base::value());
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
Value&& value() && {
|
|
1196
|
+
requireValueMove();
|
|
1197
|
+
return std::move(this->Base::value());
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
const Error& error() const& {
|
|
1201
|
+
requireError();
|
|
1202
|
+
return this->Base::error();
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
Error& error() & {
|
|
1206
|
+
requireError();
|
|
1207
|
+
return this->Base::error();
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
const Error&& error() const&& {
|
|
1211
|
+
requireError();
|
|
1212
|
+
return std::move(this->Base::error());
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
Error&& error() && {
|
|
1216
|
+
requireError();
|
|
1217
|
+
return std::move(this->Base::error());
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
// Return a copy of the value if set, or a given default if not.
|
|
1221
|
+
template <class U>
|
|
1222
|
+
Value value_or(U&& dflt) const& {
|
|
1223
|
+
if (FOLLY_LIKELY(this->which_ == expected_detail::Which::eValue)) {
|
|
1224
|
+
return this->value_;
|
|
1225
|
+
}
|
|
1226
|
+
return static_cast<U&&>(dflt);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
template <class U>
|
|
1230
|
+
Value value_or(U&& dflt) && {
|
|
1231
|
+
if (FOLLY_LIKELY(this->which_ == expected_detail::Which::eValue)) {
|
|
1232
|
+
return std::move(this->value_);
|
|
1233
|
+
}
|
|
1234
|
+
return static_cast<U&&>(dflt);
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
explicit constexpr operator bool() const noexcept { return hasValue(); }
|
|
1238
|
+
|
|
1239
|
+
const Value& operator*() const& { return this->value(); }
|
|
1240
|
+
|
|
1241
|
+
Value& operator*() & { return this->value(); }
|
|
1242
|
+
|
|
1243
|
+
Value&& operator*() && { return std::move(std::move(*this).value()); }
|
|
1244
|
+
|
|
1245
|
+
const Value* operator->() const { return std::addressof(this->value()); }
|
|
1246
|
+
|
|
1247
|
+
Value* operator->() { return std::addressof(this->value()); }
|
|
1248
|
+
|
|
1249
|
+
const Value* get_pointer() const& noexcept {
|
|
1250
|
+
return hasValue() ? std::addressof(this->value_) : nullptr;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
Value* get_pointer() & noexcept {
|
|
1254
|
+
return hasValue() ? std::addressof(this->value_) : nullptr;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
Value* get_pointer() && = delete;
|
|
1258
|
+
|
|
1259
|
+
/**
|
|
1260
|
+
* then
|
|
1261
|
+
*/
|
|
1262
|
+
template <class... Fns FOLLY_REQUIRES_TRAILING(sizeof...(Fns) >= 1)>
|
|
1263
|
+
auto then(Fns&&... fns)
|
|
1264
|
+
const& -> decltype(expected_detail::ExpectedHelper::then_(
|
|
1265
|
+
std::declval<const Base&>(), std::declval<Fns>()...)) {
|
|
1266
|
+
if (this->uninitializedByException()) {
|
|
1267
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1268
|
+
}
|
|
1269
|
+
return expected_detail::ExpectedHelper::then_(
|
|
1270
|
+
base(), static_cast<Fns&&>(fns)...);
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
template <class... Fns FOLLY_REQUIRES_TRAILING(sizeof...(Fns) >= 1)>
|
|
1274
|
+
auto then(Fns&&... fns) & -> decltype(expected_detail::ExpectedHelper::then_(
|
|
1275
|
+
std::declval<Base&>(),
|
|
1276
|
+
std::declval<Fns>()...)) {
|
|
1277
|
+
if (this->uninitializedByException()) {
|
|
1278
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1279
|
+
}
|
|
1280
|
+
return expected_detail::ExpectedHelper::then_(
|
|
1281
|
+
base(), static_cast<Fns&&>(fns)...);
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
template <class... Fns FOLLY_REQUIRES_TRAILING(sizeof...(Fns) >= 1)>
|
|
1285
|
+
auto then(Fns&&... fns) && -> decltype(expected_detail::ExpectedHelper::then_(
|
|
1286
|
+
std::declval<Base&&>(),
|
|
1287
|
+
std::declval<Fns>()...)) {
|
|
1288
|
+
if (this->uninitializedByException()) {
|
|
1289
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1290
|
+
}
|
|
1291
|
+
return expected_detail::ExpectedHelper::then_(
|
|
1292
|
+
std::move(base()), static_cast<Fns&&>(fns)...);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
/**
|
|
1296
|
+
* orElse - returns if it has a value, otherwise it calls a function with the
|
|
1297
|
+
* error type
|
|
1298
|
+
*/
|
|
1299
|
+
template <class... Fns FOLLY_REQUIRES_TRAILING(sizeof...(Fns) >= 1)>
|
|
1300
|
+
auto orElse(Fns&&... fns)
|
|
1301
|
+
const& -> decltype(expected_detail::ExpectedHelper::orElse_(
|
|
1302
|
+
std::declval<const Base&>(), std::declval<Fns>()...)) {
|
|
1303
|
+
if (this->uninitializedByException()) {
|
|
1304
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1305
|
+
}
|
|
1306
|
+
return expected_detail::ExpectedHelper::orElse_(
|
|
1307
|
+
base(), static_cast<Fns&&>(fns)...);
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
template <class... Fns FOLLY_REQUIRES_TRAILING(sizeof...(Fns) >= 1)>
|
|
1311
|
+
auto
|
|
1312
|
+
orElse(Fns&&... fns) & -> decltype(expected_detail::ExpectedHelper::orElse_(
|
|
1313
|
+
std::declval<Base&>(), std::declval<Fns>()...)) {
|
|
1314
|
+
if (this->uninitializedByException()) {
|
|
1315
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1316
|
+
}
|
|
1317
|
+
return expected_detail::ExpectedHelper::orElse_(
|
|
1318
|
+
base(), static_cast<Fns&&>(fns)...);
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
template <class... Fns FOLLY_REQUIRES_TRAILING(sizeof...(Fns) >= 1)>
|
|
1322
|
+
auto
|
|
1323
|
+
orElse(Fns&&... fns) && -> decltype(expected_detail::ExpectedHelper::orElse_(
|
|
1324
|
+
std::declval<Base&&>(), std::declval<Fns>()...)) {
|
|
1325
|
+
if (this->uninitializedByException()) {
|
|
1326
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1327
|
+
}
|
|
1328
|
+
return expected_detail::ExpectedHelper::orElse_(
|
|
1329
|
+
std::move(base()), static_cast<Fns&&>(fns)...);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
/**
|
|
1333
|
+
* thenOrThrow
|
|
1334
|
+
*/
|
|
1335
|
+
template <class Yes, class No = MakeBadExpectedAccess>
|
|
1336
|
+
auto thenOrThrow(Yes&& yes, No&& no = No{})
|
|
1337
|
+
const& -> decltype(std::declval<Yes>()(std::declval<const Value&>())) {
|
|
1338
|
+
using Ret = decltype(std::declval<Yes>()(std::declval<const Value&>()));
|
|
1339
|
+
if (this->uninitializedByException()) {
|
|
1340
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1341
|
+
}
|
|
1342
|
+
return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
|
|
1343
|
+
base(), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
template <class Yes, class No = MakeBadExpectedAccess>
|
|
1347
|
+
auto thenOrThrow(Yes&& yes, No&& no = No{}) & -> decltype(std::declval<Yes>()(
|
|
1348
|
+
std::declval<Value&>())) {
|
|
1349
|
+
using Ret = decltype(std::declval<Yes>()(std::declval<Value&>()));
|
|
1350
|
+
if (this->uninitializedByException()) {
|
|
1351
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1352
|
+
}
|
|
1353
|
+
return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
|
|
1354
|
+
base(), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
template <class Yes, class No = MakeBadExpectedAccess>
|
|
1358
|
+
auto thenOrThrow(
|
|
1359
|
+
Yes&& yes,
|
|
1360
|
+
No&& no =
|
|
1361
|
+
No{}) && -> decltype(std::declval<Yes>()(std::declval<Value&&>())) {
|
|
1362
|
+
using Ret = decltype(std::declval<Yes>()(std::declval<Value&&>()));
|
|
1363
|
+
if (this->uninitializedByException()) {
|
|
1364
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1365
|
+
}
|
|
1366
|
+
return Ret(expected_detail::ExpectedHelper::thenOrThrow_(
|
|
1367
|
+
std::move(base()), static_cast<Yes&&>(yes), static_cast<No&&>(no)));
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
/**
|
|
1371
|
+
* onError
|
|
1372
|
+
*/
|
|
1373
|
+
template <class OnError>
|
|
1374
|
+
auto onError(OnError&& onError) const& {
|
|
1375
|
+
if (this->uninitializedByException()) {
|
|
1376
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
return expected_detail::ExpectedHelper::onError_(
|
|
1380
|
+
*this, static_cast<OnError&&>(onError));
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
template <class OnError>
|
|
1384
|
+
auto onError(OnError&& onError) & {
|
|
1385
|
+
if (this->uninitializedByException()) {
|
|
1386
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1387
|
+
}
|
|
1388
|
+
return expected_detail::ExpectedHelper::onError_(
|
|
1389
|
+
*this, static_cast<OnError&&>(onError));
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
template <class OnError>
|
|
1393
|
+
auto onError(OnError&& onError) && {
|
|
1394
|
+
if (this->uninitializedByException()) {
|
|
1395
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1396
|
+
}
|
|
1397
|
+
return expected_detail::ExpectedHelper::onError_(
|
|
1398
|
+
std::move(*this), static_cast<OnError&&>(onError));
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
// Quasi-private, exposed only for implementing efficient short-circuiting
|
|
1402
|
+
// coroutines on top of `Expected`. Do NOT use this instead of
|
|
1403
|
+
// `optional<Expected<>>`, for these reasons:
|
|
1404
|
+
// - This public ctor again become private in the future.
|
|
1405
|
+
// - It is incompatible with upcoming `std::expected`.
|
|
1406
|
+
// - It violates `folly::Expected`'s almost-never-empty guarantee.
|
|
1407
|
+
// - There's no native `empty()` test -- `uninitializedByException()` is
|
|
1408
|
+
// always `false` for some value types, and `!hasValue() && !hasError()`
|
|
1409
|
+
// is less efficient.
|
|
1410
|
+
explicit Expected(expected_detail::EmptyTag tag) noexcept : Base{tag} {}
|
|
1411
|
+
|
|
1412
|
+
private:
|
|
1413
|
+
friend struct expected_detail::PromiseReturn<Value, Error>;
|
|
1414
|
+
|
|
1415
|
+
// for when coroutine promise return-object conversion is eager
|
|
1416
|
+
Expected(expected_detail::EmptyTag tag, Expected*& pointer) noexcept
|
|
1417
|
+
: Base{tag} {
|
|
1418
|
+
pointer = this;
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
void requireValue() const {
|
|
1422
|
+
if (FOLLY_UNLIKELY(!hasValue())) {
|
|
1423
|
+
if (FOLLY_LIKELY(hasError())) {
|
|
1424
|
+
throw_exception<BadExpectedAccess<Error>>(this->error_);
|
|
1425
|
+
}
|
|
1426
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
template <typename Self>
|
|
1431
|
+
static void requireValueMove(Self& self) {
|
|
1432
|
+
if (FOLLY_UNLIKELY(!self.hasValue())) {
|
|
1433
|
+
if (FOLLY_LIKELY(self.hasError())) {
|
|
1434
|
+
throw_exception<BadExpectedAccess<Error>>(std::move(self.error_));
|
|
1435
|
+
}
|
|
1436
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
void requireValueMove() { return requireValueMove(*this); }
|
|
1441
|
+
void requireValueMove() const { return requireValueMove(*this); }
|
|
1442
|
+
|
|
1443
|
+
void requireError() const {
|
|
1444
|
+
if (FOLLY_UNLIKELY(!hasError())) {
|
|
1445
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
expected_detail::Which which() const noexcept { return this->which_; }
|
|
1450
|
+
};
|
|
1451
|
+
|
|
1452
|
+
template <class Value, class Error>
|
|
1453
|
+
inline typename std::enable_if<IsEqualityComparable<Value>::value, bool>::type
|
|
1454
|
+
operator==(
|
|
1455
|
+
const Expected<Value, Error>& lhs, const Expected<Value, Error>& rhs) {
|
|
1456
|
+
if (FOLLY_UNLIKELY(lhs.uninitializedByException())) {
|
|
1457
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1458
|
+
}
|
|
1459
|
+
if (FOLLY_UNLIKELY(lhs.which_ != rhs.which_)) {
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
if (FOLLY_UNLIKELY(lhs.hasError())) {
|
|
1463
|
+
return true; // All error states are considered equal
|
|
1464
|
+
}
|
|
1465
|
+
return lhs.value_ == rhs.value_;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
template <
|
|
1469
|
+
class Value,
|
|
1470
|
+
class Error FOLLY_REQUIRES_TRAILING(IsEqualityComparable<Value>::value)>
|
|
1471
|
+
inline bool operator!=(
|
|
1472
|
+
const Expected<Value, Error>& lhs, const Expected<Value, Error>& rhs) {
|
|
1473
|
+
return !(rhs == lhs);
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
template <class Value, class Error>
|
|
1477
|
+
inline typename std::enable_if<IsLessThanComparable<Value>::value, bool>::type
|
|
1478
|
+
operator<(
|
|
1479
|
+
const Expected<Value, Error>& lhs, const Expected<Value, Error>& rhs) {
|
|
1480
|
+
if (FOLLY_UNLIKELY(
|
|
1481
|
+
lhs.uninitializedByException() || rhs.uninitializedByException())) {
|
|
1482
|
+
throw_exception<BadExpectedAccess<void>>();
|
|
1483
|
+
}
|
|
1484
|
+
if (FOLLY_UNLIKELY(lhs.hasError())) {
|
|
1485
|
+
return !rhs.hasError();
|
|
1486
|
+
}
|
|
1487
|
+
if (FOLLY_UNLIKELY(rhs.hasError())) {
|
|
1488
|
+
return false;
|
|
1489
|
+
}
|
|
1490
|
+
return lhs.value_ < rhs.value_;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
template <
|
|
1494
|
+
class Value,
|
|
1495
|
+
class Error FOLLY_REQUIRES_TRAILING(IsLessThanComparable<Value>::value)>
|
|
1496
|
+
inline bool operator<=(
|
|
1497
|
+
const Expected<Value, Error>& lhs, const Expected<Value, Error>& rhs) {
|
|
1498
|
+
return !(rhs < lhs);
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
template <
|
|
1502
|
+
class Value,
|
|
1503
|
+
class Error FOLLY_REQUIRES_TRAILING(IsLessThanComparable<Value>::value)>
|
|
1504
|
+
inline bool operator>(
|
|
1505
|
+
const Expected<Value, Error>& lhs, const Expected<Value, Error>& rhs) {
|
|
1506
|
+
return rhs < lhs;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
template <
|
|
1510
|
+
class Value,
|
|
1511
|
+
class Error FOLLY_REQUIRES_TRAILING(IsLessThanComparable<Value>::value)>
|
|
1512
|
+
inline bool operator>=(
|
|
1513
|
+
const Expected<Value, Error>& lhs, const Expected<Value, Error>& rhs) {
|
|
1514
|
+
return !(lhs < rhs);
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
/**
|
|
1518
|
+
* swap Expected values
|
|
1519
|
+
*/
|
|
1520
|
+
template <class Value, class Error>
|
|
1521
|
+
void swap(Expected<Value, Error>& lhs, Expected<Value, Error>& rhs) noexcept(
|
|
1522
|
+
std::is_nothrow_swappable_v<Value> && std::is_nothrow_swappable_v<Error>) {
|
|
1523
|
+
lhs.swap(rhs);
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
template <class Value, class Error>
|
|
1527
|
+
const Value* get_pointer(const Expected<Value, Error>& ex) noexcept {
|
|
1528
|
+
return ex.get_pointer();
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
template <class Value, class Error>
|
|
1532
|
+
Value* get_pointer(Expected<Value, Error>& ex) noexcept {
|
|
1533
|
+
return ex.get_pointer();
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
/**
|
|
1537
|
+
* For constructing an Expected object from a value, with the specified
|
|
1538
|
+
* Error type. Usage is as follows:
|
|
1539
|
+
*
|
|
1540
|
+
* enum MyErrorCode { BAD_ERROR, WORSE_ERROR };
|
|
1541
|
+
* Expected<int, MyErrorCode> myAPI() {
|
|
1542
|
+
* int i = // ...;
|
|
1543
|
+
* return i ? makeExpected<MyErrorCode>(i) : makeUnexpected(BAD_ERROR);
|
|
1544
|
+
* }
|
|
1545
|
+
*/
|
|
1546
|
+
template <class Error, class Value>
|
|
1547
|
+
FOLLY_NODISCARD constexpr Expected<typename std::decay<Value>::type, Error>
|
|
1548
|
+
makeExpected(Value&& val) {
|
|
1549
|
+
return Expected<typename std::decay<Value>::type, Error>{
|
|
1550
|
+
std::in_place, static_cast<Value&&>(val)};
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
// Suppress comparability of Optional<T> with T, despite implicit conversion.
|
|
1554
|
+
template <class Value, class Error>
|
|
1555
|
+
bool operator==(const Expected<Value, Error>&, const Value& other) = delete;
|
|
1556
|
+
template <class Value, class Error>
|
|
1557
|
+
bool operator!=(const Expected<Value, Error>&, const Value& other) = delete;
|
|
1558
|
+
template <class Value, class Error>
|
|
1559
|
+
bool operator<(const Expected<Value, Error>&, const Value& other) = delete;
|
|
1560
|
+
template <class Value, class Error>
|
|
1561
|
+
bool operator<=(const Expected<Value, Error>&, const Value& other) = delete;
|
|
1562
|
+
template <class Value, class Error>
|
|
1563
|
+
bool operator>=(const Expected<Value, Error>&, const Value& other) = delete;
|
|
1564
|
+
template <class Value, class Error>
|
|
1565
|
+
bool operator>(const Expected<Value, Error>&, const Value& other) = delete;
|
|
1566
|
+
template <class Value, class Error>
|
|
1567
|
+
bool operator==(const Value& other, const Expected<Value, Error>&) = delete;
|
|
1568
|
+
template <class Value, class Error>
|
|
1569
|
+
bool operator!=(const Value& other, const Expected<Value, Error>&) = delete;
|
|
1570
|
+
template <class Value, class Error>
|
|
1571
|
+
bool operator<(const Value& other, const Expected<Value, Error>&) = delete;
|
|
1572
|
+
template <class Value, class Error>
|
|
1573
|
+
bool operator<=(const Value& other, const Expected<Value, Error>&) = delete;
|
|
1574
|
+
template <class Value, class Error>
|
|
1575
|
+
bool operator>=(const Value& other, const Expected<Value, Error>&) = delete;
|
|
1576
|
+
template <class Value, class Error>
|
|
1577
|
+
bool operator>(const Value& other, const Expected<Value, Error>&) = delete;
|
|
1578
|
+
|
|
1579
|
+
} // namespace folly
|
|
1580
|
+
|
|
1581
|
+
#undef FOLLY_REQUIRES
|
|
1582
|
+
#undef FOLLY_REQUIRES_TRAILING
|
|
1583
|
+
|
|
1584
|
+
// Enable the use of folly::Expected with `co_await`
|
|
1585
|
+
// Inspired by https://github.com/toby-allsopp/coroutine_monad
|
|
1586
|
+
#if FOLLY_HAS_COROUTINES
|
|
1587
|
+
#include <folly/coro/Coroutine.h>
|
|
1588
|
+
|
|
1589
|
+
namespace folly {
|
|
1590
|
+
namespace expected_detail {
|
|
1591
|
+
template <typename Value, typename Error>
|
|
1592
|
+
struct PromiseBase;
|
|
1593
|
+
|
|
1594
|
+
template <typename Value, typename Error>
|
|
1595
|
+
struct PromiseReturn {
|
|
1596
|
+
Expected<Value, Error> storage_{EmptyTag{}};
|
|
1597
|
+
Expected<Value, Error>*& pointer_;
|
|
1598
|
+
|
|
1599
|
+
/* implicit */ PromiseReturn(PromiseBase<Value, Error>& p) noexcept
|
|
1600
|
+
: pointer_{p.value_} {
|
|
1601
|
+
pointer_ = &storage_;
|
|
1602
|
+
}
|
|
1603
|
+
PromiseReturn(PromiseReturn const&) = delete;
|
|
1604
|
+
// letting dtor be trivial makes the coroutine crash
|
|
1605
|
+
// TODO: fix clang/llvm codegen
|
|
1606
|
+
~PromiseReturn() {}
|
|
1607
|
+
/* implicit */ operator Expected<Value, Error>() {
|
|
1608
|
+
// handle both deferred and eager return-object conversion behaviors
|
|
1609
|
+
// see docs for detect_promise_return_object_eager_conversion
|
|
1610
|
+
if (folly::coro::detect_promise_return_object_eager_conversion()) {
|
|
1611
|
+
assert(storage_.which_ == expected_detail::Which::eEmpty);
|
|
1612
|
+
return Expected<Value, Error>{EmptyTag{}, pointer_}; // eager
|
|
1613
|
+
} else {
|
|
1614
|
+
assert(storage_.which_ != expected_detail::Which::eEmpty);
|
|
1615
|
+
return std::move(storage_); // deferred
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
};
|
|
1619
|
+
|
|
1620
|
+
template <typename Value, typename Error>
|
|
1621
|
+
struct PromiseBase {
|
|
1622
|
+
Expected<Value, Error>* value_ = nullptr;
|
|
1623
|
+
|
|
1624
|
+
PromiseBase() = default;
|
|
1625
|
+
PromiseBase(PromiseBase const&) = delete;
|
|
1626
|
+
void operator=(PromiseBase const&) = delete;
|
|
1627
|
+
|
|
1628
|
+
[[nodiscard]] coro::suspend_never initial_suspend() const noexcept {
|
|
1629
|
+
return {};
|
|
1630
|
+
}
|
|
1631
|
+
[[nodiscard]] coro::suspend_never final_suspend() const noexcept {
|
|
1632
|
+
return {};
|
|
1633
|
+
}
|
|
1634
|
+
[[noreturn]] void unhandled_exception() {
|
|
1635
|
+
// Technically, throwing from unhandled_exception is underspecified:
|
|
1636
|
+
// https://github.com/GorNishanov/CoroutineWording/issues/17
|
|
1637
|
+
rethrow_current_exception();
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
PromiseReturn<Value, Error> get_return_object() noexcept { return *this; }
|
|
1641
|
+
};
|
|
1642
|
+
|
|
1643
|
+
template <typename Value>
|
|
1644
|
+
inline constexpr bool ReturnsVoid =
|
|
1645
|
+
std::is_trivial_v<Value> && std::is_empty_v<Value>;
|
|
1646
|
+
|
|
1647
|
+
template <typename Value, typename Error>
|
|
1648
|
+
struct PromiseReturnsValue : public PromiseBase<Value, Error> {
|
|
1649
|
+
template <typename U = Value>
|
|
1650
|
+
void return_value(U&& u) {
|
|
1651
|
+
auto& v = *this->value_;
|
|
1652
|
+
ExpectedHelper::assume_empty(v);
|
|
1653
|
+
v = static_cast<U&&>(u);
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1657
|
+
template <typename Value, typename Error>
|
|
1658
|
+
struct PromiseReturnsVoid : public PromiseBase<Value, Error> {
|
|
1659
|
+
// When the coroutine uses `return;` you can fail via `co_await err`.
|
|
1660
|
+
void return_void() { this->value_->emplace(Value{}); }
|
|
1661
|
+
};
|
|
1662
|
+
|
|
1663
|
+
template <typename Value, typename Error>
|
|
1664
|
+
struct Promise //
|
|
1665
|
+
: conditional_t<
|
|
1666
|
+
ReturnsVoid<Value>,
|
|
1667
|
+
PromiseReturnsVoid<Value, Error>,
|
|
1668
|
+
PromiseReturnsValue<Value, Error>> {};
|
|
1669
|
+
|
|
1670
|
+
template <typename Error>
|
|
1671
|
+
struct UnexpectedAwaitable {
|
|
1672
|
+
Unexpected<Error> o_;
|
|
1673
|
+
|
|
1674
|
+
explicit UnexpectedAwaitable(Unexpected<Error> o) : o_(std::move(o)) {}
|
|
1675
|
+
|
|
1676
|
+
constexpr std::false_type await_ready() const noexcept { return {}; }
|
|
1677
|
+
void await_resume() { compiler_may_unsafely_assume_unreachable(); }
|
|
1678
|
+
|
|
1679
|
+
template <typename U>
|
|
1680
|
+
FOLLY_ALWAYS_INLINE void await_suspend(
|
|
1681
|
+
coro::coroutine_handle<Promise<U, Error>> h) {
|
|
1682
|
+
auto& v = *h.promise().value_;
|
|
1683
|
+
ExpectedHelper::assume_empty(v);
|
|
1684
|
+
v = std::move(o_);
|
|
1685
|
+
h.destroy();
|
|
1686
|
+
}
|
|
1687
|
+
};
|
|
1688
|
+
|
|
1689
|
+
template <typename Value, typename Error>
|
|
1690
|
+
struct ExpectedAwaitable {
|
|
1691
|
+
Expected<Value, Error> o_;
|
|
1692
|
+
|
|
1693
|
+
explicit ExpectedAwaitable(Expected<Value, Error> o) : o_(std::move(o)) {}
|
|
1694
|
+
|
|
1695
|
+
bool await_ready() const noexcept { return o_.hasValue(); }
|
|
1696
|
+
Value await_resume() { return std::move(o_.value()); }
|
|
1697
|
+
|
|
1698
|
+
// Explicitly only allow suspension into a Promise
|
|
1699
|
+
template <typename U>
|
|
1700
|
+
FOLLY_ALWAYS_INLINE void await_suspend(
|
|
1701
|
+
coro::coroutine_handle<Promise<U, Error>> h) {
|
|
1702
|
+
auto& v = *h.promise().value_;
|
|
1703
|
+
ExpectedHelper::assume_empty(v);
|
|
1704
|
+
v = makeUnexpected(std::move(o_.error()));
|
|
1705
|
+
// Abort the rest of the coroutine. resume() is not going to be called
|
|
1706
|
+
h.destroy();
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
|
|
1710
|
+
} // namespace expected_detail
|
|
1711
|
+
|
|
1712
|
+
template <typename Error>
|
|
1713
|
+
expected_detail::UnexpectedAwaitable<Error>
|
|
1714
|
+
/* implicit */ operator co_await(Unexpected<Error> o) {
|
|
1715
|
+
return expected_detail::UnexpectedAwaitable<Error>{std::move(o)};
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
template <typename Value, typename Error>
|
|
1719
|
+
expected_detail::ExpectedAwaitable<Value, Error>
|
|
1720
|
+
/* implicit */ operator co_await(Expected<Value, Error> o) {
|
|
1721
|
+
return expected_detail::ExpectedAwaitable<Value, Error>{std::move(o)};
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
} // namespace folly
|
|
1725
|
+
#endif // FOLLY_HAS_COROUTINES
|