react-native-windows 0.84.0 → 0.84.2

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.
Files changed (923) hide show
  1. package/Directory.Build.props +2 -17
  2. package/Folly/ThreadNameStub.cpp +4 -6
  3. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +1 -1
  4. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +1 -7
  5. package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj.filters +0 -3
  6. package/PropertySheets/CIBuildOptimizations.props +2 -2
  7. package/PropertySheets/Generated/PackageVersion.g.props +3 -3
  8. package/PropertySheets/JSEngine.props +1 -1
  9. package/PropertySheets/NuGet.LockFile.props +10 -1
  10. package/PropertySheets/React.Cpp.props +3 -3
  11. package/PropertySheets/WinUI.props +2 -1
  12. package/ReactCommon/ReactCommon.vcxproj +0 -5
  13. package/Scripts/EnableInternalWinAppSDKFeed.ps1 +12 -5
  14. package/Scripts/NuGetRestoreForceEvaluateAllSolutions.ps1 +61 -6
  15. package/Scripts/Tfs/Layout-Desktop-Headers.ps1 +4 -37
  16. package/Scripts/UpdateNightlyDependencies.ps1 +47 -0
  17. package/Scripts/creaternwapp.cmd +5 -8
  18. package/Scripts/creaternwlib.cmd +10 -23
  19. package/Shared/Shared.vcxitems +2 -0
  20. package/{Folly → external}/.clang-format +0 -1
  21. package/external/External.vcxitems +10 -0
  22. package/external/fast-float/.syncignore +10 -0
  23. package/external/fast-float/LICENSE-APACHE +190 -0
  24. package/external/fast-float/LICENSE-BOOST +23 -0
  25. package/external/fast-float/LICENSE-MIT +27 -0
  26. package/external/fast-float/README.md +545 -0
  27. package/external/fast-float/cgmanifest.json +15 -0
  28. package/external/fast-float/fast-float.vcxitems +14 -0
  29. package/external/fast-float/include/fast_float/ascii_number.h +588 -0
  30. package/external/fast-float/include/fast_float/bigint.h +638 -0
  31. package/external/fast-float/include/fast_float/constexpr_feature_detect.h +46 -0
  32. package/external/fast-float/include/fast_float/decimal_to_binary.h +212 -0
  33. package/external/fast-float/include/fast_float/digit_comparison.h +457 -0
  34. package/external/fast-float/include/fast_float/fast_float.h +59 -0
  35. package/external/fast-float/include/fast_float/fast_table.h +708 -0
  36. package/external/fast-float/include/fast_float/float_common.h +1240 -0
  37. package/external/fast-float/include/fast_float/parse_number.h +399 -0
  38. package/external/fast-float/sync-config.json +8 -0
  39. package/external/fmt/.syncignore +10 -0
  40. package/external/fmt/CONTRIBUTING.md +20 -0
  41. package/external/fmt/LICENSE +27 -0
  42. package/external/fmt/README.md +484 -0
  43. package/external/fmt/doc/ChangeLog-old.md +3290 -0
  44. package/external/fmt/doc/api.md +650 -0
  45. package/external/fmt/doc/fmt.css +61 -0
  46. package/external/fmt/doc/fmt.js +4 -0
  47. package/external/fmt/doc/get-started.md +222 -0
  48. package/external/fmt/doc/index.md +151 -0
  49. package/external/fmt/doc/perf.svg +1 -0
  50. package/external/fmt/doc/python-license.txt +290 -0
  51. package/external/fmt/doc/syntax.md +887 -0
  52. package/external/fmt/fmt.vcxitems +28 -0
  53. package/external/fmt/include/fmt/args.h +228 -0
  54. package/external/fmt/include/fmt/base.h +3077 -0
  55. package/external/fmt/include/fmt/chrono.h +2432 -0
  56. package/external/fmt/include/fmt/color.h +612 -0
  57. package/external/fmt/include/fmt/compile.h +529 -0
  58. package/external/fmt/include/fmt/core.h +5 -0
  59. package/external/fmt/include/fmt/format-inl.h +1928 -0
  60. package/external/fmt/include/fmt/format.h +4427 -0
  61. package/external/fmt/include/fmt/os.h +439 -0
  62. package/external/fmt/include/fmt/ostream.h +211 -0
  63. package/external/fmt/include/fmt/printf.h +656 -0
  64. package/external/fmt/include/fmt/ranges.h +882 -0
  65. package/external/fmt/include/fmt/std.h +699 -0
  66. package/external/fmt/include/fmt/xchar.h +322 -0
  67. package/external/fmt/src/fmt.cc +135 -0
  68. package/external/fmt/src/format.cc +43 -0
  69. package/external/fmt/src/os.cc +403 -0
  70. package/external/fmt/sync-config.json +8 -0
  71. package/external/folly/.syncignore +60 -0
  72. package/external/folly/LICENSE +200 -0
  73. package/external/folly/README.md +263 -0
  74. package/{fmt → external/folly/folly}/.clang-format +0 -1
  75. package/external/folly/folly/AtomicHashArray-inl.h +546 -0
  76. package/external/folly/folly/AtomicHashArray.h +431 -0
  77. package/external/folly/folly/AtomicHashMap-inl.h +653 -0
  78. package/external/folly/folly/AtomicHashMap.h +484 -0
  79. package/external/folly/folly/AtomicIntrusiveLinkedList.h +206 -0
  80. package/external/folly/folly/AtomicLinkedList.h +110 -0
  81. package/external/folly/folly/AtomicUnorderedMap.h +522 -0
  82. package/external/folly/folly/BUCK +1631 -0
  83. package/external/folly/folly/BUILD_MODE.bzl +72 -0
  84. package/external/folly/folly/Benchmark.cpp +986 -0
  85. package/external/folly/folly/Benchmark.h +680 -0
  86. package/external/folly/folly/BenchmarkUtil.h +47 -0
  87. package/external/folly/folly/Bits.h +17 -0
  88. package/external/folly/folly/CMakeLists.txt +110 -0
  89. package/external/folly/folly/CPortability.h +338 -0
  90. package/external/folly/folly/CancellationToken-inl.h +449 -0
  91. package/external/folly/folly/CancellationToken.cpp +250 -0
  92. package/external/folly/folly/CancellationToken.h +365 -0
  93. package/external/folly/folly/Chrono.h +132 -0
  94. package/external/folly/folly/ClockGettimeWrappers.cpp +93 -0
  95. package/external/folly/folly/ClockGettimeWrappers.h +29 -0
  96. package/external/folly/folly/ConcurrentBitSet.h +157 -0
  97. package/external/folly/folly/ConcurrentLazy.h +74 -0
  98. package/external/folly/folly/ConcurrentSkipList-inl.h +341 -0
  99. package/external/folly/folly/ConcurrentSkipList.h +824 -0
  100. package/external/folly/folly/ConstructorCallbackList.h +158 -0
  101. package/external/folly/folly/Conv.h +2026 -0
  102. package/external/folly/folly/CppAttributes.h +170 -0
  103. package/external/folly/folly/CpuId.h +297 -0
  104. package/external/folly/folly/DefaultKeepAliveExecutor.h +172 -0
  105. package/external/folly/folly/Demangle.cpp +255 -0
  106. package/external/folly/folly/Demangle.h +73 -0
  107. package/external/folly/folly/DiscriminatedPtr.h +236 -0
  108. package/external/folly/folly/DynamicConverter.h +17 -0
  109. package/external/folly/folly/Exception.h +150 -0
  110. package/external/folly/folly/ExceptionString.cpp +51 -0
  111. package/external/folly/folly/ExceptionString.h +33 -0
  112. package/external/folly/folly/ExceptionWrapper-inl.h +264 -0
  113. package/external/folly/folly/ExceptionWrapper.cpp +37 -0
  114. package/external/folly/folly/ExceptionWrapper.h +377 -0
  115. package/external/folly/folly/Executor.cpp +111 -0
  116. package/external/folly/folly/Executor.h +351 -0
  117. package/external/folly/folly/Expected.h +1725 -0
  118. package/external/folly/folly/FBString.h +2888 -0
  119. package/external/folly/folly/FBVector.h +17 -0
  120. package/external/folly/folly/File.cpp +180 -0
  121. package/external/folly/folly/File.h +177 -0
  122. package/external/folly/folly/FileUtil.cpp +378 -0
  123. package/external/folly/folly/FileUtil.h +332 -0
  124. package/external/folly/folly/Fingerprint.cpp +135 -0
  125. package/external/folly/folly/Fingerprint.h +289 -0
  126. package/external/folly/folly/FixedString.h +2965 -0
  127. package/external/folly/folly/FollyMemcpy.cpp +30 -0
  128. package/external/folly/folly/FollyMemcpy.h +23 -0
  129. package/external/folly/folly/FollyMemset.cpp +29 -0
  130. package/external/folly/folly/FollyMemset.h +25 -0
  131. package/external/folly/folly/Format-inl.h +1152 -0
  132. package/external/folly/folly/Format.cpp +429 -0
  133. package/external/folly/folly/Format.h +463 -0
  134. package/external/folly/folly/FormatArg.h +285 -0
  135. package/external/folly/folly/FormatTraits.h +65 -0
  136. package/external/folly/folly/Function.h +1159 -0
  137. package/external/folly/folly/GLog.h +85 -0
  138. package/external/folly/folly/GroupVarint.cpp +153 -0
  139. package/external/folly/folly/GroupVarint.h +630 -0
  140. package/external/folly/folly/Hash.h +20 -0
  141. package/external/folly/folly/IPAddress.cpp +490 -0
  142. package/external/folly/folly/IPAddress.h +667 -0
  143. package/external/folly/folly/IPAddressException.h +82 -0
  144. package/external/folly/folly/IPAddressV4.cpp +305 -0
  145. package/external/folly/folly/IPAddressV4.h +495 -0
  146. package/external/folly/folly/IPAddressV6.cpp +541 -0
  147. package/external/folly/folly/IPAddressV6.h +627 -0
  148. package/external/folly/folly/Indestructible.h +164 -0
  149. package/external/folly/folly/IndexedMemPool.h +550 -0
  150. package/external/folly/folly/IntrusiveList.h +17 -0
  151. package/external/folly/folly/Lazy.h +142 -0
  152. package/external/folly/folly/Likely.h +76 -0
  153. package/external/folly/folly/MPMCPipeline.h +280 -0
  154. package/external/folly/folly/MPMCQueue.h +1556 -0
  155. package/external/folly/folly/MacAddress.cpp +188 -0
  156. package/external/folly/folly/MacAddress.h +260 -0
  157. package/external/folly/folly/MapUtil.h +17 -0
  158. package/external/folly/folly/Math.h +258 -0
  159. package/external/folly/folly/MaybeManagedPtr.h +120 -0
  160. package/external/folly/folly/Memory.h +900 -0
  161. package/external/folly/folly/MicroLock.cpp +76 -0
  162. package/external/folly/folly/MicroLock.h +354 -0
  163. package/external/folly/folly/MicroSpinLock.h +17 -0
  164. package/external/folly/folly/MoveWrapper.h +76 -0
  165. package/external/folly/folly/ObserverContainer.h +1026 -0
  166. package/external/folly/folly/Optional.h +743 -0
  167. package/external/folly/folly/Overload.h +325 -0
  168. package/external/folly/folly/PackedSyncPtr.h +147 -0
  169. package/external/folly/folly/Padded.h +464 -0
  170. package/external/folly/folly/Poly-inl.h +230 -0
  171. package/external/folly/folly/Poly.h +1095 -0
  172. package/external/folly/folly/PolyException.h +43 -0
  173. package/external/folly/folly/Portability.h +644 -0
  174. package/external/folly/folly/Preprocessor.h +236 -0
  175. package/external/folly/folly/ProducerConsumerQueue.h +182 -0
  176. package/external/folly/folly/RWSpinLock.h +17 -0
  177. package/external/folly/folly/Random-inl.h +86 -0
  178. package/external/folly/folly/Random.cpp +184 -0
  179. package/external/folly/folly/Random.h +434 -0
  180. package/external/folly/folly/Range.h +1772 -0
  181. package/external/folly/folly/Replaceable.h +636 -0
  182. package/external/folly/folly/ScopeGuard.cpp +29 -0
  183. package/external/folly/folly/ScopeGuard.h +420 -0
  184. package/external/folly/folly/SharedMutex.cpp +81 -0
  185. package/external/folly/folly/SharedMutex.h +1751 -0
  186. package/external/folly/folly/Singleton-inl.h +332 -0
  187. package/external/folly/folly/Singleton.cpp +512 -0
  188. package/external/folly/folly/Singleton.h +891 -0
  189. package/external/folly/folly/SingletonThreadLocal.cpp +53 -0
  190. package/external/folly/folly/SingletonThreadLocal.h +263 -0
  191. package/external/folly/folly/SocketAddress.cpp +786 -0
  192. package/external/folly/folly/SocketAddress.h +768 -0
  193. package/external/folly/folly/SpinLock.h +55 -0
  194. package/external/folly/folly/String-inl.h +668 -0
  195. package/external/folly/folly/String.cpp +777 -0
  196. package/external/folly/folly/String.h +767 -0
  197. package/external/folly/folly/Subprocess.cpp +1142 -0
  198. package/external/folly/folly/Subprocess.h +1055 -0
  199. package/external/folly/folly/Synchronized.h +1833 -0
  200. package/external/folly/folly/SynchronizedPtr.h +106 -0
  201. package/external/folly/folly/ThreadCachedInt.h +175 -0
  202. package/external/folly/folly/ThreadLocal.h +478 -0
  203. package/external/folly/folly/TimeoutQueue.cpp +78 -0
  204. package/external/folly/folly/TimeoutQueue.h +123 -0
  205. package/external/folly/folly/TokenBucket.h +673 -0
  206. package/external/folly/folly/Traits.h +1442 -0
  207. package/external/folly/folly/Try-inl.h +372 -0
  208. package/external/folly/folly/Try.cpp +23 -0
  209. package/external/folly/folly/Try.h +728 -0
  210. package/external/folly/folly/UTF8String.h +56 -0
  211. package/external/folly/folly/Unicode.cpp +201 -0
  212. package/external/folly/folly/Unicode.h +94 -0
  213. package/external/folly/folly/Unit.h +65 -0
  214. package/external/folly/folly/Uri-inl.h +101 -0
  215. package/external/folly/folly/Uri.cpp +190 -0
  216. package/external/folly/folly/Uri.h +142 -0
  217. package/external/folly/folly/Utility.h +932 -0
  218. package/external/folly/folly/VERSION +1 -0
  219. package/external/folly/folly/Varint.h +230 -0
  220. package/external/folly/folly/VirtualExecutor.h +17 -0
  221. package/external/folly/folly/algorithm/simd/BUCK +47 -0
  222. package/external/folly/folly/algorithm/simd/Contains.cpp +42 -0
  223. package/external/folly/folly/algorithm/simd/Contains.h +116 -0
  224. package/external/folly/folly/algorithm/simd/FindFixed.h +301 -0
  225. package/external/folly/folly/algorithm/simd/Ignore.h +52 -0
  226. package/external/folly/folly/algorithm/simd/Movemask.h +207 -0
  227. package/external/folly/folly/algorithm/simd/detail/BUCK +70 -0
  228. package/external/folly/folly/algorithm/simd/detail/ContainsImpl.h +91 -0
  229. package/external/folly/folly/algorithm/simd/detail/SimdAnyOf.h +83 -0
  230. package/external/folly/folly/algorithm/simd/detail/SimdForEach.h +209 -0
  231. package/external/folly/folly/algorithm/simd/detail/SimdPlatform.h +445 -0
  232. package/external/folly/folly/algorithm/simd/detail/Traits.h +125 -0
  233. package/external/folly/folly/algorithm/simd/detail/UnrollUtils.h +126 -0
  234. package/external/folly/folly/base64.h +264 -0
  235. package/external/folly/folly/chrono/BUCK +29 -0
  236. package/external/folly/folly/chrono/Clock.h +65 -0
  237. package/external/folly/folly/chrono/Conv.h +712 -0
  238. package/external/folly/folly/chrono/test/BUCK +26 -0
  239. package/external/folly/folly/chrono/test/ClockTest.cpp +68 -0
  240. package/external/folly/folly/chrono/test/ConvTest.cpp +652 -0
  241. package/external/folly/folly/concurrency/AtomicSharedPtr.h +387 -0
  242. package/external/folly/folly/concurrency/BUCK +170 -0
  243. package/external/folly/folly/concurrency/CacheLocality.h +460 -0
  244. package/external/folly/folly/concurrency/ConcurrentHashMap.h +822 -0
  245. package/external/folly/folly/concurrency/CoreCachedSharedPtr.h +232 -0
  246. package/external/folly/folly/concurrency/DeadlockDetector.cpp +27 -0
  247. package/external/folly/folly/concurrency/DeadlockDetector.h +44 -0
  248. package/external/folly/folly/concurrency/DynamicBoundedQueue.h +751 -0
  249. package/external/folly/folly/concurrency/PriorityUnboundedQueueSet.h +207 -0
  250. package/external/folly/folly/concurrency/ProcessLocalUniqueId.cpp +46 -0
  251. package/external/folly/folly/concurrency/ProcessLocalUniqueId.h +38 -0
  252. package/external/folly/folly/concurrency/SingletonRelaxedCounter.h +325 -0
  253. package/external/folly/folly/concurrency/ThreadCachedSynchronized.h +227 -0
  254. package/external/folly/folly/concurrency/UnboundedQueue.h +891 -0
  255. package/external/folly/folly/concurrency/container/BUCK +77 -0
  256. package/external/folly/folly/concurrency/container/FlatCombiningPriorityQueue.h +426 -0
  257. package/external/folly/folly/concurrency/container/LockFreeRingBuffer.h +306 -0
  258. package/external/folly/folly/concurrency/container/RelaxedConcurrentPriorityQueue.h +1212 -0
  259. package/external/folly/folly/concurrency/container/SingleWriterFixedHashMap.h +322 -0
  260. package/external/folly/folly/concurrency/container/atomic_grow_array.h +564 -0
  261. package/external/folly/folly/concurrency/container/test/BUCK +75 -0
  262. package/external/folly/folly/concurrency/container/test/FlatCombiningPriorityQueueTest.cpp +570 -0
  263. package/external/folly/folly/concurrency/container/test/LockFreeRingBufferTest.cpp +276 -0
  264. package/external/folly/folly/concurrency/container/test/RelaxedConcurrentPriorityQueueTest.cpp +1570 -0
  265. package/external/folly/folly/concurrency/container/test/SingleWriterFixedHashMapTest.cpp +401 -0
  266. package/external/folly/folly/concurrency/container/test/atomic_grow_array_test.cpp +187 -0
  267. package/external/folly/folly/concurrency/detail/AtomicSharedPtr-detail.h +212 -0
  268. package/external/folly/folly/concurrency/detail/ConcurrentHashMap-detail.h +1911 -0
  269. package/external/folly/folly/concurrency/memory/AtomicReadMostlyMainPtr.cpp +43 -0
  270. package/external/folly/folly/concurrency/memory/AtomicReadMostlyMainPtr.h +190 -0
  271. package/external/folly/folly/concurrency/memory/BUCK +53 -0
  272. package/external/folly/folly/concurrency/memory/PrimaryPtr.h +338 -0
  273. package/external/folly/folly/concurrency/memory/ReadMostlySharedPtr.h +511 -0
  274. package/external/folly/folly/concurrency/memory/TLRefCount.h +228 -0
  275. package/external/folly/folly/concurrency/memory/test/AtomicReadMostlyMainPtrBenchmark.cpp +56 -0
  276. package/external/folly/folly/concurrency/memory/test/AtomicReadMostlyMainPtrTest.cpp +454 -0
  277. package/external/folly/folly/concurrency/memory/test/BUCK +95 -0
  278. package/external/folly/folly/concurrency/memory/test/PrimaryPtrTest.cpp +303 -0
  279. package/external/folly/folly/concurrency/memory/test/ReadMostlySharedPtrBenchmark.cpp +138 -0
  280. package/external/folly/folly/concurrency/memory/test/ReadMostlySharedPtrStressTest.cpp +75 -0
  281. package/external/folly/folly/concurrency/memory/test/ReadMostlySharedPtrTest.cpp +378 -0
  282. package/external/folly/folly/concurrency/memory/test/RefCountBenchmark.cpp +90 -0
  283. package/external/folly/folly/concurrency/memory/test/RefCountTest.cpp +168 -0
  284. package/external/folly/folly/concurrency/test/AtomicSharedPtrCounted.h +156 -0
  285. package/external/folly/folly/concurrency/test/AtomicSharedPtrPerformance.cpp +255 -0
  286. package/external/folly/folly/concurrency/test/AtomicSharedPtrTest.cpp +257 -0
  287. package/external/folly/folly/concurrency/test/BUCK +229 -0
  288. package/external/folly/folly/concurrency/test/CacheLocalityBenchmark.cpp +392 -0
  289. package/external/folly/folly/concurrency/test/CacheLocalityTest.cpp +1229 -0
  290. package/external/folly/folly/concurrency/test/ConcurrentHashMapBench.cpp +260 -0
  291. package/external/folly/folly/concurrency/test/ConcurrentHashMapTest.cpp +1242 -0
  292. package/external/folly/folly/concurrency/test/CoreCachedSharedPtrTest.cpp +408 -0
  293. package/external/folly/folly/concurrency/test/DynamicBoundedQueueTest.cpp +984 -0
  294. package/external/folly/folly/concurrency/test/PriorityUnboundedQueueSetTest.cpp +73 -0
  295. package/external/folly/folly/concurrency/test/ProcessLocalUniqueIdTest.cpp +66 -0
  296. package/external/folly/folly/concurrency/test/SingletonRelaxedCounterBench.cpp +101 -0
  297. package/external/folly/folly/concurrency/test/SingletonRelaxedCounterTest.cpp +185 -0
  298. package/external/folly/folly/concurrency/test/ThreadCachedSynchronizedBench.cpp +76 -0
  299. package/external/folly/folly/concurrency/test/ThreadCachedSynchronizedTest.cpp +93 -0
  300. package/external/folly/folly/concurrency/test/UnboundedQueueTest.cpp +1302 -0
  301. package/external/folly/folly/container/Access.h +57 -0
  302. package/external/folly/folly/container/Array.h +87 -0
  303. package/external/folly/folly/container/BUCK +353 -0
  304. package/external/folly/folly/container/BitIterator.h +203 -0
  305. package/external/folly/folly/container/Enumerate.h +162 -0
  306. package/external/folly/folly/container/EvictingCacheMap.h +730 -0
  307. package/external/folly/folly/container/F14.md +300 -0
  308. package/external/folly/folly/container/F14Map-fwd.h +113 -0
  309. package/external/folly/folly/container/F14Map.h +2108 -0
  310. package/external/folly/folly/container/F14Set-fwd.h +95 -0
  311. package/external/folly/folly/container/F14Set.h +1603 -0
  312. package/external/folly/folly/container/FBVector.h +1711 -0
  313. package/external/folly/folly/container/Foreach-inl.h +316 -0
  314. package/external/folly/folly/container/Foreach.h +209 -0
  315. package/external/folly/folly/container/HeterogeneousAccess-fwd.h +33 -0
  316. package/external/folly/folly/container/HeterogeneousAccess.h +171 -0
  317. package/external/folly/folly/container/IntrusiveHeap.h +268 -0
  318. package/external/folly/folly/container/IntrusiveList.h +131 -0
  319. package/external/folly/folly/container/Iterator.h +843 -0
  320. package/external/folly/folly/container/MapUtil.h +376 -0
  321. package/external/folly/folly/container/Merge.h +90 -0
  322. package/external/folly/folly/container/RegexMatchCache.cpp +521 -0
  323. package/external/folly/folly/container/RegexMatchCache.h +699 -0
  324. package/external/folly/folly/container/Reserve.h +109 -0
  325. package/external/folly/folly/container/SparseByteSet.h +123 -0
  326. package/external/folly/folly/container/View.h +81 -0
  327. package/external/folly/folly/container/WeightedEvictingCacheMap.h +651 -0
  328. package/external/folly/folly/container/detail/BUCK +115 -0
  329. package/external/folly/folly/container/detail/BitIteratorDetail.h +87 -0
  330. package/external/folly/folly/container/detail/F14Defaults.h +34 -0
  331. package/external/folly/folly/container/detail/F14IntrinsicsAvailability.h +67 -0
  332. package/external/folly/folly/container/detail/F14MapFallback.h +717 -0
  333. package/external/folly/folly/container/detail/F14Mask.h +235 -0
  334. package/external/folly/folly/container/detail/F14Policy.h +1523 -0
  335. package/external/folly/folly/container/detail/F14SetFallback.h +528 -0
  336. package/external/folly/folly/container/detail/F14Table.cpp +71 -0
  337. package/external/folly/folly/container/detail/F14Table.h +2680 -0
  338. package/external/folly/folly/container/detail/Util.h +303 -0
  339. package/external/folly/folly/container/detail/tape_detail.h +135 -0
  340. package/external/folly/folly/container/detail/test/BUCK +14 -0
  341. package/external/folly/folly/container/detail/test/F14DetailTest.cpp +47 -0
  342. package/external/folly/folly/container/heap_vector_types.h +1683 -0
  343. package/external/folly/folly/container/range_traits.h +81 -0
  344. package/external/folly/folly/container/small_vector.h +1476 -0
  345. package/external/folly/folly/container/sorted_vector_types.h +1652 -0
  346. package/external/folly/folly/container/span.h +408 -0
  347. package/external/folly/folly/container/tape.h +608 -0
  348. package/external/folly/folly/container/test/.clang-tidy +12 -0
  349. package/external/folly/folly/container/test/AccessTest.cpp +138 -0
  350. package/external/folly/folly/container/test/ArrayTest.cpp +84 -0
  351. package/external/folly/folly/container/test/BUCK +568 -0
  352. package/external/folly/folly/container/test/BitIteratorBench.cpp +112 -0
  353. package/external/folly/folly/container/test/BitIteratorTest.cpp +109 -0
  354. package/external/folly/folly/container/test/EnumerateTest.cpp +294 -0
  355. package/external/folly/folly/container/test/EvictingCacheMapBench.cpp +80 -0
  356. package/external/folly/folly/container/test/EvictingCacheMapTest.cpp +842 -0
  357. package/external/folly/folly/container/test/F14AsanSupportTest.cpp +143 -0
  358. package/external/folly/folly/container/test/F14FwdTest.cpp +37 -0
  359. package/external/folly/folly/container/test/F14InterprocessTest.cpp +404 -0
  360. package/external/folly/folly/container/test/F14MapTest.cpp +2543 -0
  361. package/external/folly/folly/container/test/F14PolicyTest.cpp +49 -0
  362. package/external/folly/folly/container/test/F14SetTest.cpp +1738 -0
  363. package/external/folly/folly/container/test/F14SmallOverheads.cpp +215 -0
  364. package/external/folly/folly/container/test/F14TestUtil.h +117 -0
  365. package/external/folly/folly/container/test/FBVectorBenchmark.cpp +380 -0
  366. package/external/folly/folly/container/test/FBVectorBenchmarks.cpp.h +100 -0
  367. package/external/folly/folly/container/test/FBVectorTest.cpp +326 -0
  368. package/external/folly/folly/container/test/FBVectorTests.cpp.h +304 -0
  369. package/external/folly/folly/container/test/ForeachBenchmark.cpp +388 -0
  370. package/external/folly/folly/container/test/ForeachTest.cpp +338 -0
  371. package/external/folly/folly/container/test/HashMapsBench.cpp +458 -0
  372. package/external/folly/folly/container/test/HeterogeneousAccessTest.cpp +242 -0
  373. package/external/folly/folly/container/test/IntrusiveHeapTest.cpp +262 -0
  374. package/external/folly/folly/container/test/IteratorTest.cpp +989 -0
  375. package/external/folly/folly/container/test/MapUtilTest.cpp +365 -0
  376. package/external/folly/folly/container/test/MergeTest.cpp +66 -0
  377. package/external/folly/folly/container/test/RegexMatchCacheTest.cpp +634 -0
  378. package/external/folly/folly/container/test/ReserveTest.cpp +173 -0
  379. package/external/folly/folly/container/test/SparseByteSetBenchmark.cpp +153 -0
  380. package/external/folly/folly/container/test/SparseByteSetTest.cpp +117 -0
  381. package/external/folly/folly/container/test/TrackingTypes.h +584 -0
  382. package/external/folly/folly/container/test/UtilTest.cpp +609 -0
  383. package/external/folly/folly/container/test/WeightedEvictingCacheMapTest.cpp +800 -0
  384. package/external/folly/folly/container/test/heap_vector_types_test.cpp +1774 -0
  385. package/external/folly/folly/container/test/range_traits_test.cpp +59 -0
  386. package/external/folly/folly/container/test/small_vector_test.cpp +1571 -0
  387. package/external/folly/folly/container/test/sorted_vector_test.cpp +1589 -0
  388. package/external/folly/folly/container/test/span_test.cpp +520 -0
  389. package/external/folly/folly/container/test/tape_bench.cpp +200 -0
  390. package/external/folly/folly/container/test/tape_test.cpp +590 -0
  391. package/external/folly/folly/defs.bzl +238 -0
  392. package/external/folly/folly/detail/AsyncTrace.cpp +36 -0
  393. package/external/folly/folly/detail/AsyncTrace.h +44 -0
  394. package/external/folly/folly/detail/AtomicHashUtils.h +42 -0
  395. package/external/folly/folly/detail/AtomicUnorderedMapUtils.h +80 -0
  396. package/external/folly/folly/detail/BUCK +406 -0
  397. package/external/folly/folly/detail/DiscriminatedPtrDetail.h +172 -0
  398. package/external/folly/folly/detail/FileUtilDetail.cpp +63 -0
  399. package/external/folly/folly/detail/FileUtilDetail.h +85 -0
  400. package/external/folly/folly/detail/FileUtilVectorDetail.h +81 -0
  401. package/external/folly/folly/detail/FingerprintPolynomial.h +132 -0
  402. package/external/folly/folly/detail/Futex-inl.h +123 -0
  403. package/external/folly/folly/detail/Futex.cpp +273 -0
  404. package/external/folly/folly/detail/Futex.h +109 -0
  405. package/external/folly/folly/detail/GroupVarintDetail.h +101 -0
  406. package/external/folly/folly/detail/IPAddress.cpp +37 -0
  407. package/external/folly/folly/detail/IPAddress.h +57 -0
  408. package/external/folly/folly/detail/IPAddressSource.h +278 -0
  409. package/external/folly/folly/detail/Iterators.h +156 -0
  410. package/external/folly/folly/detail/MPMCPipelineDetail.h +122 -0
  411. package/external/folly/folly/detail/MemoryIdler.cpp +233 -0
  412. package/external/folly/folly/detail/MemoryIdler.h +216 -0
  413. package/external/folly/folly/detail/PerfScoped.cpp +112 -0
  414. package/external/folly/folly/detail/PerfScoped.h +70 -0
  415. package/external/folly/folly/detail/PolyDetail.h +921 -0
  416. package/external/folly/folly/detail/RangeCommon.cpp +55 -0
  417. package/external/folly/folly/detail/RangeCommon.h +93 -0
  418. package/external/folly/folly/detail/RangeSse42.cpp +198 -0
  419. package/external/folly/folly/detail/RangeSse42.h +30 -0
  420. package/external/folly/folly/detail/SimpleSimdStringUtils.cpp +31 -0
  421. package/external/folly/folly/detail/SimpleSimdStringUtils.h +27 -0
  422. package/external/folly/folly/detail/SimpleSimdStringUtilsImpl.h +63 -0
  423. package/external/folly/folly/detail/Singleton.h +34 -0
  424. package/external/folly/folly/detail/SlowFingerprint.h +90 -0
  425. package/external/folly/folly/detail/SocketFastOpen.cpp +175 -0
  426. package/external/folly/folly/detail/SocketFastOpen.h +89 -0
  427. package/external/folly/folly/detail/SplitStringSimd.cpp +84 -0
  428. package/external/folly/folly/detail/SplitStringSimd.h +151 -0
  429. package/external/folly/folly/detail/SplitStringSimdImpl.h +149 -0
  430. package/external/folly/folly/detail/Sse.cpp +35 -0
  431. package/external/folly/folly/detail/Sse.h +45 -0
  432. package/external/folly/folly/detail/StaticSingletonManager.cpp +119 -0
  433. package/external/folly/folly/detail/StaticSingletonManager.h +298 -0
  434. package/external/folly/folly/detail/ThreadLocalDetail.cpp +492 -0
  435. package/external/folly/folly/detail/ThreadLocalDetail.h +800 -0
  436. package/external/folly/folly/detail/TrapOnAvx512.cpp +41 -0
  437. package/external/folly/folly/detail/TrapOnAvx512.h +21 -0
  438. package/external/folly/folly/detail/TurnSequencer.h +295 -0
  439. package/external/folly/folly/detail/TypeList.h +551 -0
  440. package/external/folly/folly/detail/UniqueInstance.cpp +136 -0
  441. package/external/folly/folly/detail/UniqueInstance.h +68 -0
  442. package/external/folly/folly/detail/base64_detail/BUCK +102 -0
  443. package/external/folly/folly/detail/base64_detail/Base64Api.cpp +40 -0
  444. package/external/folly/folly/detail/base64_detail/Base64Api.h +101 -0
  445. package/external/folly/folly/detail/base64_detail/Base64Common.h +80 -0
  446. package/external/folly/folly/detail/base64_detail/Base64Constants.h +79 -0
  447. package/external/folly/folly/detail/base64_detail/Base64HiddenConstants.h +129 -0
  448. package/external/folly/folly/detail/base64_detail/Base64SWAR.cpp +161 -0
  449. package/external/folly/folly/detail/base64_detail/Base64SWAR.h +32 -0
  450. package/external/folly/folly/detail/base64_detail/Base64Scalar.h +262 -0
  451. package/external/folly/folly/detail/base64_detail/Base64Simd.h +102 -0
  452. package/external/folly/folly/detail/base64_detail/Base64_SSE4_2.cpp +42 -0
  453. package/external/folly/folly/detail/base64_detail/Base64_SSE4_2.h +33 -0
  454. package/external/folly/folly/detail/base64_detail/Base64_SSE4_2_Platform.h +167 -0
  455. package/external/folly/folly/detail/base64_detail/README.md +392 -0
  456. package/external/folly/folly/detail/base64_detail/tests/BUCK +36 -0
  457. package/external/folly/folly/detail/base64_detail/tests/Base64AgainstScalarTest.cpp +141 -0
  458. package/external/folly/folly/detail/base64_detail/tests/Base64PlatformTest.cpp +273 -0
  459. package/external/folly/folly/detail/base64_detail/tests/Base64SpecialCasesTest.cpp +555 -0
  460. package/external/folly/folly/detail/test/AsyncTraceTest.cpp +43 -0
  461. package/external/folly/folly/detail/test/BUCK +118 -0
  462. package/external/folly/folly/detail/test/FileUtilDetailTest.cpp +56 -0
  463. package/external/folly/folly/detail/test/PerfScopedTest.cpp +107 -0
  464. package/external/folly/folly/detail/test/SimpleSimdStringUtilsTest.cpp +92 -0
  465. package/external/folly/folly/detail/test/SplitStringSimdTest.cpp +242 -0
  466. package/external/folly/folly/detail/test/StaticSingletonManagerTest.cpp +121 -0
  467. package/external/folly/folly/detail/test/ThreadLocalBenchmark.cpp +116 -0
  468. package/external/folly/folly/detail/test/ThreadLocalDetailTest.cpp +194 -0
  469. package/external/folly/folly/detail/test/TrapOnAvx512TestNegative.cpp +29 -0
  470. package/external/folly/folly/detail/test/UniqueInstanceTest.cpp +60 -0
  471. package/external/folly/folly/detail/thread_local_globals.cpp +69 -0
  472. package/external/folly/folly/detail/thread_local_globals.h +36 -0
  473. package/external/folly/folly/docs/AtomicHashMap.md +134 -0
  474. package/external/folly/folly/docs/Benchmark.md +310 -0
  475. package/external/folly/folly/docs/Conv.md +291 -0
  476. package/external/folly/folly/docs/Dynamic.md +220 -0
  477. package/external/folly/folly/docs/DynamicConverter.md +71 -0
  478. package/external/folly/folly/docs/Executors.md +63 -0
  479. package/external/folly/folly/docs/FBString.md +46 -0
  480. package/external/folly/folly/docs/FBVector.md +200 -0
  481. package/external/folly/folly/docs/Fbvector--graphical_solutions.png +0 -0
  482. package/external/folly/folly/docs/Format.md +177 -0
  483. package/external/folly/folly/docs/Function.md +92 -0
  484. package/external/folly/folly/docs/Futures.md +263 -0
  485. package/external/folly/folly/docs/GroupVarint.md +46 -0
  486. package/external/folly/folly/docs/Histogram.md +104 -0
  487. package/external/folly/folly/docs/MapUtils.md +80 -0
  488. package/external/folly/folly/docs/Overview.md +263 -0
  489. package/external/folly/folly/docs/PackedSyncPtr.md +77 -0
  490. package/external/folly/folly/docs/Poly.md +500 -0
  491. package/external/folly/folly/docs/ProducerConsumerQueue.md +82 -0
  492. package/external/folly/folly/docs/Rcu.md +218 -0
  493. package/external/folly/folly/docs/SmallLocks.md +24 -0
  494. package/external/folly/folly/docs/Synchronized.md +793 -0
  495. package/external/folly/folly/docs/ThreadCachedInt.md +98 -0
  496. package/external/folly/folly/docs/ThreadLocal.md +105 -0
  497. package/external/folly/folly/docs/Traits.md +161 -0
  498. package/external/folly/folly/docs/small_vector.md +64 -0
  499. package/external/folly/folly/docs/style.css +23 -0
  500. package/external/folly/folly/dynamic-inl.h +17 -0
  501. package/external/folly/folly/dynamic.h +17 -0
  502. package/external/folly/folly/folly_extended_library.bzl +28 -0
  503. package/external/folly/folly/functional/ApplyTuple.h +204 -0
  504. package/external/folly/folly/functional/BUCK +57 -0
  505. package/external/folly/folly/functional/Invoke.h +880 -0
  506. package/external/folly/folly/functional/Partial.h +130 -0
  507. package/external/folly/folly/functional/protocol.h +203 -0
  508. package/external/folly/folly/functional/test/ApplyTupleTest.cpp +549 -0
  509. package/external/folly/folly/functional/test/BUCK +57 -0
  510. package/external/folly/folly/functional/test/InvokeTest.cpp +483 -0
  511. package/external/folly/folly/functional/test/PartialTest.cpp +141 -0
  512. package/external/folly/folly/functional/test/protocol_test.cpp +177 -0
  513. package/external/folly/folly/functional/test/traits_test.cpp +551 -0
  514. package/external/folly/folly/functional/traits.h +675 -0
  515. package/external/folly/folly/hash/BUCK +86 -0
  516. package/external/folly/folly/hash/Checksum.cpp +275 -0
  517. package/external/folly/folly/hash/Checksum.h +94 -0
  518. package/external/folly/folly/hash/FarmHash.h +46 -0
  519. package/external/folly/folly/hash/Hash.h +1045 -0
  520. package/external/folly/folly/hash/MurmurHash.h +86 -0
  521. package/external/folly/folly/hash/SpookyHashV1.cpp +391 -0
  522. package/external/folly/folly/hash/SpookyHashV1.h +307 -0
  523. package/external/folly/folly/hash/SpookyHashV2.cpp +392 -0
  524. package/external/folly/folly/hash/SpookyHashV2.h +339 -0
  525. package/external/folly/folly/hash/detail/BUCK +26 -0
  526. package/external/folly/folly/hash/detail/ChecksumDetail.cpp +296 -0
  527. package/external/folly/folly/hash/detail/ChecksumDetail.h +137 -0
  528. package/external/folly/folly/hash/detail/Crc32CombineDetail.cpp +191 -0
  529. package/external/folly/folly/hash/detail/Crc32cDetail.cpp +303 -0
  530. package/external/folly/folly/hash/test/BUCK +132 -0
  531. package/external/folly/folly/hash/test/ChecksumBenchmark.cpp +91 -0
  532. package/external/folly/folly/hash/test/ChecksumTest.cpp +587 -0
  533. package/external/folly/folly/hash/test/FarmHashTest.cpp +41 -0
  534. package/external/folly/folly/hash/test/HashBenchmark.cpp +238 -0
  535. package/external/folly/folly/hash/test/HashTest.cpp +997 -0
  536. package/external/folly/folly/hash/test/MurmurHashTest.cpp +76 -0
  537. package/external/folly/folly/hash/test/SpookyHashV1Test.cpp +559 -0
  538. package/external/folly/folly/hash/test/SpookyHashV2Test.cpp +549 -0
  539. package/external/folly/folly/hash/test/traits_test.cpp +69 -0
  540. package/external/folly/folly/hash/traits.h +115 -0
  541. package/external/folly/folly/json/BUCK +155 -0
  542. package/external/folly/folly/json/DynamicConverter.h +464 -0
  543. package/external/folly/folly/json/DynamicParser-inl.h +316 -0
  544. package/external/folly/folly/json/DynamicParser.cpp +198 -0
  545. package/external/folly/folly/json/DynamicParser.h +394 -0
  546. package/external/folly/folly/json/JSONSchema.cpp +1030 -0
  547. package/external/folly/folly/json/JSONSchema.h +73 -0
  548. package/external/folly/folly/json/JsonMockUtil.h +73 -0
  549. package/external/folly/folly/json/JsonTestUtil.cpp +167 -0
  550. package/external/folly/folly/json/JsonTestUtil.h +88 -0
  551. package/external/folly/folly/json/bser/BUCK +24 -0
  552. package/external/folly/folly/json/bser/Bser.h +107 -0
  553. package/external/folly/folly/json/bser/Dump.cpp +253 -0
  554. package/external/folly/folly/json/bser/Load.cpp +246 -0
  555. package/external/folly/folly/json/bser/test/BUCK +14 -0
  556. package/external/folly/folly/json/bser/test/BserTest.cpp +149 -0
  557. package/external/folly/folly/json/dynamic.cpp +552 -0
  558. package/external/folly/folly/json/dynamic.h +1346 -0
  559. package/external/folly/folly/json/json.h +238 -0
  560. package/external/folly/folly/json/json_patch.cpp +325 -0
  561. package/external/folly/folly/json/json_patch.h +126 -0
  562. package/external/folly/folly/json/json_pointer.cpp +114 -0
  563. package/external/folly/folly/json/json_pointer.h +87 -0
  564. package/external/folly/folly/json/test/BUCK +147 -0
  565. package/external/folly/folly/json/test/DynamicBenchmark.cpp +146 -0
  566. package/external/folly/folly/json/test/DynamicConverterTest.cpp +518 -0
  567. package/external/folly/folly/json/test/DynamicOtherTest.cpp +344 -0
  568. package/external/folly/folly/json/test/DynamicParserTest.cpp +443 -0
  569. package/external/folly/folly/json/test/DynamicTest.cpp +1647 -0
  570. package/external/folly/folly/json/test/JSONSchemaTest.cpp +450 -0
  571. package/external/folly/folly/json/test/JsonBenchmark.cpp +264 -0
  572. package/external/folly/folly/json/test/JsonOtherTest.cpp +51 -0
  573. package/external/folly/folly/json/test/JsonTest.cpp +1153 -0
  574. package/external/folly/folly/json/test/JsonTestUtilTest.cpp +97 -0
  575. package/external/folly/folly/json/test/json_patch_test.cpp +361 -0
  576. package/external/folly/folly/json/test/json_pointer_test.cpp +58 -0
  577. package/external/folly/folly/json/tool/BUCK +13 -0
  578. package/external/folly/folly/json/tool/JSONSchemaTester.cpp +58 -0
  579. package/external/folly/folly/json.h +17 -0
  580. package/external/folly/folly/json_patch.h +17 -0
  581. package/external/folly/folly/json_pointer.h +17 -0
  582. package/external/folly/folly/lang/Access.h +29 -0
  583. package/external/folly/folly/lang/Align.h +240 -0
  584. package/external/folly/folly/lang/Aligned.h +92 -0
  585. package/external/folly/folly/lang/Assume.h +82 -0
  586. package/external/folly/folly/lang/BUCK +287 -0
  587. package/external/folly/folly/lang/Badge.h +108 -0
  588. package/external/folly/folly/lang/Bits.h +570 -0
  589. package/external/folly/folly/lang/BitsClass.h +312 -0
  590. package/external/folly/folly/lang/Builtin.h +74 -0
  591. package/external/folly/folly/lang/CArray.h +34 -0
  592. package/external/folly/folly/lang/CString.cpp +86 -0
  593. package/external/folly/folly/lang/CString.h +55 -0
  594. package/external/folly/folly/lang/Cast.h +51 -0
  595. package/external/folly/folly/lang/CheckedMath.h +253 -0
  596. package/external/folly/folly/lang/CustomizationPoint.h +58 -0
  597. package/external/folly/folly/lang/Exception.cpp +822 -0
  598. package/external/folly/folly/lang/Exception.h +716 -0
  599. package/external/folly/folly/lang/Extern.h +55 -0
  600. package/external/folly/folly/lang/Hint-inl.h +144 -0
  601. package/external/folly/folly/lang/Hint.h +238 -0
  602. package/external/folly/folly/lang/Keep.h +98 -0
  603. package/external/folly/folly/lang/New.h +124 -0
  604. package/external/folly/folly/lang/Ordering.h +140 -0
  605. package/external/folly/folly/lang/Pretty.h +159 -0
  606. package/external/folly/folly/lang/PropagateConst.h +413 -0
  607. package/external/folly/folly/lang/RValueReferenceWrapper.h +152 -0
  608. package/external/folly/folly/lang/SafeAssert.cpp +589 -0
  609. package/external/folly/folly/lang/StaticConst.h +33 -0
  610. package/external/folly/folly/lang/Thunk.h +100 -0
  611. package/external/folly/folly/lang/TypeInfo.h +58 -0
  612. package/external/folly/folly/lang/UncaughtExceptions.cpp +17 -0
  613. package/external/folly/folly/lang/UncaughtExceptions.h +19 -0
  614. package/external/folly/folly/lang/test/AlignTest.cpp +87 -0
  615. package/external/folly/folly/lang/test/AlignedTest.cpp +130 -0
  616. package/external/folly/folly/lang/test/BUCK +258 -0
  617. package/external/folly/folly/lang/test/BadgeTest.cpp +89 -0
  618. package/external/folly/folly/lang/test/BitsBenchmark.cpp +164 -0
  619. package/external/folly/folly/lang/test/BitsClassBenchmark.cpp +122 -0
  620. package/external/folly/folly/lang/test/BitsClassTest.cpp +379 -0
  621. package/external/folly/folly/lang/test/BitsTest.cpp +577 -0
  622. package/external/folly/folly/lang/test/CStringTest.cpp +60 -0
  623. package/external/folly/folly/lang/test/CastTest.cpp +47 -0
  624. package/external/folly/folly/lang/test/CheckedMathTest.cpp +394 -0
  625. package/external/folly/folly/lang/test/ExceptionBench.cpp +427 -0
  626. package/external/folly/folly/lang/test/ExceptionTest.cpp +413 -0
  627. package/external/folly/folly/lang/test/ExternTest.cpp +39 -0
  628. package/external/folly/folly/lang/test/HintTest.cpp +100 -0
  629. package/external/folly/folly/lang/test/NewTest.cpp +38 -0
  630. package/external/folly/folly/lang/test/OrderingTest.cpp +105 -0
  631. package/external/folly/folly/lang/test/PrettyTest.cpp +44 -0
  632. package/external/folly/folly/lang/test/PropagateConstTest.cpp +356 -0
  633. package/external/folly/folly/lang/test/RValueReferenceWrapperTest.cpp +85 -0
  634. package/external/folly/folly/lang/test/SafeAssertTest.cpp +75 -0
  635. package/external/folly/folly/lang/test/ThunkTest.cpp +105 -0
  636. package/external/folly/folly/lang/test/ToAsciiBench.cpp +466 -0
  637. package/external/folly/folly/lang/test/ToAsciiTest.cpp +266 -0
  638. package/external/folly/folly/lang/test/TypeInfoTest.cpp +56 -0
  639. package/external/folly/folly/memcpy.S +292 -0
  640. package/external/folly/folly/memcpy_select_aarch64.cpp +145 -0
  641. package/external/folly/folly/memory/Arena-inl.h +83 -0
  642. package/external/folly/folly/memory/Arena.h +325 -0
  643. package/external/folly/folly/memory/BUCK +191 -0
  644. package/external/folly/folly/memory/JemallocHugePageAllocator.cpp +449 -0
  645. package/external/folly/folly/memory/JemallocHugePageAllocator.h +105 -0
  646. package/external/folly/folly/memory/JemallocHugePageAllocatorTest.cpp +341 -0
  647. package/external/folly/folly/memory/JemallocNodumpAllocator.cpp +176 -0
  648. package/external/folly/folly/memory/JemallocNodumpAllocator.h +119 -0
  649. package/external/folly/folly/memory/JemallocNodumpAllocatorTest.cpp +61 -0
  650. package/external/folly/folly/memory/MallctlHelper.cpp +37 -0
  651. package/external/folly/folly/memory/MallctlHelper.h +167 -0
  652. package/external/folly/folly/memory/Malloc.h +551 -0
  653. package/external/folly/folly/memory/MemoryResource.h +57 -0
  654. package/external/folly/folly/memory/ReentrantAllocator.cpp +162 -0
  655. package/external/folly/folly/memory/ReentrantAllocator.h +261 -0
  656. package/external/folly/folly/memory/SanitizeAddress.cpp +75 -0
  657. package/external/folly/folly/memory/SanitizeAddress.h +117 -0
  658. package/external/folly/folly/memory/SanitizeLeak.cpp +119 -0
  659. package/external/folly/folly/memory/SanitizeLeak.h +108 -0
  660. package/external/folly/folly/memory/ThreadCachedArena.cpp +53 -0
  661. package/external/folly/folly/memory/ThreadCachedArena.h +90 -0
  662. package/external/folly/folly/memory/UninitializedMemoryHacks.h +426 -0
  663. package/external/folly/folly/memory/detail/BUCK +10 -0
  664. package/external/folly/folly/memory/detail/MallocImpl.cpp +52 -0
  665. package/external/folly/folly/memory/detail/MallocImpl.h +97 -0
  666. package/external/folly/folly/memory/not_null-inl.h +522 -0
  667. package/external/folly/folly/memory/not_null.h +449 -0
  668. package/external/folly/folly/memory/test/ArenaTest.cpp +354 -0
  669. package/external/folly/folly/memory/test/BUCK +146 -0
  670. package/external/folly/folly/memory/test/MallctlHelperTest.cpp +169 -0
  671. package/external/folly/folly/memory/test/MallocBenchmark.cpp +91 -0
  672. package/external/folly/folly/memory/test/MallocTest.cpp +78 -0
  673. package/external/folly/folly/memory/test/MemoryResourceTest.cpp +31 -0
  674. package/external/folly/folly/memory/test/ReentrantAllocatorTest.cpp +144 -0
  675. package/external/folly/folly/memory/test/SanitizeAddressTest.cpp +67 -0
  676. package/external/folly/folly/memory/test/SanitizeLeakTest.cpp +139 -0
  677. package/external/folly/folly/memory/test/ThreadCachedArenaTest.cpp +276 -0
  678. package/external/folly/folly/memory/test/UninitializedMemoryHacksODR.cpp +21 -0
  679. package/external/folly/folly/memory/test/UninitializedMemoryHacksTest.cpp +327 -0
  680. package/external/folly/folly/memory/test/not_null_test.cpp +608 -0
  681. package/external/folly/folly/memset.S +245 -0
  682. package/external/folly/folly/memset_select_aarch64.cpp +72 -0
  683. package/external/folly/folly/portability/Asm.h +50 -0
  684. package/external/folly/folly/portability/Atomic.h +31 -0
  685. package/external/folly/folly/portability/BUCK +456 -0
  686. package/external/folly/folly/portability/Builtins.cpp +31 -0
  687. package/external/folly/folly/portability/Builtins.h +161 -0
  688. package/external/folly/folly/portability/Config.h +43 -0
  689. package/external/folly/folly/portability/Constexpr.h +145 -0
  690. package/external/folly/folly/portability/Dirent.cpp +140 -0
  691. package/external/folly/folly/portability/Dirent.h +41 -0
  692. package/external/folly/folly/portability/Event.h +44 -0
  693. package/external/folly/folly/portability/Fcntl.cpp +120 -0
  694. package/external/folly/folly/portability/Fcntl.h +67 -0
  695. package/external/folly/folly/portability/Filesystem.cpp +67 -0
  696. package/external/folly/folly/portability/Filesystem.h +114 -0
  697. package/external/folly/folly/portability/FmtCompile.h +40 -0
  698. package/external/folly/folly/portability/GFlags.h +139 -0
  699. package/external/folly/folly/portability/GMock.h +35 -0
  700. package/external/folly/folly/portability/GTest.h +35 -0
  701. package/external/folly/folly/portability/IOVec.h +34 -0
  702. package/external/folly/folly/portability/Libgen.cpp +59 -0
  703. package/external/folly/folly/portability/Libgen.h +29 -0
  704. package/external/folly/folly/portability/Libunwind.h +21 -0
  705. package/external/folly/folly/portability/Malloc.cpp +31 -0
  706. package/external/folly/folly/portability/Malloc.h +53 -0
  707. package/external/folly/folly/portability/Math.h +90 -0
  708. package/external/folly/folly/portability/Memory.h +26 -0
  709. package/external/folly/folly/portability/OpenSSL.cpp +17 -0
  710. package/external/folly/folly/portability/OpenSSL.h +102 -0
  711. package/external/folly/folly/portability/PThread.cpp +697 -0
  712. package/external/folly/folly/portability/PThread.h +148 -0
  713. package/external/folly/folly/portability/README.md +21 -0
  714. package/external/folly/folly/portability/Sched.cpp +41 -0
  715. package/external/folly/folly/portability/Sched.h +45 -0
  716. package/external/folly/folly/portability/Sockets.cpp +245 -0
  717. package/external/folly/folly/portability/Sockets.h +155 -0
  718. package/external/folly/folly/portability/SourceLocation.h +49 -0
  719. package/external/folly/folly/portability/Stdio.cpp +77 -0
  720. package/external/folly/folly/portability/Stdio.h +32 -0
  721. package/external/folly/folly/portability/Stdlib.cpp +172 -0
  722. package/external/folly/folly/portability/Stdlib.h +64 -0
  723. package/external/folly/folly/portability/String.cpp +53 -0
  724. package/external/folly/folly/portability/String.h +39 -0
  725. package/external/folly/folly/portability/SysFile.cpp +46 -0
  726. package/external/folly/folly/portability/SysFile.h +27 -0
  727. package/external/folly/folly/portability/SysMembarrier.cpp +104 -0
  728. package/external/folly/folly/portability/SysMembarrier.h +26 -0
  729. package/external/folly/folly/portability/SysMman.cpp +242 -0
  730. package/external/folly/folly/portability/SysMman.h +68 -0
  731. package/external/folly/folly/portability/SysResource.cpp +108 -0
  732. package/external/folly/folly/portability/SysResource.h +71 -0
  733. package/external/folly/folly/portability/SysStat.cpp +66 -0
  734. package/external/folly/folly/portability/SysStat.h +52 -0
  735. package/external/folly/folly/portability/SysSyscall.h +73 -0
  736. package/external/folly/folly/portability/SysTime.cpp +62 -0
  737. package/external/folly/folly/portability/SysTime.h +50 -0
  738. package/external/folly/folly/portability/SysTypes.h +44 -0
  739. package/external/folly/folly/portability/SysUio.cpp +179 -0
  740. package/external/folly/folly/portability/SysUio.h +51 -0
  741. package/external/folly/folly/portability/Syslog.h +39 -0
  742. package/external/folly/folly/portability/Time.cpp +357 -0
  743. package/external/folly/folly/portability/Time.h +74 -0
  744. package/external/folly/folly/portability/Unistd.h +111 -0
  745. package/external/folly/folly/portability/Windows.h +108 -0
  746. package/external/folly/folly/portability/openat2.c +30 -0
  747. package/external/folly/folly/portability/openat2.h +39 -0
  748. package/external/folly/folly/portability/test/BUCK +59 -0
  749. package/external/folly/folly/portability/test/ConstexprTest.cpp +102 -0
  750. package/external/folly/folly/portability/test/FilesystemTest.cpp +35 -0
  751. package/external/folly/folly/portability/test/LibgenTest.cpp +35 -0
  752. package/external/folly/folly/portability/test/OpenSSLPortabilityTest.cpp +108 -0
  753. package/external/folly/folly/portability/test/PThreadTest.cpp +80 -0
  754. package/external/folly/folly/portability/test/TimeTest.cpp +90 -0
  755. package/external/folly/folly/small_vector.h +17 -0
  756. package/external/folly/folly/somerge_defs.bzl +399 -0
  757. package/external/folly/folly/sorted_vector_types.h +17 -0
  758. package/external/folly/folly/stop_watch.h +317 -0
  759. package/external/folly/folly/synchronization/AsymmetricThreadFence.cpp +91 -0
  760. package/external/folly/folly/synchronization/AsymmetricThreadFence.h +60 -0
  761. package/external/folly/folly/synchronization/AtomicNotification-inl.h +146 -0
  762. package/external/folly/folly/synchronization/AtomicNotification.cpp +34 -0
  763. package/external/folly/folly/synchronization/AtomicNotification.h +117 -0
  764. package/external/folly/folly/synchronization/AtomicRef.h +181 -0
  765. package/external/folly/folly/synchronization/AtomicStruct.h +150 -0
  766. package/external/folly/folly/synchronization/AtomicUtil-inl.h +482 -0
  767. package/external/folly/folly/synchronization/AtomicUtil.h +179 -0
  768. package/external/folly/folly/synchronization/BUCK +418 -0
  769. package/external/folly/folly/synchronization/Baton.h +419 -0
  770. package/external/folly/folly/synchronization/CallOnce.h +263 -0
  771. package/external/folly/folly/synchronization/DelayedInit.h +179 -0
  772. package/external/folly/folly/synchronization/DistributedMutex-inl.h +1744 -0
  773. package/external/folly/folly/synchronization/DistributedMutex.cpp +27 -0
  774. package/external/folly/folly/synchronization/DistributedMutex.h +342 -0
  775. package/external/folly/folly/synchronization/EventCount.h +200 -0
  776. package/external/folly/folly/synchronization/FlatCombining.h +629 -0
  777. package/external/folly/folly/synchronization/Hazptr-fwd.h +217 -0
  778. package/external/folly/folly/synchronization/Hazptr.cpp +36 -0
  779. package/external/folly/folly/synchronization/Hazptr.h +209 -0
  780. package/external/folly/folly/synchronization/HazptrDomain.cpp +68 -0
  781. package/external/folly/folly/synchronization/HazptrDomain.h +832 -0
  782. package/external/folly/folly/synchronization/HazptrHolder.h +431 -0
  783. package/external/folly/folly/synchronization/HazptrObj.h +533 -0
  784. package/external/folly/folly/synchronization/HazptrObjLinked.h +315 -0
  785. package/external/folly/folly/synchronization/HazptrRec.h +68 -0
  786. package/external/folly/folly/synchronization/HazptrThrLocal.h +180 -0
  787. package/external/folly/folly/synchronization/HazptrThreadPoolExecutor.cpp +46 -0
  788. package/external/folly/folly/synchronization/HazptrThreadPoolExecutor.h +25 -0
  789. package/external/folly/folly/synchronization/Latch.h +160 -0
  790. package/external/folly/folly/synchronization/LifoSem.h +767 -0
  791. package/external/folly/folly/synchronization/Lock.h +887 -0
  792. package/external/folly/folly/synchronization/MicroSpinLock.h +154 -0
  793. package/external/folly/folly/synchronization/NativeSemaphore.h +187 -0
  794. package/external/folly/folly/synchronization/ParkingLot.cpp +37 -0
  795. package/external/folly/folly/synchronization/ParkingLot.h +330 -0
  796. package/external/folly/folly/synchronization/PicoSpinLock.h +167 -0
  797. package/external/folly/folly/synchronization/RWSpinLock.h +549 -0
  798. package/external/folly/folly/synchronization/Rcu.cpp +26 -0
  799. package/external/folly/folly/synchronization/Rcu.h +553 -0
  800. package/external/folly/folly/synchronization/RelaxedAtomic.h +336 -0
  801. package/external/folly/folly/synchronization/SanitizeThread.cpp +141 -0
  802. package/external/folly/folly/synchronization/SanitizeThread.h +166 -0
  803. package/external/folly/folly/synchronization/SaturatingSemaphore.h +324 -0
  804. package/external/folly/folly/synchronization/SmallLocks.h +36 -0
  805. package/external/folly/folly/synchronization/ThrottledLifoSem.h +362 -0
  806. package/external/folly/folly/synchronization/WaitOptions.cpp +25 -0
  807. package/external/folly/folly/synchronization/WaitOptions.h +75 -0
  808. package/external/folly/folly/synchronization/detail/AtomicUtils.h +59 -0
  809. package/external/folly/folly/synchronization/detail/BUCK +104 -0
  810. package/external/folly/folly/synchronization/detail/Hardware.cpp +192 -0
  811. package/external/folly/folly/synchronization/detail/Hardware.h +75 -0
  812. package/external/folly/folly/synchronization/detail/HazptrUtils.h +339 -0
  813. package/external/folly/folly/synchronization/detail/InlineFunctionRef.h +229 -0
  814. package/external/folly/folly/synchronization/detail/Sleeper.cpp +27 -0
  815. package/external/folly/folly/synchronization/detail/Sleeper.h +62 -0
  816. package/external/folly/folly/synchronization/detail/Spin.h +96 -0
  817. package/external/folly/folly/synchronization/detail/ThreadCachedLists.h +174 -0
  818. package/external/folly/folly/synchronization/detail/ThreadCachedReaders.h +189 -0
  819. package/external/folly/folly/synchronization/detail/ThreadCachedTag.h +26 -0
  820. package/external/folly/folly/synchronization/detail/test/BUCK +28 -0
  821. package/external/folly/folly/synchronization/detail/test/HardwareTest.cpp +74 -0
  822. package/external/folly/folly/synchronization/detail/test/InlineFunctionRefTest.cpp +286 -0
  823. package/external/folly/folly/synchronization/example/BUCK +27 -0
  824. package/external/folly/folly/synchronization/example/HazptrLockFreeLIFO.h +88 -0
  825. package/external/folly/folly/synchronization/example/HazptrSWMRSet.h +133 -0
  826. package/external/folly/folly/synchronization/example/HazptrWideCAS.h +62 -0
  827. package/external/folly/folly/synchronization/test/AtomicNotificationTest.cpp +236 -0
  828. package/external/folly/folly/synchronization/test/AtomicRefTest.cpp +170 -0
  829. package/external/folly/folly/synchronization/test/AtomicStructTest.cpp +65 -0
  830. package/external/folly/folly/synchronization/test/AtomicUtilBench.cpp +457 -0
  831. package/external/folly/folly/synchronization/test/AtomicUtilTest.cpp +650 -0
  832. package/external/folly/folly/synchronization/test/BUCK +495 -0
  833. package/external/folly/folly/synchronization/test/Barrier.h +52 -0
  834. package/external/folly/folly/synchronization/test/BarrierTest.cpp +56 -0
  835. package/external/folly/folly/synchronization/test/BatonBenchmark.cpp +77 -0
  836. package/external/folly/folly/synchronization/test/BatonTest.cpp +164 -0
  837. package/external/folly/folly/synchronization/test/BatonTestHelpers.h +118 -0
  838. package/external/folly/folly/synchronization/test/CallOnceBenchmark.cpp +72 -0
  839. package/external/folly/folly/synchronization/test/CallOnceTest.cpp +153 -0
  840. package/external/folly/folly/synchronization/test/DelayedInitTest.cpp +281 -0
  841. package/external/folly/folly/synchronization/test/DistributedMutexTest.cpp +2074 -0
  842. package/external/folly/folly/synchronization/test/EventCountTest.cpp +124 -0
  843. package/external/folly/folly/synchronization/test/FlatCombiningBenchmark.cpp +1789 -0
  844. package/external/folly/folly/synchronization/test/FlatCombiningExamples.h +222 -0
  845. package/external/folly/folly/synchronization/test/FlatCombiningTest.cpp +121 -0
  846. package/external/folly/folly/synchronization/test/FlatCombiningTestHelpers.h +227 -0
  847. package/external/folly/folly/synchronization/test/HazptrTest.cpp +1689 -0
  848. package/external/folly/folly/synchronization/test/LatchTest.cpp +224 -0
  849. package/external/folly/folly/synchronization/test/LifoSemBench.cpp +185 -0
  850. package/external/folly/folly/synchronization/test/LifoSemTests.cpp +353 -0
  851. package/external/folly/folly/synchronization/test/LockTest.cpp +1239 -0
  852. package/external/folly/folly/synchronization/test/NativeSemaphoreTest.cpp +37 -0
  853. package/external/folly/folly/synchronization/test/ParkingLotBenchmark.cpp +239 -0
  854. package/external/folly/folly/synchronization/test/ParkingLotTest.cpp +170 -0
  855. package/external/folly/folly/synchronization/test/RWSpinLockTest.cpp +235 -0
  856. package/external/folly/folly/synchronization/test/RcuBench.cpp +66 -0
  857. package/external/folly/folly/synchronization/test/RcuTest.cpp +330 -0
  858. package/external/folly/folly/synchronization/test/RelaxedAtomicTest.cpp +389 -0
  859. package/external/folly/folly/synchronization/test/SaturatingSemaphoreTest.cpp +166 -0
  860. package/external/folly/folly/synchronization/test/Semaphore.h +242 -0
  861. package/external/folly/folly/synchronization/test/SemaphoreTest.cpp +271 -0
  862. package/external/folly/folly/synchronization/test/SmallLocksBenchmark.cpp +1296 -0
  863. package/external/folly/folly/synchronization/test/SmallLocksTest.cpp +510 -0
  864. package/external/folly/folly/synchronization/test/ThreadCachedEpochBench.h +67 -0
  865. package/external/folly/folly/synchronization/test/ThreadCachedReadersBench.cpp +42 -0
  866. package/external/folly/folly/synchronization/test/ThreadCachedReadersTest.cpp +52 -0
  867. package/external/folly/folly/synchronization/test/ThrottledLifoSemTest.cpp +243 -0
  868. package/external/folly/folly/system/AtFork.cpp +205 -0
  869. package/external/folly/folly/system/AtFork.h +116 -0
  870. package/external/folly/folly/system/AuxVector.h +198 -0
  871. package/external/folly/folly/system/BUCK +144 -0
  872. package/external/folly/folly/system/EnvUtil.cpp +93 -0
  873. package/external/folly/folly/system/EnvUtil.h +113 -0
  874. package/external/folly/folly/system/HardwareConcurrency.cpp +39 -0
  875. package/external/folly/folly/system/HardwareConcurrency.h +23 -0
  876. package/external/folly/folly/system/MemoryMapping.cpp +477 -0
  877. package/external/folly/folly/system/MemoryMapping.h +287 -0
  878. package/external/folly/folly/system/Pid.cpp +87 -0
  879. package/external/folly/folly/system/Pid.h +34 -0
  880. package/external/folly/folly/system/Shell.cpp +33 -0
  881. package/external/folly/folly/system/Shell.h +93 -0
  882. package/external/folly/folly/system/ThreadId.cpp +89 -0
  883. package/external/folly/folly/system/ThreadId.h +62 -0
  884. package/external/folly/folly/system/ThreadName.cpp +330 -0
  885. package/external/folly/folly/system/ThreadName.h +72 -0
  886. package/external/folly/folly/system/test/AtForkTest.cpp +309 -0
  887. package/external/folly/folly/system/test/AuxVectorTest.cpp +55 -0
  888. package/external/folly/folly/system/test/BUCK +120 -0
  889. package/external/folly/folly/system/test/EnvUtilSubprocess.cpp +26 -0
  890. package/external/folly/folly/system/test/EnvUtilTest.cpp +197 -0
  891. package/external/folly/folly/system/test/MemoryMappingTest.cpp +179 -0
  892. package/external/folly/folly/system/test/PidTest.cpp +46 -0
  893. package/external/folly/folly/system/test/ShellTest.cpp +66 -0
  894. package/external/folly/folly/system/test/ThreadIdTest.cpp +114 -0
  895. package/external/folly/folly/system/test/ThreadNameTest.cpp +85 -0
  896. package/external/folly/folly.vcxitems +164 -0
  897. package/external/folly/static/logo.svg +1 -0
  898. package/external/folly/sync-config.json +8 -0
  899. package/package.json +6 -6
  900. package/template/cpp-lib/proj/MyLib.sln +0 -33
  901. package/template/cs-lib/proj/MyLib.sln +0 -33
  902. package/templates/cpp-app/windows/MyApp.sln +0 -33
  903. package/templates/cpp-lib/example/metro.config.js +30 -4
  904. package/templates/cpp-lib/windows/MyLib.sln +0 -33
  905. package/Folly/Folly.vcxproj +0 -378
  906. package/Folly/Folly.vcxproj.filters +0 -558
  907. package/fmt/fmt.vcxproj +0 -153
  908. package/fmt/fmt.vcxproj.filters +0 -59
  909. package/fmt/pch.cpp +0 -4
  910. package/fmt/pch.h +0 -2
  911. /package/{fmt → external/fmt}/cgmanifest.json +0 -0
  912. /package/{Folly → external/folly}/Folly.natvis +0 -0
  913. /package/{Folly → external/folly}/cgmanifest.json +0 -0
  914. /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/ConstexprMath.h +0 -0
  915. /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/Conv.cpp +0 -0
  916. /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/chrono/Hardware.h +0 -0
  917. /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/concurrency/CacheLocality.cpp +0 -0
  918. /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/json/dynamic-inl.h +0 -0
  919. /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/json/json.cpp +0 -0
  920. /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/lang/SafeAssert.h +0 -0
  921. /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/lang/ToAscii.cpp +0 -0
  922. /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/lang/ToAscii.h +0 -0
  923. /package/{Folly/TEMP_UntilFollyUpdate → external/folly/folly}/portability/Unistd.cpp +0 -0
@@ -0,0 +1,2026 @@
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
+ // Docs: https://fburl.com/fbcref_conv
19
+ //
20
+
21
+ /**
22
+ * Conv provides the ubiquitous method `to<TargetType>(source)`, along with
23
+ * a few other generic interfaces for converting objects to and from
24
+ * string-like types (std::string, fbstring, StringPiece), as well as
25
+ * range-checked conversions between numeric and enum types. The mechanisms are
26
+ * extensible, so that user-specified types can add folly::to support.
27
+ *
28
+ * folly::to<std::string>(123)
29
+ * // "123"
30
+ *
31
+ *******************************************************************************
32
+ * ## TYPE -> STRING CONVERSIONS
33
+ *******************************************************************************
34
+ * You can call the `to<std::string>` or `to<fbstring>`. These are variadic
35
+ * functions that convert their arguments to strings, and concatenate them to
36
+ * form a result. So, for example,
37
+ *
38
+ * auto str = to<std::string>(123, "456", 789);
39
+ *
40
+ * Sets str to `"123456789"`.
41
+ *
42
+ * In addition to just concatenating the arguments, related functions can
43
+ * delimit them with some string: `toDelim<std::string>(",", "123", 456, "789")`
44
+ * will return the string `"123,456,789"`.
45
+ *
46
+ * toAppend does not return a string; instead, it takes a pointer to a string as
47
+ * its last argument, and appends the result of the concatenation into it:
48
+ * std::string str = "123";
49
+ * toAppend(456, "789", &str); // Now str is "123456789".
50
+ *
51
+ * The toAppendFit function acts like toAppend, but it precalculates the size
52
+ * required to perform the append operation, and reserves that space in the
53
+ * output string before actually inserting its arguments. This can sometimes
54
+ * save on string expansion, but beware: appending to the same string many times
55
+ * with toAppendFit is likely a pessimization, since it will resize the string
56
+ * once per append.
57
+ *
58
+ * The combination of the append and delim variants also exist: toAppendDelim
59
+ * and toAppendDelimFit are defined, with the obvious semantics.
60
+ *
61
+ *******************************************************************************
62
+ * ## STRING -> TYPE CONVERSIONS
63
+ *******************************************************************************
64
+ * Going in the other direction, and parsing a string into a C++ type, is also
65
+ * supported:
66
+ * to<int>("123"); // Returns 123.
67
+ *
68
+ * Out of range (e.g. `to<std::uint8_t>("1000")`), or invalidly formatted (e.g.
69
+ * `to<int>("four")`) inputs will throw. If throw-on-error is undesirable (for
70
+ * instance: you're dealing with untrusted input, and want to protect yourself
71
+ * from users sending you down a very slow exception-throwing path), you can use
72
+ * `tryTo<T>`, which will return an `Expected<T, ConversionCode>`.
73
+ *
74
+ * There are overloads of to() and tryTo() that take a `StringPiece*`. These
75
+ * parse out a type from the beginning of a string, and modify the passed-in
76
+ * StringPiece to indicate the portion of the string not consumed.
77
+ *
78
+ *******************************************************************************
79
+ * ## NUMERIC / ENUM CONVERSIONS
80
+ *******************************************************************************
81
+ * Conv also supports a `to<T>(S)` overload, where T and S are numeric or enum
82
+ * types, that checks to see that the target type can represent its argument,
83
+ * and will throw if it cannot. This includes cases where a floating point to
84
+ * integral conversion is attempted on a value with a non-zero fractional
85
+ * component, and integral to floating point conversions that would lose
86
+ * precision. Enum conversions are range-checked for the underlying type of the
87
+ * enum, but there is no check that the input value is a valid choice of enum
88
+ * value.
89
+ *
90
+ *******************************************************************************
91
+ * ## CUSTOM TYPE CONVERSIONS
92
+ *******************************************************************************
93
+ * Users may customize the string conversion functionality for their own data
94
+ * types. The key functions you should implement are:
95
+ * // Two functions to allow conversion to your type from a string.
96
+ * Expected<StringPiece, ConversionCode> parseTo(folly::StringPiece in,
97
+ * YourType& out);
98
+ * YourErrorType makeConversionError(YourErrorType in, StringPiece in);
99
+ * // Two functions to allow conversion from your type to a string.
100
+ * template <class String>
101
+ * void toAppend(const YourType& in, String* out);
102
+ * size_t estimateSpaceNeeded(const YourType& in);
103
+ *
104
+ * These are documented below, inline.
105
+ *
106
+ * @file Conv.h
107
+ */
108
+
109
+ #pragma once
110
+
111
+ #include <algorithm>
112
+ #include <cassert>
113
+ #include <cctype>
114
+ #include <climits>
115
+ #include <cmath>
116
+ #include <cstddef>
117
+ #include <limits>
118
+ #include <optional>
119
+ #include <stdexcept>
120
+ #include <string>
121
+ #include <system_error>
122
+ #include <tuple>
123
+ #include <type_traits>
124
+ #include <utility>
125
+
126
+ #if __has_include(<charconv>)
127
+ #include <charconv>
128
+ #endif
129
+
130
+ #include <double-conversion/double-conversion.h> // V8 JavaScript implementation
131
+
132
+ #include <folly/CPortability.h>
133
+
134
+ #include <folly/Demangle.h>
135
+ #include <folly/Expected.h>
136
+ #include <folly/FBString.h>
137
+ #include <folly/Likely.h>
138
+ #include <folly/Portability.h>
139
+ #include <folly/Range.h>
140
+ #include <folly/Traits.h>
141
+ #include <folly/Unit.h>
142
+ #include <folly/Utility.h>
143
+ #include <folly/lang/Exception.h>
144
+ #include <folly/lang/Pretty.h>
145
+ #include <folly/lang/ToAscii.h>
146
+ #include <folly/portability/Math.h>
147
+
148
+ // FOLLY_CONV_AVALIABILITY_TO_CHARS_FLOATING_POINT indicates that
149
+ // std::to_chars for floating point is available
150
+ #if (defined(__cpp_lib_to_chars) && __cpp_lib_to_chars >= 201611L)
151
+ #define FOLLY_CONV_AVALIABILITY_TO_CHARS_FLOATING_POINT 1
152
+ #elif defined(_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS) && \
153
+ defined(_LIBCPP_AVAILABILITY_TO_CHARS_FLOATING_POINT)
154
+ #define FOLLY_CONV_AVALIABILITY_TO_CHARS_FLOATING_POINT 1
155
+ #elif defined(__APPLE__) && \
156
+ ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
157
+ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 130300) || \
158
+ (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
159
+ __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 160300) || \
160
+ (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \
161
+ __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 160300) || \
162
+ (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
163
+ __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 90300))
164
+ // Apple introduces std::to_chars & std::from_chars support for floating
165
+ // point types for: macOS 13.3, iOS 16.3, tvOS 16.3, watchOS 9.3.
166
+ // https://developer.apple.com/xcode/cpp/#c++17
167
+ // __builtin_available(macOS 13.3, iOS 16.3, tvOS 16.3, watchOS 9.3, *)) {
168
+ // The avaliability attributes are marked as strict, so preprocessor
169
+ // conditionals must be used to check if it's available.
170
+ #define FOLLY_CONV_AVALIABILITY_TO_CHARS_FLOATING_POINT 1
171
+ #else
172
+ #define FOLLY_CONV_AVALIABILITY_TO_CHARS_FLOATING_POINT 0
173
+ #endif
174
+
175
+ // FOLLY_CONV_USE_TO_CHARS set to 1 indicates that std::to_chars will be used
176
+ // because it's available and it was requested.
177
+ #if defined(FOLLY_CONV_DTOA_TO_CHARS) && FOLLY_CONV_DTOA_TO_CHARS == 1 && \
178
+ defined(FOLLY_CONV_AVALIABILITY_TO_CHARS_FLOATING_POINT) && \
179
+ FOLLY_CONV_AVALIABILITY_TO_CHARS_FLOATING_POINT == 1
180
+ #define FOLLY_CONV_USE_TO_CHARS 1
181
+ #else
182
+ #define FOLLY_CONV_USE_TO_CHARS 0
183
+ #endif
184
+
185
+ namespace folly {
186
+
187
+ // Keep this in sync with kErrorStrings in Conv.cpp
188
+ enum class ConversionCode : unsigned char {
189
+ SUCCESS,
190
+ EMPTY_INPUT_STRING,
191
+ NO_DIGITS,
192
+ BOOL_OVERFLOW,
193
+ BOOL_INVALID_VALUE,
194
+ NON_DIGIT_CHAR,
195
+ INVALID_LEADING_CHAR,
196
+ POSITIVE_OVERFLOW,
197
+ NEGATIVE_OVERFLOW,
198
+ STRING_TO_FLOAT_ERROR,
199
+ NON_WHITESPACE_AFTER_END,
200
+ ARITH_POSITIVE_OVERFLOW,
201
+ ARITH_NEGATIVE_OVERFLOW,
202
+ ARITH_LOSS_OF_PRECISION,
203
+ NUM_ERROR_CODES, // has to be the last entry
204
+ };
205
+
206
+ struct FOLLY_EXPORT ConversionErrorBase : std::range_error {
207
+ using std::range_error::range_error;
208
+ };
209
+
210
+ class FOLLY_EXPORT ConversionError : public ConversionErrorBase {
211
+ public:
212
+ ConversionError(const std::string& str, ConversionCode code)
213
+ : ConversionErrorBase(str), code_(code) {}
214
+
215
+ ConversionError(const char* str, ConversionCode code)
216
+ : ConversionErrorBase(str), code_(code) {}
217
+
218
+ ConversionCode errorCode() const { return code_; }
219
+
220
+ private:
221
+ ConversionCode code_;
222
+ };
223
+
224
+ /**
225
+ * Custom Error Translation
226
+ *
227
+ * Your overloaded parseTo() function can return a custom error code on failure.
228
+ * ::folly::to() will call makeConversionError to translate that error code into
229
+ * an object to throw. makeConversionError is found by argument-dependent
230
+ * lookup. It should have this signature:
231
+ *
232
+ * namespace other_namespace {
233
+ * enum YourErrorCode { BAD_ERROR, WORSE_ERROR };
234
+ *
235
+ * struct YourConversionError : ConversionErrorBase {
236
+ * YourConversionError(const char* what) : ConversionErrorBase(what) {}
237
+ * };
238
+ *
239
+ * YourConversionError
240
+ * makeConversionError(YourErrorCode code, ::folly::StringPiece sp) {
241
+ * ...
242
+ * return YourConversionError(messageString);
243
+ * }
244
+ */
245
+ ConversionError makeConversionError(ConversionCode code, StringPiece input);
246
+
247
+ namespace detail {
248
+ /**
249
+ * Enforce that the suffix following a number is made up only of whitespace.
250
+ */
251
+ inline ConversionCode enforceWhitespaceErr(StringPiece sp) {
252
+ for (auto c : sp) {
253
+ if (FOLLY_UNLIKELY(!std::isspace(c))) {
254
+ return ConversionCode::NON_WHITESPACE_AFTER_END;
255
+ }
256
+ }
257
+ return ConversionCode::SUCCESS;
258
+ }
259
+
260
+ /**
261
+ * Keep this implementation around for prettyToDouble().
262
+ */
263
+ inline void enforceWhitespace(StringPiece sp) {
264
+ auto err = enforceWhitespaceErr(sp);
265
+ if (err != ConversionCode::SUCCESS) {
266
+ throw_exception(makeConversionError(err, sp));
267
+ }
268
+ }
269
+ } // namespace detail
270
+
271
+ /**
272
+ * @overloadbrief to, but return an Expected
273
+ *
274
+ * The identity conversion function.
275
+ * tryTo<T>(T) returns itself for all types T.
276
+ */
277
+ template <class Tgt, class Src>
278
+ typename std::enable_if<
279
+ std::is_same<Tgt, typename std::decay<Src>::type>::value,
280
+ Expected<Tgt, ConversionCode>>::type
281
+ tryTo(Src&& value) noexcept {
282
+ return static_cast<Src&&>(value);
283
+ }
284
+
285
+ /**
286
+ * @overloadbrief Convert from one type to another.
287
+ */
288
+ template <class Tgt, class Src>
289
+ typename std::enable_if<
290
+ std::is_same<Tgt, typename std::decay<Src>::type>::value,
291
+ Tgt>::type
292
+ to(Src&& value) {
293
+ return static_cast<Src&&>(value);
294
+ }
295
+
296
+ /**
297
+ * Arithmetic to boolean
298
+ */
299
+
300
+ /**
301
+ * Unchecked conversion from arithmetic to boolean. This is different from the
302
+ * other arithmetic conversions because we use the C convention of treating any
303
+ * non-zero value as true, instead of range checking.
304
+ */
305
+ template <class Tgt, class Src>
306
+ typename std::enable_if<
307
+ is_arithmetic_v<Src> && !std::is_same<Tgt, Src>::value &&
308
+ std::is_same<Tgt, bool>::value,
309
+ Expected<Tgt, ConversionCode>>::type
310
+ tryTo(const Src& value) noexcept {
311
+ return value != Src();
312
+ }
313
+
314
+ template <class Tgt, class Src>
315
+ typename std::enable_if<
316
+ is_arithmetic_v<Src> && !std::is_same<Tgt, Src>::value &&
317
+ std::is_same<Tgt, bool>::value,
318
+ Tgt>::type
319
+ to(const Src& value) {
320
+ return value != Src();
321
+ }
322
+
323
+ /**
324
+ * Anything to string
325
+ */
326
+
327
+ namespace detail {
328
+
329
+ template <class... T>
330
+ using LastElement = type_pack_element_t<sizeof...(T) - 1, T...>;
331
+
332
+ #ifdef _MSC_VER
333
+ // MSVC can't quite figure out the LastElementImpl::call() stuff
334
+ // in the base implementation, so we have to use tuples instead,
335
+ // which result in significantly more templates being compiled,
336
+ // though the runtime performance is the same.
337
+
338
+ template <typename... Ts, typename R = LastElement<Ts...>>
339
+ const R& getLastElement(const Ts&... ts) {
340
+ return std::get<sizeof...(Ts) - 1>(std::forward_as_tuple(ts...));
341
+ }
342
+
343
+ inline void getLastElement() {}
344
+ #else
345
+ template <typename...>
346
+ struct LastElementImpl;
347
+ template <>
348
+ struct LastElementImpl<> {
349
+ static void call() {}
350
+ };
351
+ template <typename Ign, typename... Igns>
352
+ struct LastElementImpl<Ign, Igns...> {
353
+ template <typename Last>
354
+ static const Last& call(Igns..., const Last& last) {
355
+ return last;
356
+ }
357
+ };
358
+
359
+ template <typename... Ts, typename R = LastElement<Ts...>>
360
+ const R& getLastElement(const Ts&... ts) {
361
+ return LastElementImpl<Ignored<Ts>...>::call(ts...);
362
+ }
363
+ #endif
364
+
365
+ } // namespace detail
366
+
367
+ /**
368
+ * Conversions from integral types to string types.
369
+ */
370
+
371
+ #if FOLLY_HAVE_INT128_T
372
+ namespace detail {
373
+
374
+ template <typename IntegerType>
375
+ constexpr unsigned int digitsEnough() {
376
+ // digits10 returns the number of decimal digits that this type can represent,
377
+ // not the number of characters required for the max value, so we need to add
378
+ // one. ex: char digits10 returns 2, because 256-999 cannot be represented,
379
+ // but we need 3.
380
+ auto const digits10 = std::numeric_limits<IntegerType>::digits10;
381
+ return static_cast<unsigned int>(digits10) + 1;
382
+ }
383
+
384
+ inline size_t unsafeTelescope128(char* outb, char* oute, unsigned __int128 x) {
385
+ using Usrc = unsigned __int128;
386
+
387
+ // Decompose the input into at most 3 components using the largest power-of-10
388
+ // base that fits in a 64-bit unsigned integer, and then convert the
389
+ // components using 64-bit arithmetic and concatenate them.
390
+ constexpr static auto kBase = UINT64_C(10'000'000'000'000'000'000);
391
+ constexpr static size_t kBaseDigits = 19;
392
+
393
+ size_t p = 0;
394
+ const auto leading = [&](Usrc v) {
395
+ assert(v >> 64 == 0);
396
+ p = detail::to_ascii_with_route<10, to_ascii_alphabet_lower>(
397
+ outb, oute, static_cast<uint64_t>(v));
398
+ };
399
+ const auto append = [&](uint64_t v) {
400
+ assert(v < kBase);
401
+ assert(outb + p + kBaseDigits <= oute);
402
+ auto v64 = static_cast<uint64_t>(v);
403
+ detail::to_ascii_with_route<10, to_ascii_alphabet_lower>(
404
+ outb + p, kBaseDigits, v64);
405
+ p += kBaseDigits;
406
+ };
407
+
408
+ if (x >> 64 > 0) {
409
+ const auto rem = static_cast<uint64_t>(x % kBase);
410
+ x /= kBase;
411
+
412
+ if (x >> 64 > 0) {
413
+ const auto rem2 = static_cast<uint64_t>(x % kBase);
414
+ x /= kBase;
415
+
416
+ leading(x);
417
+ append(rem2);
418
+ append(rem);
419
+ return p;
420
+ }
421
+
422
+ leading(x);
423
+ append(rem);
424
+ return p;
425
+ }
426
+
427
+ leading(x);
428
+ return p;
429
+ }
430
+
431
+ } // namespace detail
432
+ #endif
433
+
434
+ /**
435
+ * @overloadbrief Appends conversion to string.
436
+ *
437
+ * A single char gets appended.
438
+ */
439
+ template <class Tgt>
440
+ void toAppend(char value, Tgt* result) {
441
+ *result += value;
442
+ }
443
+
444
+ /**
445
+ * @overloadbrief Estimates the number of characters in a value's string
446
+ * representation.
447
+ */
448
+ template <class T>
449
+ constexpr typename std::enable_if<std::is_same<T, char>::value, size_t>::type
450
+ estimateSpaceNeeded(T) {
451
+ return 1;
452
+ }
453
+
454
+ template <size_t N>
455
+ constexpr size_t estimateSpaceNeeded(const char (&)[N]) {
456
+ return N;
457
+ }
458
+
459
+ /**
460
+ * Everything implicitly convertible to const char* gets appended.
461
+ */
462
+ template <class Tgt, class Src>
463
+ typename std::enable_if<
464
+ std::is_convertible<Src, const char*>::value &&
465
+ IsSomeString<Tgt>::value>::type
466
+ toAppend(Src value, Tgt* result) {
467
+ // Treat null pointers like an empty string, as in:
468
+ // operator<<(std::ostream&, const char*).
469
+ const char* c = value;
470
+ if (c) {
471
+ result->append(value);
472
+ }
473
+ }
474
+
475
+ template <class Src>
476
+ typename std::enable_if<std::is_convertible<Src, const char*>::value, size_t>::
477
+ type
478
+ estimateSpaceNeeded(Src value) {
479
+ const char* c = value;
480
+ return c ? std::strlen(c) : 0;
481
+ }
482
+
483
+ template <class Src>
484
+ typename std::enable_if<IsSomeString<Src>::value, size_t>::type
485
+ estimateSpaceNeeded(Src const& value) {
486
+ return value.size();
487
+ }
488
+
489
+ template <class Src>
490
+ typename std::enable_if<
491
+ std::is_convertible<Src, folly::StringPiece>::value &&
492
+ !IsSomeString<Src>::value &&
493
+ !std::is_convertible<Src, const char*>::value,
494
+ size_t>::type
495
+ estimateSpaceNeeded(Src value) {
496
+ return folly::StringPiece(value).size();
497
+ }
498
+
499
+ template <>
500
+ inline size_t estimateSpaceNeeded(std::nullptr_t /* value */) {
501
+ return 0;
502
+ }
503
+
504
+ template <class Src>
505
+ typename std::enable_if<
506
+ std::is_pointer<Src>::value &&
507
+ IsSomeString<std::remove_pointer<Src>>::value,
508
+ size_t>::type
509
+ estimateSpaceNeeded(Src value) {
510
+ return value->size();
511
+ }
512
+
513
+ /**
514
+ * Strings get appended, too.
515
+ */
516
+ template <class Tgt, class Src>
517
+ typename std::enable_if<
518
+ IsSomeString<Src>::value && IsSomeString<Tgt>::value>::type
519
+ toAppend(const Src& value, Tgt* result) {
520
+ result->append(value);
521
+ }
522
+
523
+ /**
524
+ * and StringPiece objects too
525
+ */
526
+ template <class Tgt>
527
+ typename std::enable_if<IsSomeString<Tgt>::value>::type toAppend(
528
+ StringPiece value, Tgt* result) {
529
+ result->append(value.data(), value.size());
530
+ }
531
+
532
+ /**
533
+ * There's no implicit conversion from fbstring to other string types,
534
+ * so make a specialization.
535
+ */
536
+ template <class Tgt>
537
+ typename std::enable_if<IsSomeString<Tgt>::value>::type toAppend(
538
+ const fbstring& value, Tgt* result) {
539
+ result->append(value.data(), value.size());
540
+ }
541
+
542
+ #if FOLLY_HAVE_INT128_T
543
+ /**
544
+ * Special handling for 128 bit integers.
545
+ */
546
+
547
+ template <class Tgt>
548
+ void toAppend(__int128 value, Tgt* result) {
549
+ typedef unsigned __int128 Usrc;
550
+ char buffer[detail::digitsEnough<unsigned __int128>() + 1];
551
+ const auto oute = buffer + sizeof(buffer);
552
+ size_t p;
553
+
554
+ if (value < 0) {
555
+ buffer[0] = '-';
556
+ p = 1 + detail::unsafeTelescope128(buffer + 1, oute, -Usrc(value));
557
+ } else {
558
+ p = detail::unsafeTelescope128(buffer, oute, value);
559
+ }
560
+
561
+ result->append(buffer, p);
562
+ }
563
+
564
+ template <class Tgt>
565
+ void toAppend(unsigned __int128 value, Tgt* result) {
566
+ char buffer[detail::digitsEnough<unsigned __int128>()];
567
+ size_t p = detail::unsafeTelescope128(buffer, buffer + sizeof(buffer), value);
568
+ result->append(buffer, p);
569
+ }
570
+
571
+ template <class T>
572
+ constexpr
573
+ typename std::enable_if<std::is_same<T, __int128>::value, size_t>::type
574
+ estimateSpaceNeeded(T) {
575
+ return detail::digitsEnough<__int128>();
576
+ }
577
+
578
+ template <class T>
579
+ constexpr typename std::
580
+ enable_if<std::is_same<T, unsigned __int128>::value, size_t>::type
581
+ estimateSpaceNeeded(T) {
582
+ return detail::digitsEnough<unsigned __int128>();
583
+ }
584
+
585
+ #endif
586
+
587
+ /**
588
+ * int32_t and int64_t to string (by appending) go through here. The
589
+ * result is APPENDED to a preexisting string passed as the second
590
+ * parameter. This should be efficient with fbstring because fbstring
591
+ * incurs no dynamic allocation below 23 bytes and no number has more
592
+ * than 22 bytes in its textual representation (20 for digits, one for
593
+ * sign, one for the terminating 0).
594
+ */
595
+ template <class Tgt, class Src>
596
+ typename std::enable_if<
597
+ is_integral_v<Src> && is_signed_v<Src> && IsSomeString<Tgt>::value &&
598
+ sizeof(Src) >= 4>::type
599
+ toAppend(Src value, Tgt* result) {
600
+ char buffer[to_ascii_size_max_decimal<uint64_t>];
601
+ auto uvalue = value < 0 ? ~static_cast<uint64_t>(value) + 1
602
+ : static_cast<uint64_t>(value);
603
+ if (value < 0) {
604
+ result->push_back('-');
605
+ }
606
+ result->append(buffer, to_ascii_decimal(buffer, uvalue));
607
+ }
608
+
609
+ template <class Src>
610
+ typename std::enable_if<
611
+ is_integral_v<Src> && is_signed_v<Src> && sizeof(Src) >= 4 &&
612
+ sizeof(Src) < 16,
613
+ size_t>::type
614
+ estimateSpaceNeeded(Src value) {
615
+ auto uvalue = value < 0 ? ~static_cast<uint64_t>(value) + 1
616
+ : static_cast<uint64_t>(value);
617
+ return size_t(value < 0) + to_ascii_size_decimal(uvalue);
618
+ }
619
+
620
+ /**
621
+ * As above, but for uint32_t and uint64_t.
622
+ */
623
+ template <class Tgt, class Src>
624
+ typename std::enable_if<
625
+ is_integral_v<Src> && !is_signed_v<Src> && IsSomeString<Tgt>::value &&
626
+ sizeof(Src) >= 4>::type
627
+ toAppend(Src value, Tgt* result) {
628
+ char buffer[to_ascii_size_max_decimal<uint64_t>];
629
+ result->append(buffer, to_ascii_decimal(buffer, value));
630
+ }
631
+
632
+ template <class Src>
633
+ typename std::enable_if<
634
+ is_integral_v<Src> && !is_signed_v<Src> && sizeof(Src) >= 4 &&
635
+ sizeof(Src) < 16,
636
+ size_t>::type
637
+ estimateSpaceNeeded(Src value) {
638
+ return to_ascii_size_decimal(value);
639
+ }
640
+
641
+ /**
642
+ * All small signed and unsigned integers to string go through 32-bit
643
+ * types int32_t and uint32_t, respectively.
644
+ */
645
+ template <class Tgt, class Src>
646
+ typename std::enable_if<
647
+ is_integral_v<Src> && IsSomeString<Tgt>::value && sizeof(Src) < 4>::type
648
+ toAppend(Src value, Tgt* result) {
649
+ typedef typename std::conditional<is_signed_v<Src>, int64_t, uint64_t>::type
650
+ Intermediate;
651
+ toAppend<Tgt>(static_cast<Intermediate>(value), result);
652
+ }
653
+
654
+ template <class Src>
655
+ typename std::enable_if<
656
+ is_integral_v<Src> && sizeof(Src) < 4 && !std::is_same<Src, char>::value,
657
+ size_t>::type
658
+ estimateSpaceNeeded(Src value) {
659
+ typedef typename std::conditional<is_signed_v<Src>, int64_t, uint64_t>::type
660
+ Intermediate;
661
+ return estimateSpaceNeeded(static_cast<Intermediate>(value));
662
+ }
663
+
664
+ /**
665
+ * Enumerated values get appended as integers.
666
+ */
667
+ template <class Tgt, class Src>
668
+ typename std::enable_if<
669
+ std::is_enum<Src>::value && IsSomeString<Tgt>::value>::type
670
+ toAppend(Src value, Tgt* result) {
671
+ toAppend(to_underlying(value), result);
672
+ }
673
+
674
+ template <class Src>
675
+ typename std::enable_if<std::is_enum<Src>::value, size_t>::type
676
+ estimateSpaceNeeded(Src value) {
677
+ return estimateSpaceNeeded(to_underlying(value));
678
+ }
679
+
680
+ /**
681
+ * Conversions from floating-point types to string types.
682
+ */
683
+
684
+ /// Operating mode for the floating point type version of
685
+ /// `folly::ToAppend`. This is modeled after
686
+ /// `double_conversion::DoubleToStringConverter::DtoaMode`.
687
+ /// Dtoa is an acryonym for Double to ASCII.
688
+ enum class DtoaMode {
689
+ /// Outputs the shortest representation of a `double`.
690
+ /// The output is either in decimal or exponential notation; which ever is
691
+ /// shortest.
692
+ SHORTEST,
693
+ /// Outputs the shortest representation of a `float`.
694
+ /// This outputs in either decimal or exponential notation, which ever is
695
+ /// shortest.
696
+ SHORTEST_SINGLE,
697
+ /// Outputs fixed precision after the decimal point. Similar to
698
+ /// `printf`'s %f.
699
+ /// The output is in decimal notation.
700
+ /// Use the `numDigits` parameter to specify the precision.
701
+ FIXED,
702
+ /// Outputs with a precision that is independent of the decimal point.
703
+ /// The outputs is either decimal or exponential notation, depending on the
704
+ /// value and the precision.
705
+ /// Similar to `printf`'s %g formating.
706
+ /// Use the `numDigits` parameter to specify the precision.
707
+ PRECISION,
708
+ };
709
+
710
+ /// Flags for the floating point type version of `folly::ToAppend`.
711
+ /// This is modeled after `double_conversion::DoubleToStringConverter::Flags`.
712
+ /// Dtoa is an acryonym for Double to ASCII.
713
+ /// This enum is used to store bit wise flags, so a variable of this type may be
714
+ /// a bitwise combination of these definitions.
715
+ enum class DtoaFlags {
716
+ NO_FLAGS = 0,
717
+ /// Emits a plus sign for positive exponents. e.g., 1.2e+3
718
+ EMIT_POSITIVE_EXPONENT_SIGN = 1,
719
+ /// Emits a trailing decimal point. e.g., 123.
720
+ EMIT_TRAILING_DECIMAL_POINT = 2,
721
+ /// Emits a trailing decimal point. e.g., 123.0
722
+ /// Requires `EMIT_TRAILING_DECIMAL_POINT` to be set.
723
+ EMIT_TRAILING_ZERO_AFTER_POINT = 4,
724
+ /// -0.0 outputs as 0.0
725
+ UNIQUE_ZERO = 8,
726
+ /// Trailing zeros are removed from the fractional portion
727
+ /// of the result in precision mode. Matches `printf`'s %g.
728
+ /// When `EMIT_TRAILING_ZERO_AFTER_POINT` is also given, one trailing zero is
729
+ /// preserved.
730
+ NO_TRAILING_ZERO = 16,
731
+ };
732
+
733
+ constexpr DtoaFlags operator|(DtoaFlags a, DtoaFlags b) {
734
+ return static_cast<DtoaFlags>(to_underlying(a) | to_underlying(b));
735
+ }
736
+
737
+ constexpr DtoaFlags operator&(DtoaFlags a, DtoaFlags b) {
738
+ return static_cast<DtoaFlags>(to_underlying(a) & to_underlying(b));
739
+ }
740
+
741
+ namespace detail {
742
+ constexpr int kConvMaxDecimalInShortestLow = -6;
743
+ /// 10^kConvMaxDecimalInShortestLow. Replace with constexpr std::pow in C++26.
744
+ constexpr double kConvMaxDecimalInShortestLowValue = 0.000001;
745
+ constexpr int kConvMaxDecimalInShortestHigh = 21;
746
+ /// 10^kConvMaxDecimalInShortestHigh. Replace with constexpr std::pow in C++26.
747
+ constexpr double kConvMaxDecimalInShortestHighValue =
748
+ 1'000'000'000'000'000'000'000.0;
749
+ constexpr int kBase10MaximalLength = 17;
750
+
751
+ enum class FloatToStringImpl {
752
+ LibDoubleConversion,
753
+ StdToChars,
754
+ };
755
+
756
+ #if defined(FOLLY_CONV_USE_TO_CHARS) && FOLLY_CONV_USE_TO_CHARS == 1
757
+ constexpr FloatToStringImpl kConvFloatToStringImpl =
758
+ FloatToStringImpl::StdToChars;
759
+ constexpr int kConvMaxFixedDigitsAfterPoint = 100;
760
+ constexpr int kConvMaxPrecisionDigits = 120;
761
+ #else
762
+ constexpr FloatToStringImpl kConvFloatToStringImpl =
763
+ FloatToStringImpl::LibDoubleConversion;
764
+ constexpr int kConvMaxFixedDigitsAfterPoint =
765
+ double_conversion::DoubleToStringConverter::kMaxFixedDigitsAfterPoint;
766
+ constexpr int kConvMaxPrecisionDigits =
767
+ double_conversion::DoubleToStringConverter::kMaxPrecisionDigits;
768
+
769
+ /// Converts `DtoaMode` to
770
+ /// `double_conversion::DoubleToStringConverter::DtoaMode`.
771
+ /// This is temporary until
772
+ /// `double_conversion::DoubleToStringConverter::DtoaMode` is removed.
773
+ constexpr double_conversion::DoubleToStringConverter::DtoaMode convert(
774
+ DtoaMode mode) {
775
+ switch (mode) {
776
+ case DtoaMode::SHORTEST:
777
+ return double_conversion::DoubleToStringConverter::SHORTEST;
778
+ case DtoaMode::SHORTEST_SINGLE:
779
+ return double_conversion::DoubleToStringConverter::SHORTEST_SINGLE;
780
+ case DtoaMode::FIXED:
781
+ return double_conversion::DoubleToStringConverter::FIXED;
782
+ case DtoaMode::PRECISION:
783
+ return double_conversion::DoubleToStringConverter::PRECISION;
784
+ }
785
+
786
+ assert(false);
787
+ // Default to PRECISION per exising behavior.
788
+ return double_conversion::DoubleToStringConverter::PRECISION;
789
+ }
790
+
791
+ /// Converts `DtoaFlags` to
792
+ /// `double_conversion::DoubleToStringConverter::DtoaFlags`.
793
+ /// This is temporary until
794
+ /// `double_conversion::DoubleToStringConverter::DtoaFlags` is removed.
795
+ constexpr double_conversion::DoubleToStringConverter::Flags convert(
796
+ DtoaFlags flags) {
797
+ return static_cast<double_conversion::DoubleToStringConverter::Flags>(flags);
798
+ }
799
+
800
+ /**
801
+ * Wrapper around `double_conversion::DoubleToStringConverter`.
802
+ */
803
+ template <class Tgt, class Src>
804
+ typename std::enable_if<
805
+ std::is_floating_point<Src>::value && IsSomeString<Tgt>::value>::type
806
+ toAppendDoubleConversion(
807
+ Src value,
808
+ Tgt* result,
809
+ DtoaMode mode,
810
+ unsigned int numDigits,
811
+ DtoaFlags flags = DtoaFlags::NO_FLAGS) {
812
+ using namespace double_conversion;
813
+ DoubleToStringConverter::Flags dcFlags = detail::convert(flags);
814
+ DoubleToStringConverter conv(
815
+ dcFlags,
816
+ "Infinity",
817
+ "NaN",
818
+ 'E',
819
+ detail::kConvMaxDecimalInShortestLow,
820
+ detail::kConvMaxDecimalInShortestHigh,
821
+ 6, // max leading padding zeros
822
+ 1); // max trailing padding zeros
823
+ char buffer[256];
824
+ StringBuilder builder(buffer, sizeof(buffer));
825
+ DoubleToStringConverter::DtoaMode dcMode = detail::convert(mode);
826
+ FOLLY_PUSH_WARNING
827
+ FOLLY_CLANG_DISABLE_WARNING("-Wcovered-switch-default")
828
+ switch (dcMode) {
829
+ case DoubleToStringConverter::SHORTEST:
830
+ conv.ToShortest(value, &builder);
831
+ break;
832
+ case DoubleToStringConverter::SHORTEST_SINGLE:
833
+ conv.ToShortestSingle(static_cast<float>(value), &builder);
834
+ break;
835
+ case DoubleToStringConverter::FIXED:
836
+ conv.ToFixed(value, int(numDigits), &builder);
837
+ break;
838
+ case DoubleToStringConverter::PRECISION:
839
+ default:
840
+ assert(dcMode == DoubleToStringConverter::PRECISION);
841
+ conv.ToPrecision(value, int(numDigits), &builder);
842
+ break;
843
+ }
844
+ FOLLY_POP_WARNING
845
+ const size_t length = size_t(builder.position());
846
+ builder.Finalize();
847
+ result->append(buffer, length);
848
+ }
849
+ #endif // FOLLY_CONV_USE_TO_CHARS
850
+
851
+ #if defined(FOLLY_CONV_AVALIABILITY_TO_CHARS_FLOATING_POINT) && \
852
+ FOLLY_CONV_AVALIABILITY_TO_CHARS_FLOATING_POINT == 1
853
+ /// Holds a set of `DtoaFlags` as a bitwise OR of the flags.
854
+ /// It has convience member functions to check if a flag is set.
855
+ struct DtoaFlagsSet {
856
+ explicit DtoaFlagsSet(DtoaFlags flags);
857
+
858
+ bool isSet(DtoaFlags flag) const;
859
+
860
+ bool emitPositiveExponentSign() const;
861
+ bool emitTrailingDecimalPoint() const;
862
+ bool emitTrailingZeroAfterPoint() const;
863
+ bool uniqueZero() const;
864
+ bool noTrailingZero() const;
865
+
866
+ private:
867
+ DtoaFlags flags_;
868
+ };
869
+ /// This parses a decimal string into a structured format.
870
+ /// For example, given "123.456e+7", this will create pointers to the integer,
871
+ /// fractional, exponentional parts.
872
+ ///
873
+ /// The decimal string is passed in as a `char` buffer with begin and end
874
+ /// pointers. The parsing will create pointers to parts of the decimal string.
875
+ ///
876
+ /// e.g.,
877
+ /// -123.456e+78
878
+ /// ABCDEFGHIJK
879
+ /// negativeSign points to address A
880
+ /// integerBegin points to address B
881
+ /// integerEnd points to address E
882
+ /// and so on...
883
+ ///
884
+ /// The is used to format the output of `std::to_chars` so that it is consistent
885
+ /// with `double_conversion::DoubleToStringConverter`'s format.
886
+ ///
887
+ /// This also has helper member functions to identify parts needed to apply
888
+ /// `DtoaMode::PRECISION` formating.
889
+ class ParsedDecimal {
890
+ public:
891
+ char* negativeSign{};
892
+ char* integerBegin{};
893
+ char* integerEnd{};
894
+ char* decimalPoint{};
895
+ char* fractionalBegin{};
896
+ char* fractionalEnd{};
897
+ char* exponentSymbol{};
898
+ char* exponentSign{};
899
+ char* exponentBegin{};
900
+ char* exponentEnd{};
901
+
902
+ ParsedDecimal(char* begin, char* end);
903
+
904
+ /// Returns the number of figures that count in PRECISION/general mode.
905
+ /// This is needed to know how many more figures to add when NO_TRAILING_ZERO
906
+ /// is unset.
907
+ int numPrecisionFigures() const;
908
+
909
+ /// first is the begin pointer of the fractional suffix.
910
+ /// second is the end pointer of the fractional suffix.
911
+ using FractionalSuffix = std::pair<char*, char*>;
912
+
913
+ /// Returns pointers to the suffix after the fraction.
914
+ /// e.g., for "12.34-56" this returns pointers to "e-56".
915
+ /// Returns nothing if there is no suffix (e.g., "7.89").
916
+ std::optional<FractionalSuffix> fractionalSuffix() const;
917
+
918
+ /// Shifts the pointers of the fractional suffix by the given amount.
919
+ /// This is used when inserting additional figures for `DtoaMode::PRECISION`.
920
+ /// The pointers need to be updated after the fractional suffix is `memmove`'d
921
+ /// to accommodate the additional figures.
922
+ void shiftFractionalSuffixPtrs(size_t amount);
923
+ };
924
+
925
+ /// Formats the output from `std::to_chars` as if it came from
926
+ /// `double_conversion::DoubleToStringConverter`.
927
+ ///
928
+ /// Specifically it adds support for:
929
+ /// - EMIT_POSITIVE_EXPONENT_SIGN
930
+ /// - EMIT_TRAILING_DECIMAL_POINT
931
+ /// - EMIT_TRAILING_ZERO_AFTER_POINT
932
+ /// - UNIQUE_ZERO
933
+ /// - NO_TRAILING_ZERO
934
+ /// - Captial E exponent sign (e.g., 1.23e4 -> 1.23E4)
935
+ /// - Removes leading zeros in exponent (e.g., 1.23e04 -> 1.23e4)
936
+ ///
937
+ /// This modifies the result buffer in place to match the output format of
938
+ /// `double_conversion::DoubleToStringConverter`.
939
+ /// `resultBegin` is the begin pointer of the result from `std::to_chars`.
940
+ /// `resultEnd` is the end pointer of the result from `std::to_chars`.
941
+ /// `bufferEnd` is the end pointer of the buffer space given to `std::to_chars`.
942
+ /// The extra buffer space is used to expand the result.
943
+ /// `resultBegin`, `resultEnd`, and `bufferEnd` must point to the same buffer.
944
+ ///
945
+ /// The first char* of the return type is the begin pointer of the newly
946
+ /// formatted output. The second char* of the return type is the begin pointer
947
+ /// of the newly formatted output.
948
+ std::pair<char*, char*> formatAsDoubleConversion(
949
+ bool valueIsZero,
950
+ DtoaMode mode,
951
+ unsigned int numDigits,
952
+ DtoaFlags flags,
953
+ char* resultBegin,
954
+ char* resultEnd,
955
+ char* bufferEnd);
956
+
957
+ template <class Tgt, class Src>
958
+ typename std::enable_if<
959
+ std::is_floating_point<Src>::value && IsSomeString<Tgt>::value>::type
960
+ toAppendStdToChars(
961
+ Src value,
962
+ Tgt* result,
963
+ DtoaMode mode,
964
+ unsigned int numDigits,
965
+ DtoaFlags flags = DtoaFlags::NO_FLAGS) {
966
+ if (std::isnan(value)) {
967
+ // no signbit check because -nan outputs as NaN
968
+ result->append("NaN", 3);
969
+ return;
970
+ }
971
+
972
+ if (std::isinf(value)) {
973
+ if (std::signbit(value)) {
974
+ result->append("-", 1);
975
+ }
976
+ // std::to_chars returns "inf", this needs "Infinity"
977
+ result->append("Infinity", 8);
978
+ return;
979
+ }
980
+
981
+ if (mode == DtoaMode::PRECISION &&
982
+ (numDigits == 0 || numDigits > detail::kConvMaxPrecisionDigits)) {
983
+ // double_conversion outputs the empty string in this scenario
984
+ return;
985
+ }
986
+
987
+ if (mode == DtoaMode::FIXED &&
988
+ numDigits > detail::kConvMaxFixedDigitsAfterPoint) {
989
+ // double_conversion outputs the empty string in this scenario
990
+ return;
991
+ }
992
+
993
+ bool useShortestFixed{false};
994
+ if (mode == DtoaMode::SHORTEST || mode == DtoaMode::SHORTEST_SINGLE) {
995
+ Src absValue = std::abs(value);
996
+ // use fixed decimal notation (i.e., not exponential notation)
997
+ // for values in this range to match double-conversion formatting.
998
+ useShortestFixed = kConvMaxDecimalInShortestLowValue <= absValue &&
999
+ absValue < kConvMaxDecimalInShortestHighValue;
1000
+ }
1001
+
1002
+ std::to_chars_result conv_result;
1003
+ char buffer[256];
1004
+ char* const bufferEnd = buffer + sizeof(buffer);
1005
+ FOLLY_PUSH_WARNING
1006
+ FOLLY_CLANG_DISABLE_WARNING("-Wcovered-switch-default")
1007
+ switch (mode) {
1008
+ case DtoaMode::SHORTEST: {
1009
+ if (useShortestFixed) {
1010
+ conv_result =
1011
+ std::to_chars(buffer, bufferEnd, value, std::chars_format::fixed);
1012
+ } else {
1013
+ conv_result = std::to_chars(buffer, bufferEnd, value);
1014
+ }
1015
+ break;
1016
+ }
1017
+ case DtoaMode::SHORTEST_SINGLE:
1018
+ if (useShortestFixed) {
1019
+ conv_result = std::to_chars(
1020
+ buffer,
1021
+ bufferEnd,
1022
+ static_cast<float>(value),
1023
+ std::chars_format::fixed);
1024
+ } else {
1025
+ conv_result =
1026
+ std::to_chars(buffer, bufferEnd, static_cast<float>(value));
1027
+ }
1028
+ break;
1029
+ case DtoaMode::FIXED:
1030
+ conv_result = std::to_chars(
1031
+ buffer, bufferEnd, value, std::chars_format::fixed, numDigits);
1032
+ break;
1033
+ case DtoaMode::PRECISION:
1034
+ default:
1035
+ assert(mode == DtoaMode::PRECISION);
1036
+ conv_result = std::to_chars(
1037
+ buffer, bufferEnd, value, std::chars_format::general, numDigits);
1038
+ break;
1039
+ }
1040
+ FOLLY_POP_WARNING
1041
+
1042
+ auto [resultEnd, ec] = conv_result;
1043
+ if (ec != std::errc()) {
1044
+ folly::throw_exception<std::system_error>(std::make_error_code(ec));
1045
+ }
1046
+
1047
+ char* resultBegin = buffer;
1048
+ bool valueIsZero = value == 0.0;
1049
+ auto [formattedBegin, formattedEnd] = detail::formatAsDoubleConversion(
1050
+ valueIsZero, mode, numDigits, flags, resultBegin, resultEnd, bufferEnd);
1051
+
1052
+ result->append(formattedBegin, formattedEnd - formattedBegin);
1053
+ }
1054
+ #endif // FOLLY_CONV_AVALIABILITY_TO_CHARS_FLOATING_POINT
1055
+ } // namespace detail
1056
+
1057
+ /**
1058
+ * `numDigits` is only used with `FIXED` && `PRECISION`.
1059
+ */
1060
+ template <class Tgt, class Src>
1061
+ typename std::enable_if<
1062
+ std::is_floating_point<Src>::value && IsSomeString<Tgt>::value>::type
1063
+ toAppend(
1064
+ Src value,
1065
+ Tgt* result,
1066
+ DtoaMode mode,
1067
+ unsigned int numDigits,
1068
+ DtoaFlags flags = DtoaFlags::NO_FLAGS) {
1069
+ #if defined(FOLLY_CONV_USE_TO_CHARS) && FOLLY_CONV_USE_TO_CHARS == 1
1070
+ detail::toAppendStdToChars(value, result, mode, numDigits, flags);
1071
+ #else
1072
+ detail::toAppendDoubleConversion(value, result, mode, numDigits, flags);
1073
+ #endif
1074
+ }
1075
+
1076
+ /**
1077
+ * As above, but for floating point
1078
+ */
1079
+ template <class Tgt, class Src>
1080
+ typename std::enable_if<
1081
+ std::is_floating_point<Src>::value && IsSomeString<Tgt>::value>::type
1082
+ toAppend(Src value, Tgt* result) {
1083
+ toAppend(value, result, DtoaMode::SHORTEST, 0);
1084
+ }
1085
+
1086
+ /**
1087
+ * Upper bound of the length of the output from
1088
+ * DoubleToStringConverter::ToShortest(double, StringBuilder*),
1089
+ * as used in toAppend(double, string*).
1090
+ */
1091
+ template <class Src>
1092
+ typename std::enable_if<std::is_floating_point<Src>::value, size_t>::type
1093
+ estimateSpaceNeeded(Src value) {
1094
+ // kBase10MaximalLength is 17. We add 1 for decimal point,
1095
+ // e.g. 10.0/9 is 17 digits and 18 characters, including the decimal point.
1096
+ constexpr int kMaxMantissaSpace = detail::kBase10MaximalLength + 1;
1097
+ // strlen("E-") + digits10(numeric_limits<double>::max_exponent10)
1098
+ constexpr int kMaxExponentSpace = 2 + 3;
1099
+ static const int kMaxPositiveSpace = std::max({
1100
+ // E.g. 1.1111111111111111E-100.
1101
+ kMaxMantissaSpace + kMaxExponentSpace,
1102
+ // E.g. 0.000001.1111111111111111, if kConvMaxDecimalInShortestLow is -6.
1103
+ kMaxMantissaSpace - detail::kConvMaxDecimalInShortestLow,
1104
+ // If kConvMaxDecimalInShortestHigh is 21, then 1e21 is the smallest
1105
+ // number > 1 which ToShortest outputs in exponential notation,
1106
+ // so 21 is the longest non-exponential number > 1.
1107
+ detail::kConvMaxDecimalInShortestHigh,
1108
+ });
1109
+ return size_t(
1110
+ kMaxPositiveSpace +
1111
+ (value < 0 ? 1 : 0)); // +1 for minus sign, if negative
1112
+ }
1113
+
1114
+ template <class Src>
1115
+ constexpr typename std::enable_if<
1116
+ !std::is_fundamental<Src>::value &&
1117
+ #if FOLLY_HAVE_INT128_T
1118
+ // On OSX 10.10, is_fundamental<__int128> is false :-O
1119
+ !std::is_same<__int128, Src>::value &&
1120
+ !std::is_same<unsigned __int128, Src>::value &&
1121
+ #endif
1122
+ !IsSomeString<Src>::value &&
1123
+ !std::is_convertible<Src, const char*>::value &&
1124
+ !std::is_convertible<Src, StringPiece>::value &&
1125
+ !std::is_enum<Src>::value,
1126
+ size_t>::type
1127
+ estimateSpaceNeeded(const Src&) {
1128
+ return sizeof(Src) + 1; // dumbest best effort ever?
1129
+ }
1130
+
1131
+ #ifndef DOXYGEN_SHOULD_SKIP_THIS
1132
+ namespace detail {
1133
+
1134
+ FOLLY_ERASE constexpr size_t estimateSpaceToReserveOne(std::false_type, void*) {
1135
+ return 0;
1136
+ }
1137
+ template <typename T>
1138
+ FOLLY_ERASE constexpr size_t estimateSpaceToReserveOne(
1139
+ std::true_type, const T& v) {
1140
+ return estimateSpaceNeeded(v);
1141
+ }
1142
+
1143
+ template <typename>
1144
+ struct EstimateSpaceToReserveAll;
1145
+ template <size_t... I>
1146
+ struct EstimateSpaceToReserveAll<std::index_sequence<I...>> {
1147
+ template <size_t J, size_t N = sizeof...(I)>
1148
+ using tag = std::bool_constant<J + 1 < N>;
1149
+ template <class... T>
1150
+ static size_t call(const T&... v) {
1151
+ const size_t sizes[] = {estimateSpaceToReserveOne(tag<I>{}, v)...};
1152
+ size_t size = 0;
1153
+ for (const auto s : sizes) {
1154
+ size += s;
1155
+ }
1156
+ return size;
1157
+ }
1158
+ };
1159
+
1160
+ template <class O>
1161
+ void reserveInTarget(const O& o) {
1162
+ (void)o;
1163
+ }
1164
+ template <class T, class O>
1165
+ void reserveInTarget(const T& v, const O& o) {
1166
+ o->reserve(estimateSpaceNeeded(v));
1167
+ }
1168
+ template <class T0, class T1, class... Ts>
1169
+ void reserveInTarget(const T0& v0, const T1& v1, const Ts&... vs) {
1170
+ using seq = std::index_sequence_for<T0, T1, Ts...>;
1171
+ getLastElement(vs...)->reserve(
1172
+ EstimateSpaceToReserveAll<seq>::call(v0, v1, vs...));
1173
+ }
1174
+
1175
+ template <class Delimiter, class... Ts>
1176
+ void reserveInTargetDelim(const Delimiter& d, const Ts&... vs) {
1177
+ static_assert(sizeof...(vs) >= 2, "Needs at least 2 args");
1178
+ using seq = std::index_sequence_for<Ts...>;
1179
+ size_t fordelim = (sizeof...(vs) - 2) * estimateSpaceNeeded(d);
1180
+ getLastElement(vs...)->reserve(
1181
+ fordelim + EstimateSpaceToReserveAll<seq>::call(vs...));
1182
+ }
1183
+
1184
+ template <class T>
1185
+ FOLLY_ERASE constexpr int toAppendStrImplOne(
1186
+ std::false_type, const T& v, void*) {
1187
+ (void)v;
1188
+ return 0;
1189
+ }
1190
+ template <class T, class Tgt>
1191
+ FOLLY_ERASE int toAppendStrImplOne(std::true_type, const T& v, Tgt result) {
1192
+ return toAppend(v, result), 0;
1193
+ }
1194
+ template <typename>
1195
+ struct ToAppendStrImplAll;
1196
+ template <size_t... I>
1197
+ struct ToAppendStrImplAll<std::index_sequence<I...>> {
1198
+ template <class... T>
1199
+ static void call(const T&... v) {
1200
+ using _ = int[];
1201
+ auto r = getLastElement(v...);
1202
+ void(_{toAppendStrImplOne(
1203
+ std::bool_constant<I + 1 < sizeof...(T)>{}, v, r)...});
1204
+ }
1205
+ };
1206
+
1207
+ template <class Delimiter, class T>
1208
+ FOLLY_ERASE constexpr int toAppendDelimStrImplOne(
1209
+ index_constant<0>, const Delimiter& d, const T& v, void*) {
1210
+ (void)d;
1211
+ (void)v;
1212
+ return 0;
1213
+ }
1214
+ template <class Delimiter, class T, class Tgt>
1215
+ FOLLY_ERASE int toAppendDelimStrImplOne(
1216
+ index_constant<1>, const Delimiter& d, const T& v, Tgt result) {
1217
+ (void)d;
1218
+ toAppend(v, result);
1219
+ return 0;
1220
+ }
1221
+ template <class Delimiter, class T, class Tgt>
1222
+ FOLLY_ERASE int toAppendDelimStrImplOne(
1223
+ index_constant<2>, const Delimiter& d, const T& v, Tgt result) {
1224
+ toAppend(v, result);
1225
+ toAppend(d, result);
1226
+ return 0;
1227
+ }
1228
+ template <typename>
1229
+ struct ToAppendDelimStrImplAll;
1230
+ template <size_t... I>
1231
+ struct ToAppendDelimStrImplAll<std::index_sequence<I...>> {
1232
+ template <size_t J, size_t N = sizeof...(I), size_t K = N - J - 1>
1233
+ using tag = index_constant<(K < 2 ? K : 2)>;
1234
+ template <class Delimiter, class... T>
1235
+ static void call(const Delimiter& d, const T&... v) {
1236
+ using _ = int[];
1237
+ auto r = detail::getLastElement(v...);
1238
+ void(_{toAppendDelimStrImplOne(tag<I>{}, d, v, r)...});
1239
+ }
1240
+ };
1241
+ template <
1242
+ class Delimiter,
1243
+ class T,
1244
+ class... Ts,
1245
+ std::enable_if_t<
1246
+ sizeof...(Ts) >= 2 &&
1247
+ IsSomeString<typename std::remove_pointer<
1248
+ detail::LastElement<Ts...>>::type>::value,
1249
+ int> = 0>
1250
+ void toAppendDelimStrImpl(const Delimiter& delim, const T& v, const Ts&... vs) {
1251
+ using seq = std::index_sequence_for<T, Ts...>;
1252
+ ToAppendDelimStrImplAll<seq>::call(delim, v, vs...);
1253
+ }
1254
+ } // namespace detail
1255
+ #endif
1256
+
1257
+ /**
1258
+ * Variadic conversion to string. Appends each element in turn.
1259
+ * If we have two or more things to append, we will not reserve
1260
+ * the space for them and will depend on strings exponential growth.
1261
+ * If you just append once consider using toAppendFit which reserves
1262
+ * the space needed (but does not have exponential as a result).
1263
+ *
1264
+ * Custom implementations of toAppend() can be provided in the same namespace as
1265
+ * the type to customize printing. estimateSpaceNeed() may also be provided to
1266
+ * avoid reallocations in toAppendFit():
1267
+ *
1268
+ * namespace other_namespace {
1269
+ *
1270
+ * template <class String>
1271
+ * void toAppend(const OtherType&, String* out);
1272
+ *
1273
+ * // optional
1274
+ * size_t estimateSpaceNeeded(const OtherType&);
1275
+ *
1276
+ * }
1277
+ */
1278
+ template <
1279
+ class... Ts,
1280
+ std::enable_if_t<
1281
+ sizeof...(Ts) >= 3 &&
1282
+ IsSomeString<typename std::remove_pointer<
1283
+ detail::LastElement<Ts...>>::type>::value,
1284
+ int> = 0>
1285
+ void toAppend(const Ts&... vs) {
1286
+ using seq = std::index_sequence_for<Ts...>;
1287
+ detail::ToAppendStrImplAll<seq>::call(vs...);
1288
+ }
1289
+
1290
+ /**
1291
+ * @overloadbrief toAppend, but pre-allocate the exact amount of space required.
1292
+ *
1293
+ * Special version of the call that preallocates exactly as much memory
1294
+ * as need for arguments to be stored in target. This means we are
1295
+ * not doing exponential growth when we append. If you are using it
1296
+ * in a loop you are aiming at your foot with a big perf-destroying
1297
+ * bazooka.
1298
+ * On the other hand if you are appending to a string once, this
1299
+ * will probably save a few calls to malloc.
1300
+ */
1301
+ template <
1302
+ class... Ts,
1303
+ std::enable_if_t<
1304
+ IsSomeString<typename std::remove_pointer<
1305
+ detail::LastElement<Ts...>>::type>::value,
1306
+ int> = 0>
1307
+ void toAppendFit(const Ts&... vs) {
1308
+ ::folly::detail::reserveInTarget(vs...);
1309
+ toAppend(vs...);
1310
+ }
1311
+
1312
+ template <class Ts>
1313
+ void toAppendFit(const Ts&) {}
1314
+
1315
+ /**
1316
+ * Variadic base case: do nothing.
1317
+ */
1318
+ template <class Tgt>
1319
+ typename std::enable_if<IsSomeString<Tgt>::value>::type toAppend(
1320
+ Tgt* /* result */) {}
1321
+
1322
+ /**
1323
+ * @overloadbrief Use a specified delimiter between appendees.
1324
+ *
1325
+ * Variadic base case: do nothing.
1326
+ */
1327
+ template <class Delimiter, class Tgt>
1328
+ typename std::enable_if<IsSomeString<Tgt>::value>::type toAppendDelim(
1329
+ const Delimiter& /* delim */, Tgt* /* result */) {}
1330
+
1331
+ /**
1332
+ * 1 element: same as toAppend.
1333
+ */
1334
+ template <class Delimiter, class T, class Tgt>
1335
+ typename std::enable_if<IsSomeString<Tgt>::value>::type toAppendDelim(
1336
+ const Delimiter& /* delim */, const T& v, Tgt* tgt) {
1337
+ toAppend(v, tgt);
1338
+ }
1339
+
1340
+ /**
1341
+ * Append to string with a delimiter in between elements. Check out
1342
+ * comments for toAppend for details about memory allocation.
1343
+ */
1344
+ template <
1345
+ class Delimiter,
1346
+ class... Ts,
1347
+ std::enable_if_t<
1348
+ sizeof...(Ts) >= 3 &&
1349
+ IsSomeString<typename std::remove_pointer<
1350
+ detail::LastElement<Ts...>>::type>::value,
1351
+ int> = 0>
1352
+ void toAppendDelim(const Delimiter& delim, const Ts&... vs) {
1353
+ detail::toAppendDelimStrImpl(delim, vs...);
1354
+ }
1355
+
1356
+ /**
1357
+ * @overloadbrief toAppend with custom delimiter and exact pre-allocation.
1358
+ *
1359
+ * Detail in comment for toAppendFit
1360
+ */
1361
+ template <
1362
+ class Delimiter,
1363
+ class... Ts,
1364
+ std::enable_if_t<
1365
+ IsSomeString<typename std::remove_pointer<
1366
+ detail::LastElement<Ts...>>::type>::value,
1367
+ int> = 0>
1368
+ void toAppendDelimFit(const Delimiter& delim, const Ts&... vs) {
1369
+ detail::reserveInTargetDelim(delim, vs...);
1370
+ toAppendDelim(delim, vs...);
1371
+ }
1372
+
1373
+ template <class De, class Ts>
1374
+ void toAppendDelimFit(const De&, const Ts&) {}
1375
+
1376
+ /**
1377
+ * to<SomeString>(v1, v2, ...) uses toAppend() (see below) as back-end
1378
+ * for all types.
1379
+ */
1380
+ template <
1381
+ class Tgt,
1382
+ class... Ts,
1383
+ std::enable_if_t<
1384
+ IsSomeString<Tgt>::value &&
1385
+ (sizeof...(Ts) != 1 ||
1386
+ !std::is_same<Tgt, detail::LastElement<void, Ts...>>::value),
1387
+ int> = 0>
1388
+ Tgt to(const Ts&... vs) {
1389
+ Tgt result;
1390
+ toAppendFit(vs..., &result);
1391
+ return result;
1392
+ }
1393
+
1394
+ /**
1395
+ * Special version of to<SomeString> for floating point. When calling
1396
+ * folly::to<SomeString>(double), generic implementation above will
1397
+ * firstly reserve 24 (or 25 when negative value) bytes. This will
1398
+ * introduce a malloc call for most mainstream string implementations.
1399
+ *
1400
+ * But for most cases, a floating point doesn't need 24 (or 25) bytes to
1401
+ * be converted as a string.
1402
+ *
1403
+ * This special version will not do string reserve.
1404
+ */
1405
+ template <class Tgt, class Src>
1406
+ typename std::enable_if<
1407
+ IsSomeString<Tgt>::value && std::is_floating_point<Src>::value,
1408
+ Tgt>::type
1409
+ to(Src value) {
1410
+ Tgt result;
1411
+ toAppend(value, &result);
1412
+ return result;
1413
+ }
1414
+
1415
+ /**
1416
+ * @overloadbrief Like `to`, but uses a custom delimiter.
1417
+ *
1418
+ * toDelim<SomeString>(SomeString str) returns itself.
1419
+ */
1420
+ template <class Tgt, class Delim, class Src>
1421
+ typename std::enable_if<
1422
+ IsSomeString<Tgt>::value &&
1423
+ std::is_same<Tgt, typename std::decay<Src>::type>::value,
1424
+ Tgt>::type
1425
+ toDelim(const Delim& /* delim */, Src&& value) {
1426
+ return static_cast<Src&&>(value);
1427
+ }
1428
+
1429
+ /**
1430
+ * toDelim<SomeString>(delim, v1, v2, ...) uses toAppendDelim() as
1431
+ * back-end for all types.
1432
+ */
1433
+ template <
1434
+ class Tgt,
1435
+ class Delim,
1436
+ class... Ts,
1437
+ std::enable_if_t<
1438
+ IsSomeString<Tgt>::value &&
1439
+ (sizeof...(Ts) != 1 ||
1440
+ !std::is_same<Tgt, detail::LastElement<void, Ts...>>::value),
1441
+ int> = 0>
1442
+ Tgt toDelim(const Delim& delim, const Ts&... vs) {
1443
+ Tgt result;
1444
+ toAppendDelimFit(delim, vs..., &result);
1445
+ return result;
1446
+ }
1447
+
1448
+ /**
1449
+ * Conversions from string types to integral types.
1450
+ */
1451
+
1452
+ namespace detail {
1453
+
1454
+ Expected<bool, ConversionCode> str_to_bool(StringPiece* src) noexcept;
1455
+
1456
+ template <typename T>
1457
+ Expected<T, ConversionCode> str_to_floating(StringPiece* src) noexcept;
1458
+
1459
+ extern template Expected<float, ConversionCode> str_to_floating<float>(
1460
+ StringPiece* src) noexcept;
1461
+ extern template Expected<double, ConversionCode> str_to_floating<double>(
1462
+ StringPiece* src) noexcept;
1463
+
1464
+ template <typename T>
1465
+ Expected<T, ConversionCode> str_to_floating_fast_float_from_chars(
1466
+ StringPiece* src) noexcept;
1467
+
1468
+ extern template Expected<float, ConversionCode>
1469
+ str_to_floating_fast_float_from_chars<float>(StringPiece* src) noexcept;
1470
+ extern template Expected<double, ConversionCode>
1471
+ str_to_floating_fast_float_from_chars<double>(StringPiece* src) noexcept;
1472
+
1473
+ template <class Tgt>
1474
+ Expected<Tgt, ConversionCode> digits_to(const char* b, const char* e) noexcept;
1475
+
1476
+ extern template Expected<char, ConversionCode> digits_to<char>(
1477
+ const char*, const char*) noexcept;
1478
+ extern template Expected<signed char, ConversionCode> digits_to<signed char>(
1479
+ const char*, const char*) noexcept;
1480
+ extern template Expected<unsigned char, ConversionCode>
1481
+ digits_to<unsigned char>(const char*, const char*) noexcept;
1482
+
1483
+ extern template Expected<short, ConversionCode> digits_to<short>(
1484
+ const char*, const char*) noexcept;
1485
+ extern template Expected<unsigned short, ConversionCode>
1486
+ digits_to<unsigned short>(const char*, const char*) noexcept;
1487
+
1488
+ extern template Expected<int, ConversionCode> digits_to<int>(
1489
+ const char*, const char*) noexcept;
1490
+ extern template Expected<unsigned int, ConversionCode> digits_to<unsigned int>(
1491
+ const char*, const char*) noexcept;
1492
+
1493
+ extern template Expected<long, ConversionCode> digits_to<long>(
1494
+ const char*, const char*) noexcept;
1495
+ extern template Expected<unsigned long, ConversionCode>
1496
+ digits_to<unsigned long>(const char*, const char*) noexcept;
1497
+
1498
+ extern template Expected<long long, ConversionCode> digits_to<long long>(
1499
+ const char*, const char*) noexcept;
1500
+ extern template Expected<unsigned long long, ConversionCode>
1501
+ digits_to<unsigned long long>(const char*, const char*) noexcept;
1502
+
1503
+ #if FOLLY_HAVE_INT128_T
1504
+ extern template Expected<__int128, ConversionCode> digits_to<__int128>(
1505
+ const char*, const char*) noexcept;
1506
+ extern template Expected<unsigned __int128, ConversionCode>
1507
+ digits_to<unsigned __int128>(const char*, const char*) noexcept;
1508
+ #endif
1509
+
1510
+ template <class T>
1511
+ Expected<T, ConversionCode> str_to_integral(StringPiece* src) noexcept;
1512
+
1513
+ extern template Expected<char, ConversionCode> str_to_integral<char>(
1514
+ StringPiece* src) noexcept;
1515
+ extern template Expected<signed char, ConversionCode>
1516
+ str_to_integral<signed char>(StringPiece* src) noexcept;
1517
+ extern template Expected<unsigned char, ConversionCode>
1518
+ str_to_integral<unsigned char>(StringPiece* src) noexcept;
1519
+
1520
+ extern template Expected<short, ConversionCode> str_to_integral<short>(
1521
+ StringPiece* src) noexcept;
1522
+ extern template Expected<unsigned short, ConversionCode>
1523
+ str_to_integral<unsigned short>(StringPiece* src) noexcept;
1524
+
1525
+ extern template Expected<int, ConversionCode> str_to_integral<int>(
1526
+ StringPiece* src) noexcept;
1527
+ extern template Expected<unsigned int, ConversionCode>
1528
+ str_to_integral<unsigned int>(StringPiece* src) noexcept;
1529
+
1530
+ extern template Expected<long, ConversionCode> str_to_integral<long>(
1531
+ StringPiece* src) noexcept;
1532
+ extern template Expected<unsigned long, ConversionCode>
1533
+ str_to_integral<unsigned long>(StringPiece* src) noexcept;
1534
+
1535
+ extern template Expected<long long, ConversionCode> str_to_integral<long long>(
1536
+ StringPiece* src) noexcept;
1537
+ extern template Expected<unsigned long long, ConversionCode>
1538
+ str_to_integral<unsigned long long>(StringPiece* src) noexcept;
1539
+
1540
+ #if FOLLY_HAVE_INT128_T
1541
+ extern template Expected<__int128, ConversionCode> str_to_integral<__int128>(
1542
+ StringPiece* src) noexcept;
1543
+ extern template Expected<unsigned __int128, ConversionCode>
1544
+ str_to_integral<unsigned __int128>(StringPiece* src) noexcept;
1545
+ #endif
1546
+
1547
+ template <typename T>
1548
+ typename std::
1549
+ enable_if<std::is_same<T, bool>::value, Expected<T, ConversionCode>>::type
1550
+ convertTo(StringPiece* src) noexcept {
1551
+ return str_to_bool(src);
1552
+ }
1553
+
1554
+ template <typename T>
1555
+ typename std::enable_if<
1556
+ std::is_floating_point<T>::value,
1557
+ Expected<T, ConversionCode>>::type
1558
+ convertTo(StringPiece* src) noexcept {
1559
+ return str_to_floating<T>(src);
1560
+ }
1561
+
1562
+ template <typename T>
1563
+ typename std::enable_if<
1564
+ is_integral_v<T> && !std::is_same<T, bool>::value,
1565
+ Expected<T, ConversionCode>>::type
1566
+ convertTo(StringPiece* src) noexcept {
1567
+ return str_to_integral<T>(src);
1568
+ }
1569
+
1570
+ } // namespace detail
1571
+
1572
+ /**
1573
+ * String represented as a pair of pointers to char to unsigned
1574
+ * integrals. Assumes NO whitespace before or after.
1575
+ */
1576
+ template <typename Tgt>
1577
+ typename std::enable_if<
1578
+ is_integral_v<Tgt> && !std::is_same<Tgt, bool>::value,
1579
+ Expected<Tgt, ConversionCode>>::type
1580
+ tryTo(const char* b, const char* e) noexcept {
1581
+ return detail::digits_to<Tgt>(b, e);
1582
+ }
1583
+
1584
+ template <typename Tgt>
1585
+ typename std::enable_if< //
1586
+ is_integral_v<Tgt> && !std::is_same<Tgt, bool>::value,
1587
+ Tgt>::type
1588
+ to(const char* b, const char* e) {
1589
+ return tryTo<Tgt>(b, e).thenOrThrow(identity, [=](ConversionCode code) {
1590
+ return makeConversionError(code, StringPiece(b, e));
1591
+ });
1592
+ }
1593
+
1594
+ /**
1595
+ * Conversions from string types to arithmetic types.
1596
+ */
1597
+
1598
+ /**
1599
+ * Parsing strings to numeric types.
1600
+ */
1601
+ template <typename Tgt>
1602
+ FOLLY_NODISCARD inline typename std::enable_if< //
1603
+ is_arithmetic_v<Tgt>,
1604
+ Expected<StringPiece, ConversionCode>>::type
1605
+ parseTo(StringPiece src, Tgt& out) {
1606
+ return detail::convertTo<Tgt>(&src).then(
1607
+ [&](Tgt res) { return void(out = res), src; });
1608
+ }
1609
+
1610
+ /**
1611
+ * Integral / Floating Point to integral / Floating Point
1612
+ */
1613
+
1614
+ namespace detail {
1615
+
1616
+ /**
1617
+ * Bool to integral/float doesn't need any special checks, and this
1618
+ * overload means we aren't trying to see if a bool is less than
1619
+ * an integer.
1620
+ */
1621
+ template <class Tgt>
1622
+ typename std::enable_if<
1623
+ !std::is_same<Tgt, bool>::value &&
1624
+ (is_integral_v<Tgt> || std::is_floating_point<Tgt>::value),
1625
+ Expected<Tgt, ConversionCode>>::type
1626
+ convertTo(const bool& value) noexcept {
1627
+ return static_cast<Tgt>(value ? 1 : 0);
1628
+ }
1629
+
1630
+ /**
1631
+ * Checked conversion from integral to integral. The checks are only
1632
+ * performed when meaningful, e.g. conversion from int to long goes
1633
+ * unchecked.
1634
+ */
1635
+ template <class Tgt, class Src>
1636
+ typename std::enable_if<
1637
+ is_integral_v<Src> && !std::is_same<Tgt, Src>::value &&
1638
+ !std::is_same<Tgt, bool>::value && is_integral_v<Tgt>,
1639
+ Expected<Tgt, ConversionCode>>::type
1640
+ convertTo(const Src& value) noexcept {
1641
+ if /* constexpr */ (
1642
+ make_unsigned_t<Tgt>(std::numeric_limits<Tgt>::max()) <
1643
+ make_unsigned_t<Src>(std::numeric_limits<Src>::max())) {
1644
+ if (greater_than<Tgt, std::numeric_limits<Tgt>::max()>(value)) {
1645
+ return makeUnexpected(ConversionCode::ARITH_POSITIVE_OVERFLOW);
1646
+ }
1647
+ }
1648
+ if /* constexpr */ (
1649
+ is_signed_v<Src> && (!is_signed_v<Tgt> || sizeof(Src) > sizeof(Tgt))) {
1650
+ if (less_than<Tgt, std::numeric_limits<Tgt>::min()>(value)) {
1651
+ return makeUnexpected(ConversionCode::ARITH_NEGATIVE_OVERFLOW);
1652
+ }
1653
+ }
1654
+ return static_cast<Tgt>(value);
1655
+ }
1656
+
1657
+ /**
1658
+ * Checked conversion from floating to floating. The checks are only
1659
+ * performed when meaningful, e.g. conversion from float to double goes
1660
+ * unchecked.
1661
+ */
1662
+ template <class Tgt, class Src>
1663
+ typename std::enable_if<
1664
+ std::is_floating_point<Tgt>::value && std::is_floating_point<Src>::value &&
1665
+ !std::is_same<Tgt, Src>::value,
1666
+ Expected<Tgt, ConversionCode>>::type
1667
+ convertTo(const Src& value) noexcept {
1668
+ if (FOLLY_UNLIKELY(std::isinf(value))) {
1669
+ return static_cast<Tgt>(value);
1670
+ }
1671
+ if /* constexpr */ (
1672
+ std::numeric_limits<Tgt>::max() < std::numeric_limits<Src>::max()) {
1673
+ if (value > std::numeric_limits<Tgt>::max()) {
1674
+ return makeUnexpected(ConversionCode::ARITH_POSITIVE_OVERFLOW);
1675
+ }
1676
+ if (value < std::numeric_limits<Tgt>::lowest()) {
1677
+ return makeUnexpected(ConversionCode::ARITH_NEGATIVE_OVERFLOW);
1678
+ }
1679
+ }
1680
+ return static_cast<Tgt>(value);
1681
+ }
1682
+
1683
+ /**
1684
+ * Check if a floating point value can safely be converted to an
1685
+ * integer value without triggering undefined behaviour.
1686
+ */
1687
+ template <typename Tgt, typename Src>
1688
+ inline typename std::enable_if<
1689
+ std::is_floating_point<Src>::value && is_integral_v<Tgt> &&
1690
+ !std::is_same<Tgt, bool>::value,
1691
+ bool>::type
1692
+ checkConversion(const Src& value) {
1693
+ constexpr Src tgtMaxAsSrc = static_cast<Src>(std::numeric_limits<Tgt>::max());
1694
+ constexpr Src tgtMinAsSrc = static_cast<Src>(std::numeric_limits<Tgt>::min());
1695
+ // NOTE: The following two comparisons also handle the case where value is
1696
+ // NaN, as all comparisons with NaN are false.
1697
+ if (!(value < tgtMaxAsSrc)) {
1698
+ if (!(value <= tgtMaxAsSrc)) {
1699
+ return false;
1700
+ }
1701
+ const Src mmax = folly::nextafter(tgtMaxAsSrc, Src());
1702
+ if (static_cast<Tgt>(value - mmax) >
1703
+ std::numeric_limits<Tgt>::max() - static_cast<Tgt>(mmax)) {
1704
+ return false;
1705
+ }
1706
+ } else if (value <= tgtMinAsSrc) {
1707
+ if (value < tgtMinAsSrc) {
1708
+ return false;
1709
+ }
1710
+ const Src mmin = folly::nextafter(tgtMinAsSrc, Src());
1711
+ if (static_cast<Tgt>(value - mmin) <
1712
+ std::numeric_limits<Tgt>::min() - static_cast<Tgt>(mmin)) {
1713
+ return false;
1714
+ }
1715
+ }
1716
+ return true;
1717
+ }
1718
+
1719
+ // Integers can always safely be converted to floating point values
1720
+ template <typename Tgt, typename Src>
1721
+ constexpr typename std::enable_if<
1722
+ is_integral_v<Src> && std::is_floating_point<Tgt>::value,
1723
+ bool>::type
1724
+ checkConversion(const Src&) {
1725
+ return true;
1726
+ }
1727
+
1728
+ // Also, floating point values can always be safely converted to bool
1729
+ // Per the standard, any floating point value that is not zero will yield true
1730
+ template <typename Tgt, typename Src>
1731
+ constexpr typename std::enable_if<
1732
+ std::is_floating_point<Src>::value && std::is_same<Tgt, bool>::value,
1733
+ bool>::type
1734
+ checkConversion(const Src&) {
1735
+ return true;
1736
+ }
1737
+
1738
+ /**
1739
+ * Checked conversion from integral to floating point and back. The
1740
+ * result must be convertible back to the source type without loss of
1741
+ * precision. This seems Draconian but sometimes is what's needed, and
1742
+ * complements existing routines nicely. For various rounding
1743
+ * routines, see <math>.
1744
+ */
1745
+ template <typename Tgt, typename Src>
1746
+ typename std::enable_if<
1747
+ (is_integral_v<Src> && std::is_floating_point<Tgt>::value) ||
1748
+ (std::is_floating_point<Src>::value && is_integral_v<Tgt>),
1749
+ Expected<Tgt, ConversionCode>>::type
1750
+ convertTo(const Src& value) noexcept {
1751
+ if (FOLLY_LIKELY(checkConversion<Tgt>(value))) {
1752
+ Tgt result = static_cast<Tgt>(value);
1753
+ if (FOLLY_LIKELY(checkConversion<Src>(result))) {
1754
+ Src witness = static_cast<Src>(result);
1755
+ if (FOLLY_LIKELY(value == witness)) {
1756
+ return result;
1757
+ }
1758
+ }
1759
+ }
1760
+ return makeUnexpected(ConversionCode::ARITH_LOSS_OF_PRECISION);
1761
+ }
1762
+
1763
+ template <typename Tgt, typename Src>
1764
+ inline std::string errorValue(const Src& value) {
1765
+ return to<std::string>("(", pretty_name<Tgt>(), ") ", value);
1766
+ }
1767
+
1768
+ template <typename Tgt, typename Src>
1769
+ using IsArithToArith = std::bool_constant<
1770
+ !std::is_same<Tgt, Src>::value && !std::is_same<Tgt, bool>::value &&
1771
+ is_arithmetic_v<Src> && is_arithmetic_v<Tgt>>;
1772
+
1773
+ } // namespace detail
1774
+
1775
+ template <typename Tgt, typename Src>
1776
+ typename std::enable_if<
1777
+ detail::IsArithToArith<Tgt, Src>::value,
1778
+ Expected<Tgt, ConversionCode>>::type
1779
+ tryTo(const Src& value) noexcept {
1780
+ return detail::convertTo<Tgt>(value);
1781
+ }
1782
+
1783
+ template <typename Tgt, typename Src>
1784
+ typename std::enable_if<detail::IsArithToArith<Tgt, Src>::value, Tgt>::type to(
1785
+ const Src& value) {
1786
+ return tryTo<Tgt>(value).thenOrThrow(identity, [&](ConversionCode e) {
1787
+ return makeConversionError(e, detail::errorValue<Tgt>(value));
1788
+ });
1789
+ }
1790
+
1791
+ /**
1792
+ * Custom Conversions
1793
+ *
1794
+ * Any type can be used with folly::to by implementing parseTo. The
1795
+ * implementation should be provided in the namespace of the type to facilitate
1796
+ * argument-dependent lookup:
1797
+ *
1798
+ * namespace other_namespace {
1799
+ * ::folly::Expected<::folly::StringPiece, SomeErrorCode>
1800
+ * parseTo(::folly::StringPiece, OtherType&) noexcept;
1801
+ * }
1802
+ */
1803
+ template <class T>
1804
+ FOLLY_NODISCARD typename std::enable_if<
1805
+ std::is_enum<T>::value,
1806
+ Expected<StringPiece, ConversionCode>>::type
1807
+ parseTo(StringPiece in, T& out) noexcept {
1808
+ typename std::underlying_type<T>::type tmp{};
1809
+ auto restOrError = parseTo(in, tmp);
1810
+ out = static_cast<T>(tmp); // Harmless if parseTo fails
1811
+ return restOrError;
1812
+ }
1813
+
1814
+ FOLLY_NODISCARD
1815
+ inline Expected<StringPiece, ConversionCode> parseTo(
1816
+ StringPiece in, StringPiece& out) noexcept {
1817
+ out = in;
1818
+ return StringPiece{in.end(), in.end()};
1819
+ }
1820
+
1821
+ namespace detail {
1822
+
1823
+ template <class Str>
1824
+ FOLLY_ERASE Expected<StringPiece, ConversionCode> parseToStr(
1825
+ StringPiece in, Str& out) {
1826
+ out.clear();
1827
+ out.append(in.data(), in.size()); // TODO try/catch?
1828
+ return StringPiece{in.end(), in.end()};
1829
+ }
1830
+
1831
+ } // namespace detail
1832
+
1833
+ FOLLY_NODISCARD
1834
+ inline Expected<StringPiece, ConversionCode> parseTo(
1835
+ StringPiece in, std::string& out) {
1836
+ return detail::parseToStr(in, out);
1837
+ }
1838
+
1839
+ FOLLY_NODISCARD
1840
+ inline Expected<StringPiece, ConversionCode> parseTo(
1841
+ StringPiece in, std::string_view& out) {
1842
+ out = std::string_view(in.data(), in.size());
1843
+ return StringPiece{in.end(), in.end()};
1844
+ }
1845
+
1846
+ FOLLY_NODISCARD
1847
+ inline Expected<StringPiece, ConversionCode> parseTo(
1848
+ StringPiece in, fbstring& out) {
1849
+ return detail::parseToStr(in, out);
1850
+ }
1851
+
1852
+ template <class Str>
1853
+ FOLLY_NODISCARD inline typename std::enable_if<
1854
+ IsSomeString<Str>::value,
1855
+ Expected<StringPiece, ConversionCode>>::type
1856
+ parseTo(StringPiece in, Str& out) {
1857
+ return detail::parseToStr(in, out);
1858
+ }
1859
+
1860
+ namespace detail {
1861
+ template <typename Tgt>
1862
+ using ParseToResult = decltype(parseTo(StringPiece{}, std::declval<Tgt&>()));
1863
+
1864
+ struct CheckTrailingSpace {
1865
+ Expected<Unit, ConversionCode> operator()(StringPiece sp) const {
1866
+ auto e = enforceWhitespaceErr(sp);
1867
+ if (FOLLY_UNLIKELY(e != ConversionCode::SUCCESS)) {
1868
+ return makeUnexpected(e);
1869
+ }
1870
+ return unit;
1871
+ }
1872
+ };
1873
+
1874
+ template <class Error>
1875
+ struct ReturnUnit {
1876
+ template <class T>
1877
+ constexpr Expected<Unit, Error> operator()(T&&) const {
1878
+ return unit;
1879
+ }
1880
+ };
1881
+
1882
+ // Older versions of the parseTo customization point threw on error and
1883
+ // returned void. Handle that.
1884
+ template <class Tgt>
1885
+ inline typename std::enable_if<
1886
+ std::is_void<ParseToResult<Tgt>>::value,
1887
+ Expected<StringPiece, ConversionCode>>::type
1888
+ parseToWrap(StringPiece sp, Tgt& out) {
1889
+ parseTo(sp, out);
1890
+ return StringPiece(sp.end(), sp.end());
1891
+ }
1892
+
1893
+ template <class Tgt>
1894
+ inline typename std::enable_if<
1895
+ !std::is_void<ParseToResult<Tgt>>::value,
1896
+ ParseToResult<Tgt>>::type
1897
+ parseToWrap(StringPiece sp, Tgt& out) {
1898
+ return parseTo(sp, out);
1899
+ }
1900
+
1901
+ template <typename Tgt>
1902
+ using ParseToError = ExpectedErrorType<decltype(detail::parseToWrap(
1903
+ StringPiece{}, std::declval<Tgt&>()))>;
1904
+
1905
+ } // namespace detail
1906
+
1907
+ /**
1908
+ * String or StringPiece to target conversion. Accepts leading and trailing
1909
+ * whitespace, but no non-space trailing characters.
1910
+ */
1911
+
1912
+ template <class Tgt>
1913
+ inline typename std::enable_if<
1914
+ !std::is_same<StringPiece, Tgt>::value,
1915
+ Expected<Tgt, detail::ParseToError<Tgt>>>::type
1916
+ tryTo(StringPiece src) noexcept {
1917
+ Tgt result{};
1918
+ using Error = detail::ParseToError<Tgt>;
1919
+ using Check = typename std::conditional<
1920
+ is_arithmetic_v<Tgt>,
1921
+ detail::CheckTrailingSpace,
1922
+ detail::ReturnUnit<Error>>::type;
1923
+ return parseTo(src, result).then(Check(), [&](Unit) {
1924
+ return std::move(result);
1925
+ });
1926
+ }
1927
+
1928
+ template <class Tgt, class Src>
1929
+ inline typename std::enable_if<
1930
+ IsSomeString<Src>::value && !std::is_same<StringPiece, Tgt>::value,
1931
+ Tgt>::type
1932
+ to(Src const& src) {
1933
+ return to<Tgt>(StringPiece(src.data(), src.size()));
1934
+ }
1935
+
1936
+ template <class Tgt>
1937
+ inline
1938
+ typename std::enable_if<!std::is_same<StringPiece, Tgt>::value, Tgt>::type
1939
+ to(StringPiece src) {
1940
+ Tgt result{};
1941
+ using Error = detail::ParseToError<Tgt>;
1942
+ using Check = typename std::conditional<
1943
+ is_arithmetic_v<Tgt>,
1944
+ detail::CheckTrailingSpace,
1945
+ detail::ReturnUnit<Error>>::type;
1946
+ auto tmp = detail::parseToWrap(src, result);
1947
+ return tmp
1948
+ .thenOrThrow(
1949
+ Check(),
1950
+ [&](Error e) { throw_exception(makeConversionError(e, src)); })
1951
+ .thenOrThrow(
1952
+ [&](Unit) { return std::move(result); },
1953
+ [&](Error e) {
1954
+ throw_exception(makeConversionError(e, tmp.value()));
1955
+ });
1956
+ }
1957
+
1958
+ /**
1959
+ * tryTo/to that take the strings by pointer so the caller gets information
1960
+ * about how much of the string was consumed by the conversion. These do not
1961
+ * check for trailing whitespace.
1962
+ */
1963
+ template <class Tgt>
1964
+ Expected<Tgt, detail::ParseToError<Tgt>> tryTo(StringPiece* src) noexcept {
1965
+ Tgt result;
1966
+ return parseTo(*src, result).then([&, src](StringPiece sp) -> Tgt {
1967
+ *src = sp;
1968
+ return std::move(result);
1969
+ });
1970
+ }
1971
+
1972
+ template <class Tgt>
1973
+ Tgt to(StringPiece* src) {
1974
+ Tgt result{};
1975
+ using Error = detail::ParseToError<Tgt>;
1976
+ return parseTo(*src, result)
1977
+ .thenOrThrow(
1978
+ [&, src](StringPiece sp) -> Tgt {
1979
+ *src = sp;
1980
+ return std::move(result);
1981
+ },
1982
+ [=](Error e) { return makeConversionError(e, *src); });
1983
+ }
1984
+
1985
+ /**
1986
+ * Enum to anything and back
1987
+ */
1988
+
1989
+ template <class Tgt, class Src>
1990
+ typename std::enable_if<
1991
+ std::is_enum<Src>::value && !std::is_same<Src, Tgt>::value &&
1992
+ !std::is_convertible<Tgt, StringPiece>::value,
1993
+ Expected<Tgt, ConversionCode>>::type
1994
+ tryTo(const Src& value) noexcept {
1995
+ return tryTo<Tgt>(to_underlying(value));
1996
+ }
1997
+
1998
+ template <class Tgt, class Src>
1999
+ typename std::enable_if<
2000
+ !std::is_convertible<Src, StringPiece>::value && std::is_enum<Tgt>::value &&
2001
+ !std::is_same<Src, Tgt>::value,
2002
+ Expected<Tgt, ConversionCode>>::type
2003
+ tryTo(const Src& value) noexcept {
2004
+ using I = typename std::underlying_type<Tgt>::type;
2005
+ return tryTo<I>(value).then([](I i) { return static_cast<Tgt>(i); });
2006
+ }
2007
+
2008
+ template <class Tgt, class Src>
2009
+ typename std::enable_if<
2010
+ std::is_enum<Src>::value && !std::is_same<Src, Tgt>::value &&
2011
+ !std::is_convertible<Tgt, StringPiece>::value,
2012
+ Tgt>::type
2013
+ to(const Src& value) {
2014
+ return to<Tgt>(to_underlying(value));
2015
+ }
2016
+
2017
+ template <class Tgt, class Src>
2018
+ typename std::enable_if<
2019
+ !std::is_convertible<Src, StringPiece>::value && std::is_enum<Tgt>::value &&
2020
+ !std::is_same<Src, Tgt>::value,
2021
+ Tgt>::type
2022
+ to(const Src& value) {
2023
+ return static_cast<Tgt>(to<typename std::underlying_type<Tgt>::type>(value));
2024
+ }
2025
+
2026
+ } // namespace folly