react-native-windows 0.74.10 → 0.75.0-preview.1

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 (327) hide show
  1. package/.flowconfig +8 -2
  2. package/Common/Common.vcxproj +8 -0
  3. package/Common/Utilities.cpp +2 -2
  4. package/Directory.Build.targets +5 -0
  5. package/Folly/Folly.vcxproj +10 -2
  6. package/Folly/Folly.vcxproj.filters +0 -7
  7. package/Folly/TEMP_UntilFollyUpdate/ConstexprMath.h +970 -0
  8. package/Folly/TEMP_UntilFollyUpdate/json.cpp +1110 -0
  9. package/Folly/TEMP_UntilFollyUpdate/lang/ToAscii.cpp +4 -2
  10. package/Libraries/Animated/AnimatedImplementation.js +2 -0
  11. package/Libraries/Animated/NativeAnimatedHelper.js +4 -0
  12. package/Libraries/Animated/createAnimatedComponent.js +10 -4
  13. package/Libraries/Animated/useAnimatedProps.js +56 -28
  14. package/Libraries/BatchedBridge/MessageQueue.js +1 -0
  15. package/Libraries/Components/Button.js +10 -5
  16. package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.android.js +11 -2
  17. package/Libraries/Components/Flyout/Flyout.js +10 -10
  18. package/Libraries/Components/Flyout/FlyoutNativeComponent.js +8 -7
  19. package/Libraries/Components/Pressable/Pressable.js +13 -6
  20. package/Libraries/Components/Pressable/Pressable.windows.js +13 -6
  21. package/Libraries/Components/ScrollView/AndroidHorizontalScrollViewNativeComponent.js +4 -0
  22. package/Libraries/Components/ScrollView/ScrollView.js +109 -29
  23. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.js +6 -0
  24. package/Libraries/Components/ScrollView/ScrollViewNativeComponent.windows.js +6 -0
  25. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +13 -1
  26. package/Libraries/Components/StatusBar/StatusBar.js +1 -21
  27. package/Libraries/Components/Switch/Switch.windows.js +2 -0
  28. package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +0 -15
  29. package/Libraries/Components/TextInput/InputAccessoryView.js +10 -1
  30. package/Libraries/Components/TextInput/RCTTextInputViewConfig.js +0 -12
  31. package/Libraries/Components/TextInput/TextInput.d.ts +0 -19
  32. package/Libraries/Components/TextInput/TextInput.js +20 -73
  33. package/Libraries/Components/TextInput/TextInput.windows.js +21 -75
  34. package/Libraries/Components/TextInput/WindowsTextInputNativeComponent.js +27 -12
  35. package/Libraries/Components/Touchable/Touchable.js +2 -2
  36. package/Libraries/Components/Touchable/TouchableHighlight.d.ts +4 -10
  37. package/Libraries/Components/Touchable/TouchableHighlight.js +3 -1
  38. package/Libraries/Components/Touchable/TouchableHighlight.windows.js +3 -1
  39. package/Libraries/Components/Touchable/TouchableOpacity.d.ts +4 -32
  40. package/Libraries/Components/Touchable/TouchableOpacity.js +3 -1
  41. package/Libraries/Components/Touchable/TouchableOpacity.windows.js +3 -1
  42. package/Libraries/Components/Touchable/TouchableWithoutFeedback.d.ts +8 -0
  43. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +117 -111
  44. package/Libraries/Components/Touchable/TouchableWithoutFeedback.windows.js +129 -110
  45. package/Libraries/Components/View/ReactNativeStyleAttributes.js +6 -0
  46. package/Libraries/Components/View/ReactNativeViewAttributes.js +1 -0
  47. package/Libraries/Components/View/ReactNativeViewAttributes.windows.js +1 -0
  48. package/Libraries/Components/View/View.js +0 -11
  49. package/Libraries/Components/View/View.windows.js +0 -11
  50. package/Libraries/Components/View/ViewAccessibility.js +4 -4
  51. package/Libraries/Components/View/ViewAccessibility.windows.js +4 -4
  52. package/Libraries/Components/View/ViewPropTypes.d.ts +21 -59
  53. package/Libraries/Components/View/ViewPropTypes.js +7 -0
  54. package/Libraries/Components/View/ViewPropTypes.windows.js +7 -0
  55. package/Libraries/Core/Devtools/loadBundleFromServer.js +3 -3
  56. package/Libraries/Core/Devtools/loadBundleFromServer.windows.js +153 -0
  57. package/Libraries/Core/Devtools/parseErrorStack.js +5 -5
  58. package/Libraries/Core/Devtools/parseHermesStack.js +22 -16
  59. package/Libraries/Core/ErrorHandlers.js +116 -0
  60. package/Libraries/Core/ExceptionsManager.js +2 -2
  61. package/Libraries/Core/ReactNativeVersion.js +3 -3
  62. package/Libraries/Core/setUpDeveloperTools.js +3 -1
  63. package/Libraries/Core/setUpPerformance.js +6 -4
  64. package/Libraries/Core/setUpReactDevTools.js +70 -10
  65. package/Libraries/Core/setUpTimers.js +50 -31
  66. package/Libraries/Debugging/DebuggingOverlayRegistry.js +1 -1
  67. package/Libraries/Image/Image.android.js +23 -13
  68. package/Libraries/Image/Image.d.ts +14 -15
  69. package/Libraries/Image/Image.ios.js +21 -11
  70. package/Libraries/Image/Image.windows.js +21 -11
  71. package/Libraries/Image/ImageProps.js +16 -5
  72. package/Libraries/Image/ImageTypes.flow.js +7 -2
  73. package/Libraries/Image/ImageUtils.js +1 -0
  74. package/Libraries/Image/ImageViewNativeComponent.js +2 -1
  75. package/Libraries/Inspector/ElementBox.js +6 -3
  76. package/Libraries/Inspector/ElementProperties.js +1 -1
  77. package/Libraries/Interaction/TouchHistoryMath.js +4 -4
  78. package/Libraries/IntersectionObserver/IntersectionObserverManager.js +6 -26
  79. package/Libraries/JSInspector/NetworkAgent.js +1 -1
  80. package/Libraries/LogBox/Data/LogBoxData.js +39 -29
  81. package/Libraries/LogBox/Data/LogBoxLog.js +114 -2
  82. package/Libraries/LogBox/Data/parseLogBoxLog.js +168 -53
  83. package/Libraries/LogBox/LogBox.js +29 -12
  84. package/Libraries/LogBox/LogBoxNotificationContainer.js +4 -0
  85. package/Libraries/LogBox/UI/LogBoxInspector.js +8 -70
  86. package/Libraries/LogBox/UI/LogBoxInspectorBody.js +87 -0
  87. package/Libraries/LogBox/UI/LogBoxInspectorFooter.js +6 -42
  88. package/Libraries/LogBox/UI/LogBoxInspectorFooterButton.js +58 -0
  89. package/Libraries/LogBox/UI/LogBoxInspectorHeader.js +5 -66
  90. package/Libraries/LogBox/UI/LogBoxInspectorHeader.windows.js +5 -66
  91. package/Libraries/LogBox/UI/LogBoxInspectorHeaderButton.js +76 -0
  92. package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.js +8 -5
  93. package/Libraries/LogBox/UI/LogBoxInspectorReactFrames.windows.js +8 -5
  94. package/Libraries/LogBox/UI/LogBoxNotification.js +13 -152
  95. package/Libraries/LogBox/UI/LogBoxNotificationCountBadge.js +63 -0
  96. package/Libraries/LogBox/UI/LogBoxNotificationDismissButton.js +67 -0
  97. package/Libraries/LogBox/UI/LogBoxNotificationMessage.js +57 -0
  98. package/Libraries/NativeComponent/BaseViewConfig.android.js +5 -0
  99. package/Libraries/NativeComponent/BaseViewConfig.ios.js +5 -0
  100. package/Libraries/NativeComponent/BaseViewConfig.windows.js +5 -0
  101. package/Libraries/NativeComponent/NativeComponentRegistry.js +12 -5
  102. package/Libraries/NativeComponent/StaticViewConfigValidator.js +3 -0
  103. package/Libraries/Network/XMLHttpRequest.js +5 -1
  104. package/Libraries/NewAppScreen/components/LearnMoreLinks.js +3 -3
  105. package/Libraries/Pressability/Pressability.js +3 -51
  106. package/Libraries/Pressability/Pressability.windows.js +3 -51
  107. package/Libraries/ReactNative/AppRegistry.d.ts +4 -0
  108. package/Libraries/ReactNative/AppRegistry.js +2 -4
  109. package/Libraries/ReactNative/BridgelessUIManager.js +1 -21
  110. package/Libraries/ReactNative/FabricUIManager.js +0 -51
  111. package/Libraries/ReactNative/ReactFabricPublicInstance/warnForStyleProps.js +1 -0
  112. package/Libraries/ReactNative/RendererImplementation.js +20 -2
  113. package/Libraries/ReactNative/UIManager.d.ts +0 -21
  114. package/Libraries/ReactNative/UIManagerProperties.js +0 -3
  115. package/Libraries/ReactNative/__mocks__/FabricUIManager.js +5 -341
  116. package/Libraries/ReactNative/getNativeComponentAttributes.js +8 -8
  117. package/Libraries/Renderer/implementations/ReactFabric-dev.js +15682 -27088
  118. package/Libraries/Renderer/implementations/ReactFabric-prod.js +5082 -4381
  119. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3480 -2571
  120. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +15943 -27543
  121. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +5303 -4606
  122. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +3450 -2572
  123. package/Libraries/Renderer/shims/ReactFabric.js +2 -2
  124. package/Libraries/Renderer/shims/ReactFeatureFlags.js +2 -2
  125. package/Libraries/Renderer/shims/ReactNative.js +2 -3
  126. package/Libraries/Renderer/shims/ReactNativeTypes.js +24 -3
  127. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +2 -2
  128. package/Libraries/Renderer/shims/createReactNativeComponentClass.js +2 -2
  129. package/Libraries/Share/Share.d.ts +16 -10
  130. package/Libraries/Share/Share.js +14 -15
  131. package/Libraries/StyleSheet/StyleSheet.d.ts +1 -1
  132. package/Libraries/StyleSheet/StyleSheet.js +3 -10
  133. package/Libraries/StyleSheet/StyleSheetTypes.d.ts +21 -21
  134. package/Libraries/StyleSheet/StyleSheetTypes.js +24 -18
  135. package/Libraries/StyleSheet/flattenStyle.js +1 -0
  136. package/Libraries/StyleSheet/processFilter.js +132 -0
  137. package/Libraries/StyleSheet/processTransform.js +18 -3
  138. package/Libraries/Text/Text.js +151 -128
  139. package/Libraries/Text/Text.windows.js +144 -127
  140. package/Libraries/Text/TextNativeComponent.js +5 -4
  141. package/Libraries/Text/TextProps.js +6 -6
  142. package/Libraries/Text/TextProps.windows.js +6 -6
  143. package/Libraries/TurboModule/TurboModuleRegistry.js +2 -1
  144. package/Libraries/Types/CodegenTypes.js +3 -0
  145. package/Libraries/Utilities/{LoadingView.android.js → DevLoadingView.js} +33 -11
  146. package/Libraries/Utilities/Dimensions.js +1 -0
  147. package/Libraries/Utilities/HMRClient.js +36 -8
  148. package/Libraries/Utilities/HMRClientProdShim.js +1 -0
  149. package/Libraries/Utilities/NativePlatformConstantsWin.js +2 -2
  150. package/Libraries/Utilities/Platform.android.js +4 -4
  151. package/Libraries/Utilities/RCTLog.js +1 -0
  152. package/Libraries/Utilities/ReactNativeTestTools.js +12 -24
  153. package/Libraries/Utilities/verifyComponentAttributeEquivalence.js +11 -6
  154. package/Libraries/__tests__/ViewWindows-test.js +6 -6
  155. package/Libraries/promiseRejectionTrackingOptions.js +1 -0
  156. package/Microsoft.ReactNative/Base/FollyIncludes.h +1 -1
  157. package/Microsoft.ReactNative/ComponentView.idl +0 -17
  158. package/Microsoft.ReactNative/Fabric/AbiState.cpp +3 -45
  159. package/Microsoft.ReactNative/Fabric/AbiState.h +0 -6
  160. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.cpp +10 -6
  161. package/Microsoft.ReactNative/Fabric/Composition/ImageComponentView.h +4 -4
  162. package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +12 -3
  163. package/Microsoft.ReactNative/Fabric/Composition/ScrollViewComponentView.cpp +1 -1
  164. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +7 -12
  165. package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputShadowNode.cpp +1 -2
  166. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.cpp +9 -3
  167. package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.h +1 -1
  168. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +11 -18
  169. package/Microsoft.ReactNative/Fabric/FabricUIManagerModule.h +3 -5
  170. package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +23 -11
  171. package/Microsoft.ReactNative/Fabric/WindowsImageManager.h +5 -2
  172. package/Microsoft.ReactNative/Fabric/platform/react/renderer/components/view/HostPlatformViewEventEmitter.cpp +2 -10
  173. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.cpp +107 -36
  174. package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/TextLayoutManager.h +18 -12
  175. package/Microsoft.ReactNative/Modules/DevSettingsModule.cpp +4 -0
  176. package/Microsoft.ReactNative/Modules/DevSettingsModule.h +1 -0
  177. package/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +1 -2
  178. package/Microsoft.ReactNative/Modules/NativeUIManager.cpp +7 -4
  179. package/Microsoft.ReactNative/Modules/NativeUIManager.h +1 -1
  180. package/Microsoft.ReactNative/Modules/PlatformConstantsWinModule.cpp +2 -2
  181. package/Microsoft.ReactNative/Modules/PlatformConstantsWinModule.h +3 -3
  182. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp +11 -17
  183. package/Microsoft.ReactNative/ReactHost/ReactInstanceWin.h +1 -1
  184. package/Microsoft.ReactNative/Timer.idl +1 -3
  185. package/Microsoft.ReactNative/Utils/BatchingEventEmitter.cpp +1 -1
  186. package/Microsoft.ReactNative/Utils/LocalBundleReader.cpp +2 -3
  187. package/Microsoft.ReactNative/Utils/ValueUtils.cpp +1 -1
  188. package/Microsoft.ReactNative/Views/DynamicAutomationPeer.cpp +2 -2
  189. package/Microsoft.ReactNative/Views/TextInputViewManager.cpp +1 -1
  190. package/Microsoft.ReactNative/packages.lock.json +45 -72
  191. package/Microsoft.ReactNative.Cxx/JSI/LongLivedJsiValue.h +1 -1
  192. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems +5 -0
  193. package/Microsoft.ReactNative.Cxx/Microsoft.ReactNative.Cxx.vcxitems.filters +1 -0
  194. package/Microsoft.ReactNative.Cxx/TurboModuleProvider.cpp +14 -6
  195. package/Microsoft.ReactNative.Cxx/TurboModuleProvider.h +2 -2
  196. package/Microsoft.ReactNative.Managed/Microsoft.ReactNative.Managed.csproj +1 -1
  197. package/Microsoft.ReactNative.Managed/packages.lock.json +3 -3
  198. package/PropertySheets/ARM64EC.props +13 -0
  199. package/PropertySheets/Application/ARM64EC.props +13 -0
  200. package/PropertySheets/DynamicLibrary/ARM64EC.props +13 -0
  201. package/PropertySheets/External/Microsoft.ReactNative.WindowsSdk.Default.props +4 -4
  202. package/PropertySheets/Generated/PackageVersion.g.props +4 -4
  203. package/PropertySheets/JSEngine.props +2 -0
  204. package/PropertySheets/StaticLibrary/ARM64EC.props +13 -0
  205. package/README.md +21 -21
  206. package/ReactCommon/ReactCommon.vcxproj +11 -1
  207. package/ReactCommon/ReactCommon.vcxproj.filters +19 -12
  208. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +67 -0
  209. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.h +180 -0
  210. package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +351 -0
  211. package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +6 -3
  212. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/Base.h +152 -0
  213. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/Bridging.h +2 -1
  214. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/CallbackWrapper.h +13 -15
  215. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/EventEmitter.h +137 -0
  216. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/bridging/Function.h +283 -0
  217. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModule.cpp +7 -10
  218. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModule.h +162 -0
  219. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModuleUtils.h +2 -4
  220. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/scrollview/ScrollViewProps.cpp +33 -8
  221. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/JSRuntimeFactory.cpp +45 -0
  222. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/JSRuntimeFactory.h +67 -0
  223. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +104 -74
  224. package/Scripts/StripAdditionalPlatformsFromNuspec.ps1 +1 -1
  225. package/Scripts/Tfs/Layout-MSRN-Headers.ps1 +10 -6
  226. package/Scripts/rnw-dependencies.ps1 +36 -23
  227. package/Shared/HermesRuntimeHolder.cpp +19 -1
  228. package/Shared/HermesRuntimeHolder.h +8 -1
  229. package/Shared/HermesSamplingProfiler.cpp +1 -2
  230. package/Shared/Networking/WinRTWebSocketResource.cpp +3 -3
  231. package/Shared/OInstance.cpp +1 -2
  232. package/Shared/Shared.vcxitems +21 -15
  233. package/Shared/Shared.vcxitems.filters +8 -3
  234. package/Shared/Threading/BatchingQueueThread.cpp +6 -2
  235. package/Shared/Threading/BatchingQueueThread.h +2 -2
  236. package/Shared/Utils/CppWinrtLessExceptions.h +2 -2
  237. package/codegen/NativeAppStateSpec.g.h +8 -8
  238. package/codegen/NativeBlobModuleSpec.g.h +0 -10
  239. package/codegen/NativeDOMSpec.g.h +136 -0
  240. package/codegen/NativeDevSettingsSpec.g.h +11 -5
  241. package/codegen/NativeIdleCallbacksSpec.g.h +64 -0
  242. package/codegen/NativeIntersectionObserverSpec.g.h +14 -14
  243. package/codegen/NativeMicrotasksSpec.g.h +34 -0
  244. package/codegen/NativePerformanceSpec.g.h +35 -7
  245. package/codegen/NativePlatformConstantsWindowsSpec.g.h +81 -0
  246. package/codegen/NativePushNotificationManagerIOSSpec.g.h +15 -19
  247. package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +111 -39
  248. package/codegen/NativeUIManagerSpec.g.h +5 -17
  249. package/codegen/react/components/rnwcore/Props.cpp +1 -1
  250. package/codegen/react/components/rnwcore/Props.h +16 -12
  251. package/codegen/react/components/rnwcore/States.h +0 -26
  252. package/codegen/rnwcoreJSI-generated.cpp +688 -463
  253. package/codegen/rnwcoreJSI.h +1374 -2867
  254. package/fmt/TEMP_UntilFmtUpdate/core.h +2925 -0
  255. package/fmt/fmt.vcxproj +10 -2
  256. package/jest/mockComponent.js +7 -0
  257. package/jest/renderer.js +25 -14
  258. package/jest/setup.js +19 -13
  259. package/package.json +29 -27
  260. package/rn-get-polyfills.js +1 -0
  261. package/src/private/core/composeStyles.js +27 -0
  262. package/src/private/featureflags/ReactNativeFeatureFlags.js +93 -33
  263. package/src/private/featureflags/ReactNativeFeatureFlagsBase.js +23 -4
  264. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +56 -0
  265. package/src/private/fusebox/setUpFuseboxReactDevToolsDispatcher.js +108 -0
  266. package/src/private/specs/modules/NativeBlobModule.js +4 -2
  267. package/src/private/specs/modules/NativeDevSettings.js +1 -0
  268. package/src/private/specs/modules/NativePushNotificationManagerIOS.js +0 -4
  269. package/src/private/specs/modules/NativeUIManager.js +0 -7
  270. package/src/private/webapis/dom/geometry/DOMRectReadOnly.js +24 -24
  271. package/src/private/webapis/dom/nodes/ReactNativeElement.js +11 -14
  272. package/src/private/webapis/dom/nodes/ReadOnlyCharacterData.js +2 -3
  273. package/src/private/webapis/dom/nodes/ReadOnlyElement.js +24 -54
  274. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +5 -13
  275. package/src/private/webapis/dom/nodes/specs/NativeDOM.js +468 -0
  276. package/src/private/webapis/dom/nodes/specs/__mocks__/NativeDOMMock.js +413 -0
  277. package/src/private/webapis/dom/oldstylecollections/DOMRectList.js +4 -4
  278. package/src/private/webapis/dom/oldstylecollections/HTMLCollection.js +4 -4
  279. package/src/private/webapis/dom/oldstylecollections/NodeList.js +5 -5
  280. package/src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks.js +34 -0
  281. package/src/private/webapis/microtasks/specs/NativeMicrotasks.js +21 -0
  282. package/src/private/webapis/performance/EventCounts.js +1 -1
  283. package/src/private/webapis/performance/MemoryInfo.js +9 -9
  284. package/src/private/webapis/performance/Performance.js +10 -56
  285. package/src/private/webapis/performance/PerformanceObserver.js +30 -22
  286. package/src/private/webapis/performance/RawPerformanceEntry.js +2 -7
  287. package/src/private/webapis/performance/ReactNativeStartupTiming.js +18 -18
  288. package/src/private/webapis/performance/UserTiming.js +63 -0
  289. package/src/private/webapis/performance/{NativePerformance.js → specs/NativePerformance.js} +3 -2
  290. package/src/private/webapis/performance/{NativePerformanceObserver.js → specs/NativePerformanceObserver.js} +2 -2
  291. package/src/private/webapis/performance/{__mocks__ → specs/__mocks__}/NativePerformance.js +1 -1
  292. package/src/private/webapis/performance/{__mocks__ → specs/__mocks__}/NativePerformanceObserver.js +3 -4
  293. package/stubs/glog/logging.h +1 -0
  294. package/template/cpp-lib/proj/MyLib.vcxproj +1 -1
  295. package/template/cs-lib/proj/MyLib.csproj +1 -1
  296. package/template/metro.config.js +13 -2
  297. package/templates/cpp-app/template.config.js +1 -1
  298. package/templates/cpp-lib/example/metro.config.js +2 -2
  299. package/templates/cpp-lib/template.config.js +1 -1
  300. package/templates/old/generateWrapper.js +4 -1
  301. package/types/modules/globals.d.ts +4 -0
  302. package/Libraries/Lists/FlatList.windows.js +0 -717
  303. package/Libraries/NativeModules/specs/NativeAnimationsDebugModule.js +0 -13
  304. package/Libraries/Utilities/LoadingView.ios.js +0 -50
  305. package/Libraries/Utilities/LoadingView.js +0 -16
  306. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp +0 -178
  307. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/utils/jsi-utils.cpp +0 -39
  308. package/ReactCommon/TEMP_UntilReactCommonUpdate/react/utils/jsi-utils.h +0 -31
  309. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/YGEnums.h +0 -137
  310. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/algorithm/CalculateLayout.cpp +0 -2375
  311. package/ReactCommon/TEMP_UntilReactCommonUpdate/yoga/yoga/enums/ExperimentalFeature.h +0 -40
  312. package/codegen/NativeAnimationsDebugModuleSpec.g.h +0 -40
  313. package/codegen/NativePlatformConstantsWinSpec.g.h +0 -81
  314. package/jest/ReactNativeInternalFeatureFlagsMock.js +0 -13
  315. package/src/private/featureflags/NativeReactNativeFeatureFlags.js +0 -44
  316. package/src/private/featureflags/__tests__/ReactNativeFeatureFlags-test.js +0 -92
  317. package/src/private/specs/modules/NativeAnimationsDebugModule.js +0 -20
  318. package/src/private/webapis/dom/oldstylecollections/__tests__/DOMRectList-test.js +0 -85
  319. package/src/private/webapis/dom/oldstylecollections/__tests__/HTMLCollection-test.js +0 -80
  320. package/src/private/webapis/dom/oldstylecollections/__tests__/NodeList-test.js +0 -161
  321. package/src/private/webapis/performance/__tests__/EventCounts-test.js +0 -116
  322. package/src/private/webapis/performance/__tests__/NativePerformanceMock-test.js +0 -82
  323. package/src/private/webapis/performance/__tests__/NativePerformanceObserverMock-test.js +0 -108
  324. package/src/private/webapis/performance/__tests__/Performance-test.js +0 -117
  325. package/src/private/webapis/performance/__tests__/PerformanceObserver-test.js +0 -208
  326. package/template/metro.devMode.config.js +0 -56
  327. /package/src/private/specs/modules/{NativePlatformConstantsWin.js → NativePlatformConstantsWindows.js} +0 -0
@@ -0,0 +1,2925 @@
1
+ // Formatting library for C++ - the core API for char/UTF-8
2
+ //
3
+ // Copyright (c) 2012 - present, Victor Zverovich
4
+ // All rights reserved.
5
+ //
6
+ // For the license information refer to format.h.
7
+
8
+ #ifndef FMT_CORE_H_
9
+ #define FMT_CORE_H_
10
+
11
+ #include <cstddef> // std::byte
12
+ #include <cstdio> // std::FILE
13
+ #include <cstring> // std::strlen
14
+ #include <iterator>
15
+ #include <limits>
16
+ #include <memory> // std::addressof
17
+ #include <string>
18
+ #include <type_traits>
19
+
20
+ // The fmt library version in the form major * 10000 + minor * 100 + patch.
21
+ #define FMT_VERSION 100100
22
+
23
+ #if defined(__clang__) && !defined(__ibmxl__)
24
+ # define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__)
25
+ #else
26
+ # define FMT_CLANG_VERSION 0
27
+ #endif
28
+
29
+ #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && \
30
+ !defined(__NVCOMPILER)
31
+ # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
32
+ #else
33
+ # define FMT_GCC_VERSION 0
34
+ #endif
35
+
36
+ #ifndef FMT_GCC_PRAGMA
37
+ // Workaround _Pragma bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59884.
38
+ # if FMT_GCC_VERSION >= 504
39
+ # define FMT_GCC_PRAGMA(arg) _Pragma(arg)
40
+ # else
41
+ # define FMT_GCC_PRAGMA(arg)
42
+ # endif
43
+ #endif
44
+
45
+ #ifdef __ICL
46
+ # define FMT_ICC_VERSION __ICL
47
+ #elif defined(__INTEL_COMPILER)
48
+ # define FMT_ICC_VERSION __INTEL_COMPILER
49
+ #else
50
+ # define FMT_ICC_VERSION 0
51
+ #endif
52
+
53
+ #ifdef _MSC_VER
54
+ # define FMT_MSC_VERSION _MSC_VER
55
+ # define FMT_MSC_WARNING(...) __pragma(warning(__VA_ARGS__))
56
+ #else
57
+ # define FMT_MSC_VERSION 0
58
+ # define FMT_MSC_WARNING(...)
59
+ #endif
60
+
61
+ #ifdef _MSVC_LANG
62
+ # define FMT_CPLUSPLUS _MSVC_LANG
63
+ #else
64
+ # define FMT_CPLUSPLUS __cplusplus
65
+ #endif
66
+
67
+ #ifdef __has_feature
68
+ # define FMT_HAS_FEATURE(x) __has_feature(x)
69
+ #else
70
+ # define FMT_HAS_FEATURE(x) 0
71
+ #endif
72
+
73
+ #if defined(__has_include) || FMT_ICC_VERSION >= 1600 || FMT_MSC_VERSION > 1900
74
+ # define FMT_HAS_INCLUDE(x) __has_include(x)
75
+ #else
76
+ # define FMT_HAS_INCLUDE(x) 0
77
+ #endif
78
+
79
+ #ifdef __has_cpp_attribute
80
+ # define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
81
+ #else
82
+ # define FMT_HAS_CPP_ATTRIBUTE(x) 0
83
+ #endif
84
+
85
+ #define FMT_HAS_CPP14_ATTRIBUTE(attribute) \
86
+ (FMT_CPLUSPLUS >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute))
87
+
88
+ #define FMT_HAS_CPP17_ATTRIBUTE(attribute) \
89
+ (FMT_CPLUSPLUS >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute))
90
+
91
+ // Check if relaxed C++14 constexpr is supported.
92
+ // GCC doesn't allow throw in constexpr until version 6 (bug 67371).
93
+ #ifndef FMT_USE_CONSTEXPR
94
+ # if (FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VERSION >= 1912 || \
95
+ (FMT_GCC_VERSION >= 600 && FMT_CPLUSPLUS >= 201402L)) && \
96
+ !FMT_ICC_VERSION && (!defined(__NVCC__) || FMT_CPLUSPLUS >= 202002L)
97
+ # define FMT_USE_CONSTEXPR 1
98
+ # else
99
+ # define FMT_USE_CONSTEXPR 0
100
+ # endif
101
+ #endif
102
+ #if FMT_USE_CONSTEXPR
103
+ # define FMT_CONSTEXPR constexpr
104
+ #else
105
+ # define FMT_CONSTEXPR
106
+ #endif
107
+
108
+ #if ((FMT_CPLUSPLUS >= 202002L) && \
109
+ (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE > 9)) || \
110
+ (FMT_CPLUSPLUS >= 201709L && FMT_GCC_VERSION >= 1002)
111
+ # define FMT_CONSTEXPR20 constexpr
112
+ #else
113
+ # define FMT_CONSTEXPR20
114
+ #endif
115
+
116
+ // Check if constexpr std::char_traits<>::{compare,length} are supported.
117
+ #if defined(__GLIBCXX__)
118
+ # if FMT_CPLUSPLUS >= 201703L && defined(_GLIBCXX_RELEASE) && \
119
+ _GLIBCXX_RELEASE >= 7 // GCC 7+ libstdc++ has _GLIBCXX_RELEASE.
120
+ # define FMT_CONSTEXPR_CHAR_TRAITS constexpr
121
+ # endif
122
+ #elif defined(_LIBCPP_VERSION) && FMT_CPLUSPLUS >= 201703L && \
123
+ _LIBCPP_VERSION >= 4000
124
+ # define FMT_CONSTEXPR_CHAR_TRAITS constexpr
125
+ #elif FMT_MSC_VERSION >= 1914 && FMT_CPLUSPLUS >= 201703L
126
+ # define FMT_CONSTEXPR_CHAR_TRAITS constexpr
127
+ #endif
128
+ #ifndef FMT_CONSTEXPR_CHAR_TRAITS
129
+ # define FMT_CONSTEXPR_CHAR_TRAITS
130
+ #endif
131
+
132
+ // Check if exceptions are disabled.
133
+ #ifndef FMT_EXCEPTIONS
134
+ # if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \
135
+ (FMT_MSC_VERSION && !_HAS_EXCEPTIONS)
136
+ # define FMT_EXCEPTIONS 0
137
+ # else
138
+ # define FMT_EXCEPTIONS 1
139
+ # endif
140
+ #endif
141
+
142
+ // Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings.
143
+ #if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && \
144
+ !defined(__NVCC__)
145
+ # define FMT_NORETURN [[noreturn]]
146
+ #else
147
+ # define FMT_NORETURN
148
+ #endif
149
+
150
+ #ifndef FMT_NODISCARD
151
+ # if FMT_HAS_CPP17_ATTRIBUTE(nodiscard)
152
+ # define FMT_NODISCARD [[nodiscard]]
153
+ # else
154
+ # define FMT_NODISCARD
155
+ # endif
156
+ #endif
157
+
158
+ #ifndef FMT_INLINE
159
+ # if FMT_GCC_VERSION || FMT_CLANG_VERSION
160
+ # define FMT_INLINE inline __attribute__((always_inline))
161
+ # else
162
+ # define FMT_INLINE inline
163
+ # endif
164
+ #endif
165
+
166
+ #ifdef _MSC_VER
167
+ # define FMT_UNCHECKED_ITERATOR(It) \
168
+ using _Unchecked_type = It // Mark iterator as checked.
169
+ #else
170
+ # define FMT_UNCHECKED_ITERATOR(It) using unchecked_type = It
171
+ #endif
172
+
173
+ #ifndef FMT_BEGIN_NAMESPACE
174
+ # define FMT_BEGIN_NAMESPACE \
175
+ namespace fmt { \
176
+ inline namespace v10 {
177
+ # define FMT_END_NAMESPACE \
178
+ } \
179
+ }
180
+ #endif
181
+
182
+ #ifndef FMT_EXPORT
183
+ # define FMT_EXPORT
184
+ # define FMT_BEGIN_EXPORT
185
+ # define FMT_END_EXPORT
186
+ #endif
187
+
188
+ #if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
189
+ # ifdef FMT_LIB_EXPORT
190
+ # define FMT_API __declspec(dllexport)
191
+ # elif defined(FMT_SHARED)
192
+ # define FMT_API __declspec(dllimport)
193
+ # endif
194
+ #else
195
+ # if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED)
196
+ # if defined(__GNUC__) || defined(__clang__)
197
+ # define FMT_API __attribute__((visibility("default")))
198
+ # endif
199
+ # endif
200
+ #endif
201
+ #ifndef FMT_API
202
+ # define FMT_API
203
+ #endif
204
+
205
+ // libc++ supports string_view in pre-c++17.
206
+ #if FMT_HAS_INCLUDE(<string_view>) && \
207
+ (FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION))
208
+ # include <string_view>
209
+ # define FMT_USE_STRING_VIEW
210
+ #elif FMT_HAS_INCLUDE("experimental/string_view") && FMT_CPLUSPLUS >= 201402L
211
+ # include <experimental/string_view>
212
+ # define FMT_USE_EXPERIMENTAL_STRING_VIEW
213
+ #endif
214
+
215
+ #ifndef FMT_UNICODE
216
+ # define FMT_UNICODE !FMT_MSC_VERSION
217
+ #endif
218
+
219
+ #ifndef FMT_CONSTEVAL
220
+ # if ((FMT_GCC_VERSION >= 1000 || FMT_CLANG_VERSION >= 1101) && \
221
+ (!defined(__apple_build_version__) || \
222
+ __apple_build_version__ >= 14000029L) && \
223
+ FMT_CPLUSPLUS >= 202002L) || \
224
+ (defined(__cpp_consteval) && \
225
+ (!FMT_MSC_VERSION || _MSC_FULL_VER >= 193030704))
226
+ // consteval is broken in MSVC before VS2022 and Apple clang before 14.
227
+ # define FMT_CONSTEVAL consteval
228
+ # define FMT_HAS_CONSTEVAL
229
+ # else
230
+ # define FMT_CONSTEVAL
231
+ # endif
232
+ #endif
233
+
234
+ #ifndef FMT_USE_NONTYPE_TEMPLATE_ARGS
235
+ # if defined(__cpp_nontype_template_args) && \
236
+ ((FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L) || \
237
+ __cpp_nontype_template_args >= 201911L) && \
238
+ !defined(__NVCOMPILER) && !defined(__LCC__)
239
+ # define FMT_USE_NONTYPE_TEMPLATE_ARGS 1
240
+ # else
241
+ # define FMT_USE_NONTYPE_TEMPLATE_ARGS 0
242
+ # endif
243
+ #endif
244
+
245
+ // Enable minimal optimizations for more compact code in debug mode.
246
+ FMT_GCC_PRAGMA("GCC push_options")
247
+ #if !defined(__OPTIMIZE__) && !defined(__NVCOMPILER) && !defined(__LCC__) && \
248
+ !defined(__CUDACC__)
249
+ FMT_GCC_PRAGMA("GCC optimize(\"Og\")")
250
+ #endif
251
+
252
+ FMT_BEGIN_NAMESPACE
253
+
254
+ // Implementations of enable_if_t and other metafunctions for older systems.
255
+ template <bool B, typename T = void>
256
+ using enable_if_t = typename std::enable_if<B, T>::type;
257
+ template <bool B, typename T, typename F>
258
+ using conditional_t = typename std::conditional<B, T, F>::type;
259
+ template <bool B> using bool_constant = std::integral_constant<bool, B>;
260
+ template <typename T>
261
+ using remove_reference_t = typename std::remove_reference<T>::type;
262
+ template <typename T>
263
+ using remove_const_t = typename std::remove_const<T>::type;
264
+ template <typename T>
265
+ using remove_cvref_t = typename std::remove_cv<remove_reference_t<T>>::type;
266
+ template <typename T> struct type_identity { using type = T; };
267
+ template <typename T> using type_identity_t = typename type_identity<T>::type;
268
+ template <typename T>
269
+ using underlying_t = typename std::underlying_type<T>::type;
270
+
271
+ // Checks whether T is a container with contiguous storage.
272
+ template <typename T> struct is_contiguous : std::false_type {};
273
+ template <typename Char>
274
+ struct is_contiguous<std::basic_string<Char>> : std::true_type {};
275
+
276
+ struct monostate {
277
+ constexpr monostate() {}
278
+ };
279
+
280
+ // An enable_if helper to be used in template parameters which results in much
281
+ // shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed
282
+ // to workaround a bug in MSVC 2019 (see #1140 and #1186).
283
+ #ifdef FMT_DOC
284
+ # define FMT_ENABLE_IF(...)
285
+ #else
286
+ # define FMT_ENABLE_IF(...) fmt::enable_if_t<(__VA_ARGS__), int> = 0
287
+ #endif
288
+
289
+ // This is defined in core.h instead of format.h to avoid injecting in std.
290
+ // It is a template to avoid undesirable implicit conversions to std::byte.
291
+ #ifdef __cpp_lib_byte
292
+ template <typename T, FMT_ENABLE_IF(std::is_same<T, std::byte>::value)>
293
+ inline auto format_as(T b) -> unsigned char {
294
+ return static_cast<unsigned char>(b);
295
+ }
296
+ #endif
297
+
298
+ namespace detail {
299
+ // Suppresses "unused variable" warnings with the method described in
300
+ // https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/.
301
+ // (void)var does not work on many Intel compilers.
302
+ template <typename... T> FMT_CONSTEXPR void ignore_unused(const T&...) {}
303
+
304
+ constexpr FMT_INLINE auto is_constant_evaluated(
305
+ bool default_value = false) noexcept -> bool {
306
+ // Workaround for incompatibility between libstdc++ consteval-based
307
+ // std::is_constant_evaluated() implementation and clang-14.
308
+ // https://github.com/fmtlib/fmt/issues/3247
309
+ #if FMT_CPLUSPLUS >= 202002L && defined(_GLIBCXX_RELEASE) && \
310
+ _GLIBCXX_RELEASE >= 12 && \
311
+ (FMT_CLANG_VERSION >= 1400 && FMT_CLANG_VERSION < 1500)
312
+ ignore_unused(default_value);
313
+ return __builtin_is_constant_evaluated();
314
+ #elif defined(__cpp_lib_is_constant_evaluated)
315
+ ignore_unused(default_value);
316
+ return std::is_constant_evaluated();
317
+ #else
318
+ return default_value;
319
+ #endif
320
+ }
321
+
322
+ // Suppresses "conditional expression is constant" warnings.
323
+ template <typename T> constexpr FMT_INLINE auto const_check(T value) -> T {
324
+ return value;
325
+ }
326
+
327
+ FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
328
+ const char* message);
329
+
330
+ #ifndef FMT_ASSERT
331
+ # ifdef NDEBUG
332
+ // FMT_ASSERT is not empty to avoid -Wempty-body.
333
+ # define FMT_ASSERT(condition, message) \
334
+ fmt::detail::ignore_unused((condition), (message))
335
+ # else
336
+ # define FMT_ASSERT(condition, message) \
337
+ ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \
338
+ ? (void)0 \
339
+ : fmt::detail::assert_fail(__FILE__, __LINE__, (message)))
340
+ # endif
341
+ #endif
342
+
343
+ #if defined(FMT_USE_STRING_VIEW)
344
+ template <typename Char> using std_string_view = std::basic_string_view<Char>;
345
+ #elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW)
346
+ template <typename Char>
347
+ using std_string_view = std::experimental::basic_string_view<Char>;
348
+ #else
349
+ template <typename T> struct std_string_view {};
350
+ #endif
351
+
352
+ #ifdef FMT_USE_INT128
353
+ // Do nothing.
354
+ #elif defined(__SIZEOF_INT128__) && !defined(__NVCC__) && \
355
+ !(FMT_CLANG_VERSION && FMT_MSC_VERSION)
356
+ # define FMT_USE_INT128 1
357
+ using int128_opt = __int128_t; // An optional native 128-bit integer.
358
+ using uint128_opt = __uint128_t;
359
+ template <typename T> inline auto convert_for_visit(T value) -> T {
360
+ return value;
361
+ }
362
+ #else
363
+ # define FMT_USE_INT128 0
364
+ #endif
365
+ #if !FMT_USE_INT128
366
+ enum class int128_opt {};
367
+ enum class uint128_opt {};
368
+ // Reduce template instantiations.
369
+ template <typename T> auto convert_for_visit(T) -> monostate { return {}; }
370
+ #endif
371
+
372
+ // Casts a nonnegative integer to unsigned.
373
+ template <typename Int>
374
+ FMT_CONSTEXPR auto to_unsigned(Int value) ->
375
+ typename std::make_unsigned<Int>::type {
376
+ FMT_ASSERT(std::is_unsigned<Int>::value || value >= 0, "negative value");
377
+ return static_cast<typename std::make_unsigned<Int>::type>(value);
378
+ }
379
+
380
+ FMT_CONSTEXPR inline auto is_utf8() -> bool {
381
+ FMT_MSC_WARNING(suppress : 4566) constexpr unsigned char section[] = "\u00A7";
382
+
383
+ // Avoid buggy sign extensions in MSVC's constant evaluation mode (#2297).
384
+ using uchar = unsigned char;
385
+ return FMT_UNICODE || (sizeof(section) == 3 && uchar(section[0]) == 0xC2 &&
386
+ uchar(section[1]) == 0xA7);
387
+ }
388
+ } // namespace detail
389
+
390
+ /**
391
+ An implementation of ``std::basic_string_view`` for pre-C++17. It provides a
392
+ subset of the API. ``fmt::basic_string_view`` is used for format strings even
393
+ if ``std::string_view`` is available to prevent issues when a library is
394
+ compiled with a different ``-std`` option than the client code (which is not
395
+ recommended).
396
+ */
397
+ FMT_EXPORT
398
+ template <typename Char> class basic_string_view {
399
+ private:
400
+ const Char* data_;
401
+ size_t size_;
402
+
403
+ public:
404
+ using value_type = Char;
405
+ using iterator = const Char*;
406
+
407
+ constexpr basic_string_view() noexcept : data_(nullptr), size_(0) {}
408
+
409
+ /** Constructs a string reference object from a C string and a size. */
410
+ constexpr basic_string_view(const Char* s, size_t count) noexcept
411
+ : data_(s), size_(count) {}
412
+
413
+ /**
414
+ \rst
415
+ Constructs a string reference object from a C string computing
416
+ the size with ``std::char_traits<Char>::length``.
417
+ \endrst
418
+ */
419
+ FMT_CONSTEXPR_CHAR_TRAITS
420
+ FMT_INLINE
421
+ basic_string_view(const Char* s)
422
+ : data_(s),
423
+ size_(detail::const_check(std::is_same<Char, char>::value &&
424
+ !detail::is_constant_evaluated(true))
425
+ ? std::strlen(reinterpret_cast<const char*>(s))
426
+ : std::char_traits<Char>::length(s)) {}
427
+
428
+ /** Constructs a string reference from a ``std::basic_string`` object. */
429
+ template <typename Traits, typename Alloc>
430
+ FMT_CONSTEXPR basic_string_view(
431
+ const std::basic_string<Char, Traits, Alloc>& s) noexcept
432
+ : data_(s.data()), size_(s.size()) {}
433
+
434
+ template <typename S, FMT_ENABLE_IF(std::is_same<
435
+ S, detail::std_string_view<Char>>::value)>
436
+ FMT_CONSTEXPR basic_string_view(S s) noexcept
437
+ : data_(s.data()), size_(s.size()) {}
438
+
439
+ /** Returns a pointer to the string data. */
440
+ constexpr auto data() const noexcept -> const Char* { return data_; }
441
+
442
+ /** Returns the string size. */
443
+ constexpr auto size() const noexcept -> size_t { return size_; }
444
+
445
+ constexpr auto begin() const noexcept -> iterator { return data_; }
446
+ constexpr auto end() const noexcept -> iterator { return data_ + size_; }
447
+
448
+ constexpr auto operator[](size_t pos) const noexcept -> const Char& {
449
+ return data_[pos];
450
+ }
451
+
452
+ FMT_CONSTEXPR void remove_prefix(size_t n) noexcept {
453
+ data_ += n;
454
+ size_ -= n;
455
+ }
456
+
457
+ FMT_CONSTEXPR_CHAR_TRAITS bool starts_with(
458
+ basic_string_view<Char> sv) const noexcept {
459
+ return size_ >= sv.size_ &&
460
+ std::char_traits<Char>::compare(data_, sv.data_, sv.size_) == 0;
461
+ }
462
+ FMT_CONSTEXPR_CHAR_TRAITS bool starts_with(Char c) const noexcept {
463
+ return size_ >= 1 && std::char_traits<Char>::eq(*data_, c);
464
+ }
465
+ FMT_CONSTEXPR_CHAR_TRAITS bool starts_with(const Char* s) const {
466
+ return starts_with(basic_string_view<Char>(s));
467
+ }
468
+
469
+ // Lexicographically compare this string reference to other.
470
+ FMT_CONSTEXPR_CHAR_TRAITS auto compare(basic_string_view other) const -> int {
471
+ size_t str_size = size_ < other.size_ ? size_ : other.size_;
472
+ int result = std::char_traits<Char>::compare(data_, other.data_, str_size);
473
+ if (result == 0)
474
+ result = size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1);
475
+ return result;
476
+ }
477
+
478
+ FMT_CONSTEXPR_CHAR_TRAITS friend auto operator==(basic_string_view lhs,
479
+ basic_string_view rhs)
480
+ -> bool {
481
+ return lhs.compare(rhs) == 0;
482
+ }
483
+ friend auto operator!=(basic_string_view lhs, basic_string_view rhs) -> bool {
484
+ return lhs.compare(rhs) != 0;
485
+ }
486
+ friend auto operator<(basic_string_view lhs, basic_string_view rhs) -> bool {
487
+ return lhs.compare(rhs) < 0;
488
+ }
489
+ friend auto operator<=(basic_string_view lhs, basic_string_view rhs) -> bool {
490
+ return lhs.compare(rhs) <= 0;
491
+ }
492
+ friend auto operator>(basic_string_view lhs, basic_string_view rhs) -> bool {
493
+ return lhs.compare(rhs) > 0;
494
+ }
495
+ friend auto operator>=(basic_string_view lhs, basic_string_view rhs) -> bool {
496
+ return lhs.compare(rhs) >= 0;
497
+ }
498
+ };
499
+
500
+ FMT_EXPORT
501
+ using string_view = basic_string_view<char>;
502
+
503
+ /** Specifies if ``T`` is a character type. Can be specialized by users. */
504
+ FMT_EXPORT
505
+ template <typename T> struct is_char : std::false_type {};
506
+ template <> struct is_char<char> : std::true_type {};
507
+
508
+ namespace detail {
509
+
510
+ // A base class for compile-time strings.
511
+ struct compile_string {};
512
+
513
+ template <typename S>
514
+ struct is_compile_string : std::is_base_of<compile_string, S> {};
515
+
516
+ template <typename Char, FMT_ENABLE_IF(is_char<Char>::value)>
517
+ FMT_INLINE auto to_string_view(const Char* s) -> basic_string_view<Char> {
518
+ return s;
519
+ }
520
+ template <typename Char, typename Traits, typename Alloc>
521
+ inline auto to_string_view(const std::basic_string<Char, Traits, Alloc>& s)
522
+ -> basic_string_view<Char> {
523
+ return s;
524
+ }
525
+ template <typename Char>
526
+ constexpr auto to_string_view(basic_string_view<Char> s)
527
+ -> basic_string_view<Char> {
528
+ return s;
529
+ }
530
+ template <typename Char,
531
+ FMT_ENABLE_IF(!std::is_empty<std_string_view<Char>>::value)>
532
+ inline auto to_string_view(std_string_view<Char> s) -> basic_string_view<Char> {
533
+ return s;
534
+ }
535
+ template <typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
536
+ constexpr auto to_string_view(const S& s)
537
+ -> basic_string_view<typename S::char_type> {
538
+ return basic_string_view<typename S::char_type>(s);
539
+ }
540
+ void to_string_view(...);
541
+
542
+ // Specifies whether S is a string type convertible to fmt::basic_string_view.
543
+ // It should be a constexpr function but MSVC 2017 fails to compile it in
544
+ // enable_if and MSVC 2015 fails to compile it as an alias template.
545
+ // ADL is intentionally disabled as to_string_view is not an extension point.
546
+ template <typename S>
547
+ struct is_string
548
+ : std::is_class<decltype(detail::to_string_view(std::declval<S>()))> {};
549
+
550
+ template <typename S, typename = void> struct char_t_impl {};
551
+ template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
552
+ using result = decltype(to_string_view(std::declval<S>()));
553
+ using type = typename result::value_type;
554
+ };
555
+
556
+ enum class type {
557
+ none_type,
558
+ // Integer types should go first,
559
+ int_type,
560
+ uint_type,
561
+ long_long_type,
562
+ ulong_long_type,
563
+ int128_type,
564
+ uint128_type,
565
+ bool_type,
566
+ char_type,
567
+ last_integer_type = char_type,
568
+ // followed by floating-point types.
569
+ float_type,
570
+ double_type,
571
+ long_double_type,
572
+ last_numeric_type = long_double_type,
573
+ cstring_type,
574
+ string_type,
575
+ pointer_type,
576
+ custom_type
577
+ };
578
+
579
+ // Maps core type T to the corresponding type enum constant.
580
+ template <typename T, typename Char>
581
+ struct type_constant : std::integral_constant<type, type::custom_type> {};
582
+
583
+ #define FMT_TYPE_CONSTANT(Type, constant) \
584
+ template <typename Char> \
585
+ struct type_constant<Type, Char> \
586
+ : std::integral_constant<type, type::constant> {}
587
+
588
+ FMT_TYPE_CONSTANT(int, int_type);
589
+ FMT_TYPE_CONSTANT(unsigned, uint_type);
590
+ FMT_TYPE_CONSTANT(long long, long_long_type);
591
+ FMT_TYPE_CONSTANT(unsigned long long, ulong_long_type);
592
+ FMT_TYPE_CONSTANT(int128_opt, int128_type);
593
+ FMT_TYPE_CONSTANT(uint128_opt, uint128_type);
594
+ FMT_TYPE_CONSTANT(bool, bool_type);
595
+ FMT_TYPE_CONSTANT(Char, char_type);
596
+ FMT_TYPE_CONSTANT(float, float_type);
597
+ FMT_TYPE_CONSTANT(double, double_type);
598
+ FMT_TYPE_CONSTANT(long double, long_double_type);
599
+ FMT_TYPE_CONSTANT(const Char*, cstring_type);
600
+ FMT_TYPE_CONSTANT(basic_string_view<Char>, string_type);
601
+ FMT_TYPE_CONSTANT(const void*, pointer_type);
602
+
603
+ constexpr bool is_integral_type(type t) {
604
+ return t > type::none_type && t <= type::last_integer_type;
605
+ }
606
+ constexpr bool is_arithmetic_type(type t) {
607
+ return t > type::none_type && t <= type::last_numeric_type;
608
+ }
609
+
610
+ constexpr auto set(type rhs) -> int { return 1 << static_cast<int>(rhs); }
611
+ constexpr auto in(type t, int set) -> bool {
612
+ return ((set >> static_cast<int>(t)) & 1) != 0;
613
+ }
614
+
615
+ // Bitsets of types.
616
+ enum {
617
+ sint_set =
618
+ set(type::int_type) | set(type::long_long_type) | set(type::int128_type),
619
+ uint_set = set(type::uint_type) | set(type::ulong_long_type) |
620
+ set(type::uint128_type),
621
+ bool_set = set(type::bool_type),
622
+ char_set = set(type::char_type),
623
+ float_set = set(type::float_type) | set(type::double_type) |
624
+ set(type::long_double_type),
625
+ string_set = set(type::string_type),
626
+ cstring_set = set(type::cstring_type),
627
+ pointer_set = set(type::pointer_type)
628
+ };
629
+
630
+ FMT_NORETURN FMT_API void throw_format_error(const char* message);
631
+
632
+ struct error_handler {
633
+ constexpr error_handler() = default;
634
+
635
+ // This function is intentionally not constexpr to give a compile-time error.
636
+ FMT_NORETURN void on_error(const char* message) {
637
+ throw_format_error(message);
638
+ }
639
+ };
640
+ } // namespace detail
641
+
642
+ /** Throws ``format_error`` with a given message. */
643
+ using detail::throw_format_error;
644
+
645
+ /** String's character type. */
646
+ template <typename S> using char_t = typename detail::char_t_impl<S>::type;
647
+
648
+ /**
649
+ \rst
650
+ Parsing context consisting of a format string range being parsed and an
651
+ argument counter for automatic indexing.
652
+ You can use the ``format_parse_context`` type alias for ``char`` instead.
653
+ \endrst
654
+ */
655
+ FMT_EXPORT
656
+ template <typename Char> class basic_format_parse_context {
657
+ private:
658
+ basic_string_view<Char> format_str_;
659
+ int next_arg_id_;
660
+
661
+ FMT_CONSTEXPR void do_check_arg_id(int id);
662
+
663
+ public:
664
+ using char_type = Char;
665
+ using iterator = const Char*;
666
+
667
+ explicit constexpr basic_format_parse_context(
668
+ basic_string_view<Char> format_str, int next_arg_id = 0)
669
+ : format_str_(format_str), next_arg_id_(next_arg_id) {}
670
+
671
+ /**
672
+ Returns an iterator to the beginning of the format string range being
673
+ parsed.
674
+ */
675
+ constexpr auto begin() const noexcept -> iterator {
676
+ return format_str_.begin();
677
+ }
678
+
679
+ /**
680
+ Returns an iterator past the end of the format string range being parsed.
681
+ */
682
+ constexpr auto end() const noexcept -> iterator { return format_str_.end(); }
683
+
684
+ /** Advances the begin iterator to ``it``. */
685
+ FMT_CONSTEXPR void advance_to(iterator it) {
686
+ format_str_.remove_prefix(detail::to_unsigned(it - begin()));
687
+ }
688
+
689
+ /**
690
+ Reports an error if using the manual argument indexing; otherwise returns
691
+ the next argument index and switches to the automatic indexing.
692
+ */
693
+ FMT_CONSTEXPR auto next_arg_id() -> int {
694
+ if (next_arg_id_ < 0) {
695
+ detail::throw_format_error(
696
+ "cannot switch from manual to automatic argument indexing");
697
+ return 0;
698
+ }
699
+ int id = next_arg_id_++;
700
+ do_check_arg_id(id);
701
+ return id;
702
+ }
703
+
704
+ /**
705
+ Reports an error if using the automatic argument indexing; otherwise
706
+ switches to the manual indexing.
707
+ */
708
+ FMT_CONSTEXPR void check_arg_id(int id) {
709
+ if (next_arg_id_ > 0) {
710
+ detail::throw_format_error(
711
+ "cannot switch from automatic to manual argument indexing");
712
+ return;
713
+ }
714
+ next_arg_id_ = -1;
715
+ do_check_arg_id(id);
716
+ }
717
+ FMT_CONSTEXPR void check_arg_id(basic_string_view<Char>) {}
718
+ FMT_CONSTEXPR void check_dynamic_spec(int arg_id);
719
+ };
720
+
721
+ FMT_EXPORT
722
+ using format_parse_context = basic_format_parse_context<char>;
723
+
724
+ namespace detail {
725
+ // A parse context with extra data used only in compile-time checks.
726
+ template <typename Char>
727
+ class compile_parse_context : public basic_format_parse_context<Char> {
728
+ private:
729
+ int num_args_;
730
+ const type* types_;
731
+ using base = basic_format_parse_context<Char>;
732
+
733
+ public:
734
+ explicit FMT_CONSTEXPR compile_parse_context(
735
+ basic_string_view<Char> format_str, int num_args, const type* types,
736
+ int next_arg_id = 0)
737
+ : base(format_str, next_arg_id), num_args_(num_args), types_(types) {}
738
+
739
+ constexpr auto num_args() const -> int { return num_args_; }
740
+ constexpr auto arg_type(int id) const -> type { return types_[id]; }
741
+
742
+ FMT_CONSTEXPR auto next_arg_id() -> int {
743
+ int id = base::next_arg_id();
744
+ if (id >= num_args_) throw_format_error("argument not found");
745
+ return id;
746
+ }
747
+
748
+ FMT_CONSTEXPR void check_arg_id(int id) {
749
+ base::check_arg_id(id);
750
+ if (id >= num_args_) throw_format_error("argument not found");
751
+ }
752
+ using base::check_arg_id;
753
+
754
+ FMT_CONSTEXPR void check_dynamic_spec(int arg_id) {
755
+ detail::ignore_unused(arg_id);
756
+ #if !defined(__LCC__)
757
+ if (arg_id < num_args_ && types_ && !is_integral_type(types_[arg_id]))
758
+ throw_format_error("width/precision is not integer");
759
+ #endif
760
+ }
761
+ };
762
+
763
+ // Extracts a reference to the container from back_insert_iterator.
764
+ template <typename Container>
765
+ inline auto get_container(std::back_insert_iterator<Container> it)
766
+ -> Container& {
767
+ using base = std::back_insert_iterator<Container>;
768
+ struct accessor : base {
769
+ accessor(base b) : base(b) {}
770
+ using base::container;
771
+ };
772
+ return *accessor(it).container;
773
+ }
774
+
775
+ template <typename Char, typename InputIt, typename OutputIt>
776
+ FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out)
777
+ -> OutputIt {
778
+ while (begin != end) *out++ = static_cast<Char>(*begin++);
779
+ return out;
780
+ }
781
+
782
+ template <typename Char, typename T, typename U,
783
+ FMT_ENABLE_IF(
784
+ std::is_same<remove_const_t<T>, U>::value&& is_char<U>::value)>
785
+ FMT_CONSTEXPR auto copy_str(T* begin, T* end, U* out) -> U* {
786
+ if (is_constant_evaluated()) return copy_str<Char, T*, U*>(begin, end, out);
787
+ auto size = to_unsigned(end - begin);
788
+ if (size > 0) memcpy(out, begin, size * sizeof(U));
789
+ return out + size;
790
+ }
791
+
792
+ /**
793
+ \rst
794
+ A contiguous memory buffer with an optional growing ability. It is an internal
795
+ class and shouldn't be used directly, only via `~fmt::basic_memory_buffer`.
796
+ \endrst
797
+ */
798
+ template <typename T> class buffer {
799
+ private:
800
+ T* ptr_;
801
+ size_t size_;
802
+ size_t capacity_;
803
+
804
+ protected:
805
+ // Don't initialize ptr_ since it is not accessed to save a few cycles.
806
+ FMT_MSC_WARNING(suppress : 26495)
807
+ buffer(size_t sz) noexcept : size_(sz), capacity_(sz) {}
808
+
809
+ FMT_CONSTEXPR20 buffer(T* p = nullptr, size_t sz = 0, size_t cap = 0) noexcept
810
+ : ptr_(p), size_(sz), capacity_(cap) {}
811
+
812
+ FMT_CONSTEXPR20 ~buffer() = default;
813
+ buffer(buffer&&) = default;
814
+
815
+ /** Sets the buffer data and capacity. */
816
+ FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) noexcept {
817
+ ptr_ = buf_data;
818
+ capacity_ = buf_capacity;
819
+ }
820
+
821
+ /** Increases the buffer capacity to hold at least *capacity* elements. */
822
+ virtual FMT_CONSTEXPR20 void grow(size_t capacity) = 0;
823
+
824
+ public:
825
+ using value_type = T;
826
+ using const_reference = const T&;
827
+
828
+ buffer(const buffer&) = delete;
829
+ void operator=(const buffer&) = delete;
830
+
831
+ FMT_INLINE auto begin() noexcept -> T* { return ptr_; }
832
+ FMT_INLINE auto end() noexcept -> T* { return ptr_ + size_; }
833
+
834
+ FMT_INLINE auto begin() const noexcept -> const T* { return ptr_; }
835
+ FMT_INLINE auto end() const noexcept -> const T* { return ptr_ + size_; }
836
+
837
+ /** Returns the size of this buffer. */
838
+ constexpr auto size() const noexcept -> size_t { return size_; }
839
+
840
+ /** Returns the capacity of this buffer. */
841
+ constexpr auto capacity() const noexcept -> size_t { return capacity_; }
842
+
843
+ /** Returns a pointer to the buffer data (not null-terminated). */
844
+ FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; }
845
+ FMT_CONSTEXPR auto data() const noexcept -> const T* { return ptr_; }
846
+
847
+ /** Clears this buffer. */
848
+ void clear() { size_ = 0; }
849
+
850
+ // Tries resizing the buffer to contain *count* elements. If T is a POD type
851
+ // the new elements may not be initialized.
852
+ FMT_CONSTEXPR20 void try_resize(size_t count) {
853
+ try_reserve(count);
854
+ size_ = count <= capacity_ ? count : capacity_;
855
+ }
856
+
857
+ // Tries increasing the buffer capacity to *new_capacity*. It can increase the
858
+ // capacity by a smaller amount than requested but guarantees there is space
859
+ // for at least one additional element either by increasing the capacity or by
860
+ // flushing the buffer if it is full.
861
+ FMT_CONSTEXPR20 void try_reserve(size_t new_capacity) {
862
+ if (new_capacity > capacity_) grow(new_capacity);
863
+ }
864
+
865
+ FMT_CONSTEXPR20 void push_back(const T& value) {
866
+ try_reserve(size_ + 1);
867
+ ptr_[size_++] = value;
868
+ }
869
+
870
+ /** Appends data to the end of the buffer. */
871
+ template <typename U> void append(const U* begin, const U* end);
872
+
873
+ template <typename Idx> FMT_CONSTEXPR auto operator[](Idx index) -> T& {
874
+ return ptr_[index];
875
+ }
876
+ template <typename Idx>
877
+ FMT_CONSTEXPR auto operator[](Idx index) const -> const T& {
878
+ return ptr_[index];
879
+ }
880
+ };
881
+
882
+ struct buffer_traits {
883
+ explicit buffer_traits(size_t) {}
884
+ auto count() const -> size_t { return 0; }
885
+ auto limit(size_t size) -> size_t { return size; }
886
+ };
887
+
888
+ class fixed_buffer_traits {
889
+ private:
890
+ size_t count_ = 0;
891
+ size_t limit_;
892
+
893
+ public:
894
+ explicit fixed_buffer_traits(size_t limit) : limit_(limit) {}
895
+ auto count() const -> size_t { return count_; }
896
+ auto limit(size_t size) -> size_t {
897
+ size_t n = limit_ > count_ ? limit_ - count_ : 0;
898
+ count_ += size;
899
+ return size < n ? size : n;
900
+ }
901
+ };
902
+
903
+ // A buffer that writes to an output iterator when flushed.
904
+ template <typename OutputIt, typename T, typename Traits = buffer_traits>
905
+ class iterator_buffer final : public Traits, public buffer<T> {
906
+ private:
907
+ OutputIt out_;
908
+ enum { buffer_size = 256 };
909
+ T data_[buffer_size];
910
+
911
+ protected:
912
+ FMT_CONSTEXPR20 void grow(size_t) override {
913
+ if (this->size() == buffer_size) flush();
914
+ }
915
+
916
+ void flush() {
917
+ auto size = this->size();
918
+ this->clear();
919
+ out_ = copy_str<T>(data_, data_ + this->limit(size), out_);
920
+ }
921
+
922
+ public:
923
+ explicit iterator_buffer(OutputIt out, size_t n = buffer_size)
924
+ : Traits(n), buffer<T>(data_, 0, buffer_size), out_(out) {}
925
+ iterator_buffer(iterator_buffer&& other)
926
+ : Traits(other), buffer<T>(data_, 0, buffer_size), out_(other.out_) {}
927
+ ~iterator_buffer() { flush(); }
928
+
929
+ auto out() -> OutputIt {
930
+ flush();
931
+ return out_;
932
+ }
933
+ auto count() const -> size_t { return Traits::count() + this->size(); }
934
+ };
935
+
936
+ template <typename T>
937
+ class iterator_buffer<T*, T, fixed_buffer_traits> final
938
+ : public fixed_buffer_traits,
939
+ public buffer<T> {
940
+ private:
941
+ T* out_;
942
+ enum { buffer_size = 256 };
943
+ T data_[buffer_size];
944
+
945
+ protected:
946
+ FMT_CONSTEXPR20 void grow(size_t) override {
947
+ if (this->size() == this->capacity()) flush();
948
+ }
949
+
950
+ void flush() {
951
+ size_t n = this->limit(this->size());
952
+ if (this->data() == out_) {
953
+ out_ += n;
954
+ this->set(data_, buffer_size);
955
+ }
956
+ this->clear();
957
+ }
958
+
959
+ public:
960
+ explicit iterator_buffer(T* out, size_t n = buffer_size)
961
+ : fixed_buffer_traits(n), buffer<T>(out, 0, n), out_(out) {}
962
+ iterator_buffer(iterator_buffer&& other)
963
+ : fixed_buffer_traits(other),
964
+ buffer<T>(std::move(other)),
965
+ out_(other.out_) {
966
+ if (this->data() != out_) {
967
+ this->set(data_, buffer_size);
968
+ this->clear();
969
+ }
970
+ }
971
+ ~iterator_buffer() { flush(); }
972
+
973
+ auto out() -> T* {
974
+ flush();
975
+ return out_;
976
+ }
977
+ auto count() const -> size_t {
978
+ return fixed_buffer_traits::count() + this->size();
979
+ }
980
+ };
981
+
982
+ template <typename T> class iterator_buffer<T*, T> final : public buffer<T> {
983
+ protected:
984
+ FMT_CONSTEXPR20 void grow(size_t) override {}
985
+
986
+ public:
987
+ explicit iterator_buffer(T* out, size_t = 0) : buffer<T>(out, 0, ~size_t()) {}
988
+
989
+ auto out() -> T* { return &*this->end(); }
990
+ };
991
+
992
+ // A buffer that writes to a container with the contiguous storage.
993
+ template <typename Container>
994
+ class iterator_buffer<std::back_insert_iterator<Container>,
995
+ enable_if_t<is_contiguous<Container>::value,
996
+ typename Container::value_type>>
997
+ final : public buffer<typename Container::value_type> {
998
+ private:
999
+ Container& container_;
1000
+
1001
+ protected:
1002
+ FMT_CONSTEXPR20 void grow(size_t capacity) override {
1003
+ container_.resize(capacity);
1004
+ this->set(&container_[0], capacity);
1005
+ }
1006
+
1007
+ public:
1008
+ explicit iterator_buffer(Container& c)
1009
+ : buffer<typename Container::value_type>(c.size()), container_(c) {}
1010
+ explicit iterator_buffer(std::back_insert_iterator<Container> out, size_t = 0)
1011
+ : iterator_buffer(get_container(out)) {}
1012
+
1013
+ auto out() -> std::back_insert_iterator<Container> {
1014
+ return std::back_inserter(container_);
1015
+ }
1016
+ };
1017
+
1018
+ // A buffer that counts the number of code units written discarding the output.
1019
+ template <typename T = char> class counting_buffer final : public buffer<T> {
1020
+ private:
1021
+ enum { buffer_size = 256 };
1022
+ T data_[buffer_size];
1023
+ size_t count_ = 0;
1024
+
1025
+ protected:
1026
+ FMT_CONSTEXPR20 void grow(size_t) override {
1027
+ if (this->size() != buffer_size) return;
1028
+ count_ += this->size();
1029
+ this->clear();
1030
+ }
1031
+
1032
+ public:
1033
+ counting_buffer() : buffer<T>(data_, 0, buffer_size) {}
1034
+
1035
+ auto count() -> size_t { return count_ + this->size(); }
1036
+ };
1037
+ } // namespace detail
1038
+
1039
+ template <typename Char>
1040
+ FMT_CONSTEXPR void basic_format_parse_context<Char>::do_check_arg_id(int id) {
1041
+ // Argument id is only checked at compile-time during parsing because
1042
+ // formatting has its own validation.
1043
+ if (detail::is_constant_evaluated() &&
1044
+ (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) {
1045
+ using context = detail::compile_parse_context<Char>;
1046
+ if (id >= static_cast<context*>(this)->num_args())
1047
+ detail::throw_format_error("argument not found");
1048
+ }
1049
+ }
1050
+
1051
+ template <typename Char>
1052
+ FMT_CONSTEXPR void basic_format_parse_context<Char>::check_dynamic_spec(
1053
+ int arg_id) {
1054
+ if (detail::is_constant_evaluated() &&
1055
+ (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200)) {
1056
+ using context = detail::compile_parse_context<Char>;
1057
+ static_cast<context*>(this)->check_dynamic_spec(arg_id);
1058
+ }
1059
+ }
1060
+
1061
+ FMT_EXPORT template <typename Context> class basic_format_arg;
1062
+ FMT_EXPORT template <typename Context> class basic_format_args;
1063
+ FMT_EXPORT template <typename Context> class dynamic_format_arg_store;
1064
+
1065
+ // A formatter for objects of type T.
1066
+ FMT_EXPORT
1067
+ template <typename T, typename Char = char, typename Enable = void>
1068
+ struct formatter {
1069
+ // A deleted default constructor indicates a disabled formatter.
1070
+ formatter() = delete;
1071
+ };
1072
+
1073
+ // Specifies if T has an enabled formatter specialization. A type can be
1074
+ // formattable even if it doesn't have a formatter e.g. via a conversion.
1075
+ template <typename T, typename Context>
1076
+ using has_formatter =
1077
+ std::is_constructible<typename Context::template formatter_type<T>>;
1078
+
1079
+ // An output iterator that appends to a buffer.
1080
+ // It is used to reduce symbol sizes for the common case.
1081
+ class appender : public std::back_insert_iterator<detail::buffer<char>> {
1082
+ using base = std::back_insert_iterator<detail::buffer<char>>;
1083
+
1084
+ public:
1085
+ using std::back_insert_iterator<detail::buffer<char>>::back_insert_iterator;
1086
+ appender(base it) noexcept : base(it) {}
1087
+ FMT_UNCHECKED_ITERATOR(appender);
1088
+
1089
+ auto operator++() noexcept -> appender& { return *this; }
1090
+ auto operator++(int) noexcept -> appender { return *this; }
1091
+ };
1092
+
1093
+ namespace detail {
1094
+
1095
+ template <typename Context, typename T>
1096
+ constexpr auto has_const_formatter_impl(T*)
1097
+ -> decltype(typename Context::template formatter_type<T>().format(
1098
+ std::declval<const T&>(), std::declval<Context&>()),
1099
+ true) {
1100
+ return true;
1101
+ }
1102
+ template <typename Context>
1103
+ constexpr auto has_const_formatter_impl(...) -> bool {
1104
+ return false;
1105
+ }
1106
+ template <typename T, typename Context>
1107
+ constexpr auto has_const_formatter() -> bool {
1108
+ return has_const_formatter_impl<Context>(static_cast<T*>(nullptr));
1109
+ }
1110
+
1111
+ template <typename T>
1112
+ using buffer_appender = conditional_t<std::is_same<T, char>::value, appender,
1113
+ std::back_insert_iterator<buffer<T>>>;
1114
+
1115
+ // Maps an output iterator to a buffer.
1116
+ template <typename T, typename OutputIt>
1117
+ auto get_buffer(OutputIt out) -> iterator_buffer<OutputIt, T> {
1118
+ return iterator_buffer<OutputIt, T>(out);
1119
+ }
1120
+ template <typename T, typename Buf,
1121
+ FMT_ENABLE_IF(std::is_base_of<buffer<char>, Buf>::value)>
1122
+ auto get_buffer(std::back_insert_iterator<Buf> out) -> buffer<char>& {
1123
+ return get_container(out);
1124
+ }
1125
+
1126
+ template <typename Buf, typename OutputIt>
1127
+ FMT_INLINE auto get_iterator(Buf& buf, OutputIt) -> decltype(buf.out()) {
1128
+ return buf.out();
1129
+ }
1130
+ template <typename T, typename OutputIt>
1131
+ auto get_iterator(buffer<T>&, OutputIt out) -> OutputIt {
1132
+ return out;
1133
+ }
1134
+
1135
+ struct view {};
1136
+
1137
+ template <typename Char, typename T> struct named_arg : view {
1138
+ const Char* name;
1139
+ const T& value;
1140
+ named_arg(const Char* n, const T& v) : name(n), value(v) {}
1141
+ };
1142
+
1143
+ template <typename Char> struct named_arg_info {
1144
+ const Char* name;
1145
+ int id;
1146
+ };
1147
+
1148
+ template <typename T, typename Char, size_t NUM_ARGS, size_t NUM_NAMED_ARGS>
1149
+ struct arg_data {
1150
+ // args_[0].named_args points to named_args_ to avoid bloating format_args.
1151
+ // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning.
1152
+ T args_[1 + (NUM_ARGS != 0 ? NUM_ARGS : +1)];
1153
+ named_arg_info<Char> named_args_[NUM_NAMED_ARGS];
1154
+
1155
+ template <typename... U>
1156
+ arg_data(const U&... init) : args_{T(named_args_, NUM_NAMED_ARGS), init...} {}
1157
+ arg_data(const arg_data& other) = delete;
1158
+ auto args() const -> const T* { return args_ + 1; }
1159
+ auto named_args() -> named_arg_info<Char>* { return named_args_; }
1160
+ };
1161
+
1162
+ template <typename T, typename Char, size_t NUM_ARGS>
1163
+ struct arg_data<T, Char, NUM_ARGS, 0> {
1164
+ // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning.
1165
+ T args_[NUM_ARGS != 0 ? NUM_ARGS : +1];
1166
+
1167
+ template <typename... U>
1168
+ FMT_CONSTEXPR FMT_INLINE arg_data(const U&... init) : args_{init...} {}
1169
+ FMT_CONSTEXPR FMT_INLINE auto args() const -> const T* { return args_; }
1170
+ FMT_CONSTEXPR FMT_INLINE auto named_args() -> std::nullptr_t {
1171
+ return nullptr;
1172
+ }
1173
+ };
1174
+
1175
+ template <typename Char>
1176
+ inline void init_named_args(named_arg_info<Char>*, int, int) {}
1177
+
1178
+ template <typename T> struct is_named_arg : std::false_type {};
1179
+ template <typename T> struct is_statically_named_arg : std::false_type {};
1180
+
1181
+ template <typename T, typename Char>
1182
+ struct is_named_arg<named_arg<Char, T>> : std::true_type {};
1183
+
1184
+ template <typename Char, typename T, typename... Tail,
1185
+ FMT_ENABLE_IF(!is_named_arg<T>::value)>
1186
+ void init_named_args(named_arg_info<Char>* named_args, int arg_count,
1187
+ int named_arg_count, const T&, const Tail&... args) {
1188
+ init_named_args(named_args, arg_count + 1, named_arg_count, args...);
1189
+ }
1190
+
1191
+ template <typename Char, typename T, typename... Tail,
1192
+ FMT_ENABLE_IF(is_named_arg<T>::value)>
1193
+ void init_named_args(named_arg_info<Char>* named_args, int arg_count,
1194
+ int named_arg_count, const T& arg, const Tail&... args) {
1195
+ named_args[named_arg_count++] = {arg.name, arg_count};
1196
+ init_named_args(named_args, arg_count + 1, named_arg_count, args...);
1197
+ }
1198
+
1199
+ template <typename... Args>
1200
+ FMT_CONSTEXPR FMT_INLINE void init_named_args(std::nullptr_t, int, int,
1201
+ const Args&...) {}
1202
+
1203
+ template <bool B = false> constexpr auto count() -> size_t { return B ? 1 : 0; }
1204
+ template <bool B1, bool B2, bool... Tail> constexpr auto count() -> size_t {
1205
+ return (B1 ? 1 : 0) + count<B2, Tail...>();
1206
+ }
1207
+
1208
+ template <typename... Args> constexpr auto count_named_args() -> size_t {
1209
+ return count<is_named_arg<Args>::value...>();
1210
+ }
1211
+
1212
+ template <typename... Args>
1213
+ constexpr auto count_statically_named_args() -> size_t {
1214
+ return count<is_statically_named_arg<Args>::value...>();
1215
+ }
1216
+
1217
+ struct unformattable {};
1218
+ struct unformattable_char : unformattable {};
1219
+ struct unformattable_pointer : unformattable {};
1220
+
1221
+ template <typename Char> struct string_value {
1222
+ const Char* data;
1223
+ size_t size;
1224
+ };
1225
+
1226
+ template <typename Char> struct named_arg_value {
1227
+ const named_arg_info<Char>* data;
1228
+ size_t size;
1229
+ };
1230
+
1231
+ template <typename Context> struct custom_value {
1232
+ using parse_context = typename Context::parse_context_type;
1233
+ void* value;
1234
+ void (*format)(void* arg, parse_context& parse_ctx, Context& ctx);
1235
+ };
1236
+
1237
+ // A formatting argument value.
1238
+ template <typename Context> class value {
1239
+ public:
1240
+ using char_type = typename Context::char_type;
1241
+
1242
+ union {
1243
+ monostate no_value;
1244
+ int int_value;
1245
+ unsigned uint_value;
1246
+ long long long_long_value;
1247
+ unsigned long long ulong_long_value;
1248
+ int128_opt int128_value;
1249
+ uint128_opt uint128_value;
1250
+ bool bool_value;
1251
+ char_type char_value;
1252
+ float float_value;
1253
+ double double_value;
1254
+ long double long_double_value;
1255
+ const void* pointer;
1256
+ string_value<char_type> string;
1257
+ custom_value<Context> custom;
1258
+ named_arg_value<char_type> named_args;
1259
+ };
1260
+
1261
+ constexpr FMT_INLINE value() : no_value() {}
1262
+ constexpr FMT_INLINE value(int val) : int_value(val) {}
1263
+ constexpr FMT_INLINE value(unsigned val) : uint_value(val) {}
1264
+ constexpr FMT_INLINE value(long long val) : long_long_value(val) {}
1265
+ constexpr FMT_INLINE value(unsigned long long val) : ulong_long_value(val) {}
1266
+ FMT_INLINE value(int128_opt val) : int128_value(val) {}
1267
+ FMT_INLINE value(uint128_opt val) : uint128_value(val) {}
1268
+ constexpr FMT_INLINE value(float val) : float_value(val) {}
1269
+ constexpr FMT_INLINE value(double val) : double_value(val) {}
1270
+ FMT_INLINE value(long double val) : long_double_value(val) {}
1271
+ constexpr FMT_INLINE value(bool val) : bool_value(val) {}
1272
+ constexpr FMT_INLINE value(char_type val) : char_value(val) {}
1273
+ FMT_CONSTEXPR FMT_INLINE value(const char_type* val) {
1274
+ string.data = val;
1275
+ if (is_constant_evaluated()) string.size = {};
1276
+ }
1277
+ FMT_CONSTEXPR FMT_INLINE value(basic_string_view<char_type> val) {
1278
+ string.data = val.data();
1279
+ string.size = val.size();
1280
+ }
1281
+ FMT_INLINE value(const void* val) : pointer(val) {}
1282
+ FMT_INLINE value(const named_arg_info<char_type>* args, size_t size)
1283
+ : named_args{args, size} {}
1284
+
1285
+ template <typename T> FMT_CONSTEXPR20 FMT_INLINE value(T& val) {
1286
+ using value_type = remove_const_t<T>;
1287
+ custom.value = const_cast<value_type*>(std::addressof(val));
1288
+ // Get the formatter type through the context to allow different contexts
1289
+ // have different extension points, e.g. `formatter<T>` for `format` and
1290
+ // `printf_formatter<T>` for `printf`.
1291
+ custom.format = format_custom_arg<
1292
+ value_type, typename Context::template formatter_type<value_type>>;
1293
+ }
1294
+ value(unformattable);
1295
+ value(unformattable_char);
1296
+ value(unformattable_pointer);
1297
+
1298
+ private:
1299
+ // Formats an argument of a custom type, such as a user-defined class.
1300
+ template <typename T, typename Formatter>
1301
+ static void format_custom_arg(void* arg,
1302
+ typename Context::parse_context_type& parse_ctx,
1303
+ Context& ctx) {
1304
+ auto f = Formatter();
1305
+ parse_ctx.advance_to(f.parse(parse_ctx));
1306
+ using qualified_type =
1307
+ conditional_t<has_const_formatter<T, Context>(), const T, T>;
1308
+ ctx.advance_to(f.format(*static_cast<qualified_type*>(arg), ctx));
1309
+ }
1310
+ };
1311
+
1312
+ // To minimize the number of types we need to deal with, long is translated
1313
+ // either to int or to long long depending on its size.
1314
+ enum { long_short = sizeof(long) == sizeof(int) };
1315
+ using long_type = conditional_t<long_short, int, long long>;
1316
+ using ulong_type = conditional_t<long_short, unsigned, unsigned long long>;
1317
+
1318
+ template <typename T> struct format_as_result {
1319
+ template <typename U,
1320
+ FMT_ENABLE_IF(std::is_enum<U>::value || std::is_class<U>::value)>
1321
+ static auto map(U*) -> decltype(format_as(std::declval<U>()));
1322
+ static auto map(...) -> void;
1323
+
1324
+ using type = decltype(map(static_cast<T*>(nullptr)));
1325
+ };
1326
+ template <typename T> using format_as_t = typename format_as_result<T>::type;
1327
+
1328
+ template <typename T>
1329
+ struct has_format_as
1330
+ : bool_constant<!std::is_same<format_as_t<T>, void>::value> {};
1331
+
1332
+ // Maps formatting arguments to core types.
1333
+ // arg_mapper reports errors by returning unformattable instead of using
1334
+ // static_assert because it's used in the is_formattable trait.
1335
+ template <typename Context> struct arg_mapper {
1336
+ using char_type = typename Context::char_type;
1337
+
1338
+ FMT_CONSTEXPR FMT_INLINE auto map(signed char val) -> int { return val; }
1339
+ FMT_CONSTEXPR FMT_INLINE auto map(unsigned char val) -> unsigned {
1340
+ return val;
1341
+ }
1342
+ FMT_CONSTEXPR FMT_INLINE auto map(short val) -> int { return val; }
1343
+ FMT_CONSTEXPR FMT_INLINE auto map(unsigned short val) -> unsigned {
1344
+ return val;
1345
+ }
1346
+ FMT_CONSTEXPR FMT_INLINE auto map(int val) -> int { return val; }
1347
+ FMT_CONSTEXPR FMT_INLINE auto map(unsigned val) -> unsigned { return val; }
1348
+ FMT_CONSTEXPR FMT_INLINE auto map(long val) -> long_type { return val; }
1349
+ FMT_CONSTEXPR FMT_INLINE auto map(unsigned long val) -> ulong_type {
1350
+ return val;
1351
+ }
1352
+ FMT_CONSTEXPR FMT_INLINE auto map(long long val) -> long long { return val; }
1353
+ FMT_CONSTEXPR FMT_INLINE auto map(unsigned long long val)
1354
+ -> unsigned long long {
1355
+ return val;
1356
+ }
1357
+ FMT_CONSTEXPR FMT_INLINE auto map(int128_opt val) -> int128_opt {
1358
+ return val;
1359
+ }
1360
+ FMT_CONSTEXPR FMT_INLINE auto map(uint128_opt val) -> uint128_opt {
1361
+ return val;
1362
+ }
1363
+ FMT_CONSTEXPR FMT_INLINE auto map(bool val) -> bool { return val; }
1364
+
1365
+ template <typename T, FMT_ENABLE_IF(std::is_same<T, char>::value ||
1366
+ std::is_same<T, char_type>::value)>
1367
+ FMT_CONSTEXPR FMT_INLINE auto map(T val) -> char_type {
1368
+ return val;
1369
+ }
1370
+ template <typename T, enable_if_t<(std::is_same<T, wchar_t>::value ||
1371
+ #ifdef __cpp_char8_t
1372
+ std::is_same<T, char8_t>::value ||
1373
+ #endif
1374
+ std::is_same<T, char16_t>::value ||
1375
+ std::is_same<T, char32_t>::value) &&
1376
+ !std::is_same<T, char_type>::value,
1377
+ int> = 0>
1378
+ FMT_CONSTEXPR FMT_INLINE auto map(T) -> unformattable_char {
1379
+ return {};
1380
+ }
1381
+
1382
+ FMT_CONSTEXPR FMT_INLINE auto map(float val) -> float { return val; }
1383
+ FMT_CONSTEXPR FMT_INLINE auto map(double val) -> double { return val; }
1384
+ FMT_CONSTEXPR FMT_INLINE auto map(long double val) -> long double {
1385
+ return val;
1386
+ }
1387
+
1388
+ FMT_CONSTEXPR FMT_INLINE auto map(char_type* val) -> const char_type* {
1389
+ return val;
1390
+ }
1391
+ FMT_CONSTEXPR FMT_INLINE auto map(const char_type* val) -> const char_type* {
1392
+ return val;
1393
+ }
1394
+ template <typename T,
1395
+ FMT_ENABLE_IF(is_string<T>::value && !std::is_pointer<T>::value &&
1396
+ std::is_same<char_type, char_t<T>>::value)>
1397
+ FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
1398
+ -> basic_string_view<char_type> {
1399
+ return to_string_view(val);
1400
+ }
1401
+ template <typename T,
1402
+ FMT_ENABLE_IF(is_string<T>::value && !std::is_pointer<T>::value &&
1403
+ !std::is_same<char_type, char_t<T>>::value)>
1404
+ FMT_CONSTEXPR FMT_INLINE auto map(const T&) -> unformattable_char {
1405
+ return {};
1406
+ }
1407
+
1408
+ FMT_CONSTEXPR FMT_INLINE auto map(void* val) -> const void* { return val; }
1409
+ FMT_CONSTEXPR FMT_INLINE auto map(const void* val) -> const void* {
1410
+ return val;
1411
+ }
1412
+ FMT_CONSTEXPR FMT_INLINE auto map(std::nullptr_t val) -> const void* {
1413
+ return val;
1414
+ }
1415
+
1416
+ // Use SFINAE instead of a const T* parameter to avoid a conflict with the
1417
+ // array overload.
1418
+ template <
1419
+ typename T,
1420
+ FMT_ENABLE_IF(
1421
+ std::is_pointer<T>::value || std::is_member_pointer<T>::value ||
1422
+ std::is_function<typename std::remove_pointer<T>::type>::value ||
1423
+ (std::is_convertible<const T&, const void*>::value &&
1424
+ !std::is_convertible<const T&, const char_type*>::value &&
1425
+ !has_formatter<T, Context>::value))>
1426
+ FMT_CONSTEXPR auto map(const T&) -> unformattable_pointer {
1427
+ return {};
1428
+ }
1429
+
1430
+ template <typename T, std::size_t N,
1431
+ FMT_ENABLE_IF(!std::is_same<T, wchar_t>::value)>
1432
+ FMT_CONSTEXPR FMT_INLINE auto map(const T (&values)[N]) -> const T (&)[N] {
1433
+ return values;
1434
+ }
1435
+
1436
+ // Only map owning types because mapping views can be unsafe.
1437
+ template <typename T, typename U = format_as_t<T>,
1438
+ FMT_ENABLE_IF(std::is_arithmetic<U>::value)>
1439
+ FMT_CONSTEXPR FMT_INLINE auto map(const T& val) -> decltype(this->map(U())) {
1440
+ return map(format_as(val));
1441
+ }
1442
+
1443
+ template <typename T, typename U = remove_const_t<T>>
1444
+ struct formattable : bool_constant<has_const_formatter<U, Context>() ||
1445
+ (has_formatter<U, Context>::value &&
1446
+ !std::is_const<T>::value)> {};
1447
+
1448
+ template <typename T, FMT_ENABLE_IF(formattable<T>::value)>
1449
+ FMT_CONSTEXPR FMT_INLINE auto do_map(T& val) -> T& {
1450
+ return val;
1451
+ }
1452
+ template <typename T, FMT_ENABLE_IF(!formattable<T>::value)>
1453
+ FMT_CONSTEXPR FMT_INLINE auto do_map(T&) -> unformattable {
1454
+ return {};
1455
+ }
1456
+
1457
+ template <typename T, typename U = remove_const_t<T>,
1458
+ FMT_ENABLE_IF((std::is_class<U>::value || std::is_enum<U>::value ||
1459
+ std::is_union<U>::value) &&
1460
+ !is_string<U>::value && !is_char<U>::value &&
1461
+ !is_named_arg<U>::value &&
1462
+ !std::is_arithmetic<format_as_t<U>>::value)>
1463
+ FMT_CONSTEXPR FMT_INLINE auto map(T& val) -> decltype(this->do_map(val)) {
1464
+ return do_map(val);
1465
+ }
1466
+
1467
+ template <typename T, FMT_ENABLE_IF(is_named_arg<T>::value)>
1468
+ FMT_CONSTEXPR FMT_INLINE auto map(const T& named_arg)
1469
+ -> decltype(this->map(named_arg.value)) {
1470
+ return map(named_arg.value);
1471
+ }
1472
+
1473
+ auto map(...) -> unformattable { return {}; }
1474
+ };
1475
+
1476
+ // A type constant after applying arg_mapper<Context>.
1477
+ template <typename T, typename Context>
1478
+ using mapped_type_constant =
1479
+ type_constant<decltype(arg_mapper<Context>().map(std::declval<const T&>())),
1480
+ typename Context::char_type>;
1481
+
1482
+ enum { packed_arg_bits = 4 };
1483
+ // Maximum number of arguments with packed types.
1484
+ enum { max_packed_args = 62 / packed_arg_bits };
1485
+ enum : unsigned long long { is_unpacked_bit = 1ULL << 63 };
1486
+ enum : unsigned long long { has_named_args_bit = 1ULL << 62 };
1487
+
1488
+ template <typename Char, typename InputIt>
1489
+ auto copy_str(InputIt begin, InputIt end, appender out) -> appender {
1490
+ get_container(out).append(begin, end);
1491
+ return out;
1492
+ }
1493
+ template <typename Char, typename InputIt>
1494
+ auto copy_str(InputIt begin, InputIt end,
1495
+ std::back_insert_iterator<std::string> out)
1496
+ -> std::back_insert_iterator<std::string> {
1497
+ get_container(out).append(begin, end);
1498
+ return out;
1499
+ }
1500
+
1501
+ template <typename Char, typename R, typename OutputIt>
1502
+ FMT_CONSTEXPR auto copy_str(R&& rng, OutputIt out) -> OutputIt {
1503
+ return detail::copy_str<Char>(rng.begin(), rng.end(), out);
1504
+ }
1505
+
1506
+ #if FMT_GCC_VERSION && FMT_GCC_VERSION < 500
1507
+ // A workaround for gcc 4.8 to make void_t work in a SFINAE context.
1508
+ template <typename...> struct void_t_impl { using type = void; };
1509
+ template <typename... T> using void_t = typename void_t_impl<T...>::type;
1510
+ #else
1511
+ template <typename...> using void_t = void;
1512
+ #endif
1513
+
1514
+ template <typename It, typename T, typename Enable = void>
1515
+ struct is_output_iterator : std::false_type {};
1516
+
1517
+ template <typename It, typename T>
1518
+ struct is_output_iterator<
1519
+ It, T,
1520
+ void_t<typename std::iterator_traits<It>::iterator_category,
1521
+ decltype(*std::declval<It>() = std::declval<T>())>>
1522
+ : std::true_type {};
1523
+
1524
+ template <typename It> struct is_back_insert_iterator : std::false_type {};
1525
+ template <typename Container>
1526
+ struct is_back_insert_iterator<std::back_insert_iterator<Container>>
1527
+ : std::true_type {};
1528
+
1529
+ // A type-erased reference to an std::locale to avoid a heavy <locale> include.
1530
+ class locale_ref {
1531
+ private:
1532
+ const void* locale_; // A type-erased pointer to std::locale.
1533
+
1534
+ public:
1535
+ constexpr FMT_INLINE locale_ref() : locale_(nullptr) {}
1536
+ template <typename Locale> explicit locale_ref(const Locale& loc);
1537
+
1538
+ explicit operator bool() const noexcept { return locale_ != nullptr; }
1539
+
1540
+ template <typename Locale> auto get() const -> Locale;
1541
+ };
1542
+
1543
+ template <typename> constexpr auto encode_types() -> unsigned long long {
1544
+ return 0;
1545
+ }
1546
+
1547
+ template <typename Context, typename Arg, typename... Args>
1548
+ constexpr auto encode_types() -> unsigned long long {
1549
+ return static_cast<unsigned>(mapped_type_constant<Arg, Context>::value) |
1550
+ (encode_types<Context, Args...>() << packed_arg_bits);
1551
+ }
1552
+
1553
+ #if defined(__cpp_if_constexpr)
1554
+ // This type is intentionally undefined, only used for errors
1555
+ template <typename T, typename Char> struct type_is_unformattable_for;
1556
+ #endif
1557
+
1558
+ template <bool PACKED, typename Context, typename T, FMT_ENABLE_IF(PACKED)>
1559
+ FMT_CONSTEXPR FMT_INLINE auto make_arg(T& val) -> value<Context> {
1560
+ using arg_type = remove_cvref_t<decltype(arg_mapper<Context>().map(val))>;
1561
+
1562
+ constexpr bool formattable_char =
1563
+ !std::is_same<arg_type, unformattable_char>::value;
1564
+ static_assert(formattable_char, "Mixing character types is disallowed.");
1565
+
1566
+ // Formatting of arbitrary pointers is disallowed. If you want to format a
1567
+ // pointer cast it to `void*` or `const void*`. In particular, this forbids
1568
+ // formatting of `[const] volatile char*` printed as bool by iostreams.
1569
+ constexpr bool formattable_pointer =
1570
+ !std::is_same<arg_type, unformattable_pointer>::value;
1571
+ static_assert(formattable_pointer,
1572
+ "Formatting of non-void pointers is disallowed.");
1573
+
1574
+ constexpr bool formattable = !std::is_same<arg_type, unformattable>::value;
1575
+ #if defined(__cpp_if_constexpr)
1576
+ if constexpr (!formattable) {
1577
+ type_is_unformattable_for<T, typename Context::char_type> _;
1578
+ }
1579
+ #endif
1580
+ static_assert(
1581
+ formattable,
1582
+ "Cannot format an argument. To make type T formattable provide a "
1583
+ "formatter<T> specialization: https://fmt.dev/latest/api.html#udt");
1584
+ return {arg_mapper<Context>().map(val)};
1585
+ }
1586
+
1587
+ template <typename Context, typename T>
1588
+ FMT_CONSTEXPR auto make_arg(T& val) -> basic_format_arg<Context> {
1589
+ auto arg = basic_format_arg<Context>();
1590
+ arg.type_ = mapped_type_constant<T, Context>::value;
1591
+ arg.value_ = make_arg<true, Context>(val);
1592
+ return arg;
1593
+ }
1594
+
1595
+ template <bool PACKED, typename Context, typename T, FMT_ENABLE_IF(!PACKED)>
1596
+ FMT_CONSTEXPR inline auto make_arg(T& val) -> basic_format_arg<Context> {
1597
+ return make_arg<Context>(val);
1598
+ }
1599
+ } // namespace detail
1600
+ FMT_BEGIN_EXPORT
1601
+
1602
+ // A formatting argument. It is a trivially copyable/constructible type to
1603
+ // allow storage in basic_memory_buffer.
1604
+ template <typename Context> class basic_format_arg {
1605
+ private:
1606
+ detail::value<Context> value_;
1607
+ detail::type type_;
1608
+
1609
+ template <typename ContextType, typename T>
1610
+ friend FMT_CONSTEXPR auto detail::make_arg(T& value)
1611
+ -> basic_format_arg<ContextType>;
1612
+
1613
+ template <typename Visitor, typename Ctx>
1614
+ friend FMT_CONSTEXPR auto visit_format_arg(Visitor&& vis,
1615
+ const basic_format_arg<Ctx>& arg)
1616
+ -> decltype(vis(0));
1617
+
1618
+ friend class basic_format_args<Context>;
1619
+ friend class dynamic_format_arg_store<Context>;
1620
+
1621
+ using char_type = typename Context::char_type;
1622
+
1623
+ template <typename T, typename Char, size_t NUM_ARGS, size_t NUM_NAMED_ARGS>
1624
+ friend struct detail::arg_data;
1625
+
1626
+ basic_format_arg(const detail::named_arg_info<char_type>* args, size_t size)
1627
+ : value_(args, size) {}
1628
+
1629
+ public:
1630
+ class handle {
1631
+ public:
1632
+ explicit handle(detail::custom_value<Context> custom) : custom_(custom) {}
1633
+
1634
+ void format(typename Context::parse_context_type& parse_ctx,
1635
+ Context& ctx) const {
1636
+ custom_.format(custom_.value, parse_ctx, ctx);
1637
+ }
1638
+
1639
+ private:
1640
+ detail::custom_value<Context> custom_;
1641
+ };
1642
+
1643
+ constexpr basic_format_arg() : type_(detail::type::none_type) {}
1644
+
1645
+ constexpr explicit operator bool() const noexcept {
1646
+ return type_ != detail::type::none_type;
1647
+ }
1648
+
1649
+ auto type() const -> detail::type { return type_; }
1650
+
1651
+ auto is_integral() const -> bool { return detail::is_integral_type(type_); }
1652
+ auto is_arithmetic() const -> bool {
1653
+ return detail::is_arithmetic_type(type_);
1654
+ }
1655
+ };
1656
+
1657
+ /**
1658
+ \rst
1659
+ Visits an argument dispatching to the appropriate visit method based on
1660
+ the argument type. For example, if the argument type is ``double`` then
1661
+ ``vis(value)`` will be called with the value of type ``double``.
1662
+ \endrst
1663
+ */
1664
+ // DEPRECATED!
1665
+ FMT_EXPORT
1666
+ template <typename Visitor, typename Context>
1667
+ FMT_CONSTEXPR FMT_INLINE auto visit_format_arg(
1668
+ Visitor&& vis, const basic_format_arg<Context>& arg) -> decltype(vis(0)) {
1669
+ switch (arg.type_) {
1670
+ case detail::type::none_type:
1671
+ break;
1672
+ case detail::type::int_type:
1673
+ return vis(arg.value_.int_value);
1674
+ case detail::type::uint_type:
1675
+ return vis(arg.value_.uint_value);
1676
+ case detail::type::long_long_type:
1677
+ return vis(arg.value_.long_long_value);
1678
+ case detail::type::ulong_long_type:
1679
+ return vis(arg.value_.ulong_long_value);
1680
+ case detail::type::int128_type:
1681
+ return vis(detail::convert_for_visit(arg.value_.int128_value));
1682
+ case detail::type::uint128_type:
1683
+ return vis(detail::convert_for_visit(arg.value_.uint128_value));
1684
+ case detail::type::bool_type:
1685
+ return vis(arg.value_.bool_value);
1686
+ case detail::type::char_type:
1687
+ return vis(arg.value_.char_value);
1688
+ case detail::type::float_type:
1689
+ return vis(arg.value_.float_value);
1690
+ case detail::type::double_type:
1691
+ return vis(arg.value_.double_value);
1692
+ case detail::type::long_double_type:
1693
+ return vis(arg.value_.long_double_value);
1694
+ case detail::type::cstring_type:
1695
+ return vis(arg.value_.string.data);
1696
+ case detail::type::string_type:
1697
+ using sv = basic_string_view<typename Context::char_type>;
1698
+ return vis(sv(arg.value_.string.data, arg.value_.string.size));
1699
+ case detail::type::pointer_type:
1700
+ return vis(arg.value_.pointer);
1701
+ case detail::type::custom_type:
1702
+ return vis(typename basic_format_arg<Context>::handle(arg.value_.custom));
1703
+ }
1704
+ return vis(monostate());
1705
+ }
1706
+
1707
+ // Formatting context.
1708
+ template <typename OutputIt, typename Char> class basic_format_context {
1709
+ private:
1710
+ OutputIt out_;
1711
+ basic_format_args<basic_format_context> args_;
1712
+ detail::locale_ref loc_;
1713
+
1714
+ public:
1715
+ using iterator = OutputIt;
1716
+ using format_arg = basic_format_arg<basic_format_context>;
1717
+ using format_args = basic_format_args<basic_format_context>;
1718
+ using parse_context_type = basic_format_parse_context<Char>;
1719
+ template <typename T> using formatter_type = formatter<T, Char>;
1720
+
1721
+ /** The character type for the output. */
1722
+ using char_type = Char;
1723
+
1724
+ basic_format_context(basic_format_context&&) = default;
1725
+ basic_format_context(const basic_format_context&) = delete;
1726
+ void operator=(const basic_format_context&) = delete;
1727
+ /**
1728
+ Constructs a ``basic_format_context`` object. References to the arguments
1729
+ are stored in the object so make sure they have appropriate lifetimes.
1730
+ */
1731
+ constexpr basic_format_context(OutputIt out, format_args ctx_args,
1732
+ detail::locale_ref loc = {})
1733
+ : out_(out), args_(ctx_args), loc_(loc) {}
1734
+
1735
+ constexpr auto arg(int id) const -> format_arg { return args_.get(id); }
1736
+ FMT_CONSTEXPR auto arg(basic_string_view<Char> name) -> format_arg {
1737
+ return args_.get(name);
1738
+ }
1739
+ FMT_CONSTEXPR auto arg_id(basic_string_view<Char> name) -> int {
1740
+ return args_.get_id(name);
1741
+ }
1742
+ auto args() const -> const format_args& { return args_; }
1743
+
1744
+ FMT_CONSTEXPR auto error_handler() -> detail::error_handler { return {}; }
1745
+ void on_error(const char* message) { error_handler().on_error(message); }
1746
+
1747
+ // Returns an iterator to the beginning of the output range.
1748
+ FMT_CONSTEXPR auto out() -> iterator { return out_; }
1749
+
1750
+ // Advances the begin iterator to ``it``.
1751
+ void advance_to(iterator it) {
1752
+ if (!detail::is_back_insert_iterator<iterator>()) out_ = it;
1753
+ }
1754
+
1755
+ FMT_CONSTEXPR auto locale() -> detail::locale_ref { return loc_; }
1756
+ };
1757
+
1758
+ template <typename Char>
1759
+ using buffer_context =
1760
+ basic_format_context<detail::buffer_appender<Char>, Char>;
1761
+ using format_context = buffer_context<char>;
1762
+
1763
+ template <typename T, typename Char = char>
1764
+ using is_formattable = bool_constant<!std::is_base_of<
1765
+ detail::unformattable, decltype(detail::arg_mapper<buffer_context<Char>>()
1766
+ .map(std::declval<T&>()))>::value>;
1767
+
1768
+ /**
1769
+ \rst
1770
+ An array of references to arguments. It can be implicitly converted into
1771
+ `~fmt::basic_format_args` for passing into type-erased formatting functions
1772
+ such as `~fmt::vformat`.
1773
+ \endrst
1774
+ */
1775
+ template <typename Context, typename... Args>
1776
+ class format_arg_store
1777
+ #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
1778
+ // Workaround a GCC template argument substitution bug.
1779
+ : public basic_format_args<Context>
1780
+ #endif
1781
+ {
1782
+ private:
1783
+ static const size_t num_args = sizeof...(Args);
1784
+ static constexpr size_t num_named_args = detail::count_named_args<Args...>();
1785
+ static const bool is_packed = num_args <= detail::max_packed_args;
1786
+
1787
+ using value_type = conditional_t<is_packed, detail::value<Context>,
1788
+ basic_format_arg<Context>>;
1789
+
1790
+ detail::arg_data<value_type, typename Context::char_type, num_args,
1791
+ num_named_args>
1792
+ data_;
1793
+
1794
+ friend class basic_format_args<Context>;
1795
+
1796
+ static constexpr unsigned long long desc =
1797
+ (is_packed ? detail::encode_types<Context, Args...>()
1798
+ : detail::is_unpacked_bit | num_args) |
1799
+ (num_named_args != 0
1800
+ ? static_cast<unsigned long long>(detail::has_named_args_bit)
1801
+ : 0);
1802
+
1803
+ public:
1804
+ template <typename... T>
1805
+ FMT_CONSTEXPR FMT_INLINE format_arg_store(T&... args)
1806
+ :
1807
+ #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
1808
+ basic_format_args<Context>(*this),
1809
+ #endif
1810
+ data_{detail::make_arg<is_packed, Context>(args)...} {
1811
+ if (detail::const_check(num_named_args != 0))
1812
+ detail::init_named_args(data_.named_args(), 0, 0, args...);
1813
+ }
1814
+ };
1815
+
1816
+ /**
1817
+ \rst
1818
+ Constructs a `~fmt::format_arg_store` object that contains references to
1819
+ arguments and can be implicitly converted to `~fmt::format_args`. `Context`
1820
+ can be omitted in which case it defaults to `~fmt::format_context`.
1821
+ See `~fmt::arg` for lifetime considerations.
1822
+ \endrst
1823
+ */
1824
+ // Arguments are taken by lvalue references to avoid some lifetime issues.
1825
+ template <typename Context = format_context, typename... T>
1826
+ constexpr auto make_format_args(T&... args)
1827
+ -> format_arg_store<Context, remove_cvref_t<T>...> {
1828
+ return {args...};
1829
+ }
1830
+
1831
+ /**
1832
+ \rst
1833
+ Returns a named argument to be used in a formatting function.
1834
+ It should only be used in a call to a formatting function or
1835
+ `dynamic_format_arg_store::push_back`.
1836
+
1837
+ **Example**::
1838
+
1839
+ fmt::print("Elapsed time: {s:.2f} seconds", fmt::arg("s", 1.23));
1840
+ \endrst
1841
+ */
1842
+ template <typename Char, typename T>
1843
+ inline auto arg(const Char* name, const T& arg) -> detail::named_arg<Char, T> {
1844
+ static_assert(!detail::is_named_arg<T>(), "nested named arguments");
1845
+ return {name, arg};
1846
+ }
1847
+ FMT_END_EXPORT
1848
+
1849
+ /**
1850
+ \rst
1851
+ A view of a collection of formatting arguments. To avoid lifetime issues it
1852
+ should only be used as a parameter type in type-erased functions such as
1853
+ ``vformat``::
1854
+
1855
+ void vlog(string_view format_str, format_args args); // OK
1856
+ format_args args = make_format_args(); // Error: dangling reference
1857
+ \endrst
1858
+ */
1859
+ template <typename Context> class basic_format_args {
1860
+ public:
1861
+ using size_type = int;
1862
+ using format_arg = basic_format_arg<Context>;
1863
+
1864
+ private:
1865
+ // A descriptor that contains information about formatting arguments.
1866
+ // If the number of arguments is less or equal to max_packed_args then
1867
+ // argument types are passed in the descriptor. This reduces binary code size
1868
+ // per formatting function call.
1869
+ unsigned long long desc_;
1870
+ union {
1871
+ // If is_packed() returns true then argument values are stored in values_;
1872
+ // otherwise they are stored in args_. This is done to improve cache
1873
+ // locality and reduce compiled code size since storing larger objects
1874
+ // may require more code (at least on x86-64) even if the same amount of
1875
+ // data is actually copied to stack. It saves ~10% on the bloat test.
1876
+ const detail::value<Context>* values_;
1877
+ const format_arg* args_;
1878
+ };
1879
+
1880
+ constexpr auto is_packed() const -> bool {
1881
+ return (desc_ & detail::is_unpacked_bit) == 0;
1882
+ }
1883
+ auto has_named_args() const -> bool {
1884
+ return (desc_ & detail::has_named_args_bit) != 0;
1885
+ }
1886
+
1887
+ FMT_CONSTEXPR auto type(int index) const -> detail::type {
1888
+ int shift = index * detail::packed_arg_bits;
1889
+ unsigned int mask = (1 << detail::packed_arg_bits) - 1;
1890
+ return static_cast<detail::type>((desc_ >> shift) & mask);
1891
+ }
1892
+
1893
+ constexpr FMT_INLINE basic_format_args(unsigned long long desc,
1894
+ const detail::value<Context>* values)
1895
+ : desc_(desc), values_(values) {}
1896
+ constexpr basic_format_args(unsigned long long desc, const format_arg* args)
1897
+ : desc_(desc), args_(args) {}
1898
+
1899
+ public:
1900
+ constexpr basic_format_args() : desc_(0), args_(nullptr) {}
1901
+
1902
+ /**
1903
+ \rst
1904
+ Constructs a `basic_format_args` object from `~fmt::format_arg_store`.
1905
+ \endrst
1906
+ */
1907
+ template <typename... Args>
1908
+ constexpr FMT_INLINE basic_format_args(
1909
+ const format_arg_store<Context, Args...>& store)
1910
+ : basic_format_args(format_arg_store<Context, Args...>::desc,
1911
+ store.data_.args()) {}
1912
+
1913
+ /**
1914
+ \rst
1915
+ Constructs a `basic_format_args` object from
1916
+ `~fmt::dynamic_format_arg_store`.
1917
+ \endrst
1918
+ */
1919
+ constexpr FMT_INLINE basic_format_args(
1920
+ const dynamic_format_arg_store<Context>& store)
1921
+ : basic_format_args(store.get_types(), store.data()) {}
1922
+
1923
+ /**
1924
+ \rst
1925
+ Constructs a `basic_format_args` object from a dynamic set of arguments.
1926
+ \endrst
1927
+ */
1928
+ constexpr basic_format_args(const format_arg* args, int count)
1929
+ : basic_format_args(detail::is_unpacked_bit | detail::to_unsigned(count),
1930
+ args) {}
1931
+
1932
+ /** Returns the argument with the specified id. */
1933
+ FMT_CONSTEXPR auto get(int id) const -> format_arg {
1934
+ format_arg arg;
1935
+ if (!is_packed()) {
1936
+ if (id < max_size()) arg = args_[id];
1937
+ return arg;
1938
+ }
1939
+ // [Windows #12702 - Fix fmt CodeQL issues]
1940
+ if (static_cast<unsigned>(id) >= detail::max_packed_args) return arg;
1941
+ arg.type_ = type(id);
1942
+ if (arg.type_ == detail::type::none_type) return arg;
1943
+ arg.value_ = values_[id];
1944
+ return arg;
1945
+ }
1946
+
1947
+ template <typename Char>
1948
+ auto get(basic_string_view<Char> name) const -> format_arg {
1949
+ int id = get_id(name);
1950
+ return id >= 0 ? get(id) : format_arg();
1951
+ }
1952
+
1953
+ template <typename Char>
1954
+ auto get_id(basic_string_view<Char> name) const -> int {
1955
+ if (!has_named_args()) return -1;
1956
+ const auto& named_args =
1957
+ (is_packed() ? values_[-1] : args_[-1].value_).named_args;
1958
+ for (size_t i = 0; i < named_args.size; ++i) {
1959
+ if (named_args.data[i].name == name) return named_args.data[i].id;
1960
+ }
1961
+ return -1;
1962
+ }
1963
+
1964
+ auto max_size() const -> int {
1965
+ unsigned long long max_packed = detail::max_packed_args;
1966
+ return static_cast<int>(is_packed() ? max_packed
1967
+ : desc_ & ~detail::is_unpacked_bit);
1968
+ }
1969
+ };
1970
+
1971
+ /** An alias to ``basic_format_args<format_context>``. */
1972
+ // A separate type would result in shorter symbols but break ABI compatibility
1973
+ // between clang and gcc on ARM (#1919).
1974
+ FMT_EXPORT using format_args = basic_format_args<format_context>;
1975
+
1976
+ // We cannot use enum classes as bit fields because of a gcc bug, so we put them
1977
+ // in namespaces instead (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414).
1978
+ // Additionally, if an underlying type is specified, older gcc incorrectly warns
1979
+ // that the type is too small. Both bugs are fixed in gcc 9.3.
1980
+ #if FMT_GCC_VERSION && FMT_GCC_VERSION < 903
1981
+ # define FMT_ENUM_UNDERLYING_TYPE(type)
1982
+ #else
1983
+ # define FMT_ENUM_UNDERLYING_TYPE(type) : type
1984
+ #endif
1985
+ namespace align {
1986
+ enum type FMT_ENUM_UNDERLYING_TYPE(unsigned char){none, left, right, center,
1987
+ numeric};
1988
+ }
1989
+ using align_t = align::type;
1990
+ namespace sign {
1991
+ enum type FMT_ENUM_UNDERLYING_TYPE(unsigned char){none, minus, plus, space};
1992
+ }
1993
+ using sign_t = sign::type;
1994
+
1995
+ namespace detail {
1996
+
1997
+ // Workaround an array initialization issue in gcc 4.8.
1998
+ template <typename Char> struct fill_t {
1999
+ private:
2000
+ enum { max_size = 4 };
2001
+ Char data_[max_size] = {Char(' '), Char(0), Char(0), Char(0)};
2002
+ unsigned char size_ = 1;
2003
+
2004
+ public:
2005
+ FMT_CONSTEXPR void operator=(basic_string_view<Char> s) {
2006
+ auto size = s.size();
2007
+ FMT_ASSERT(size <= max_size, "invalid fill");
2008
+ for (size_t i = 0; i < size; ++i) data_[i] = s[i];
2009
+ size_ = static_cast<unsigned char>(size);
2010
+ }
2011
+
2012
+ constexpr auto size() const -> size_t { return size_; }
2013
+ constexpr auto data() const -> const Char* { return data_; }
2014
+
2015
+ FMT_CONSTEXPR auto operator[](size_t index) -> Char& { return data_[index]; }
2016
+ FMT_CONSTEXPR auto operator[](size_t index) const -> const Char& {
2017
+ return data_[index];
2018
+ }
2019
+ };
2020
+ } // namespace detail
2021
+
2022
+ enum class presentation_type : unsigned char {
2023
+ none,
2024
+ dec, // 'd'
2025
+ oct, // 'o'
2026
+ hex_lower, // 'x'
2027
+ hex_upper, // 'X'
2028
+ bin_lower, // 'b'
2029
+ bin_upper, // 'B'
2030
+ hexfloat_lower, // 'a'
2031
+ hexfloat_upper, // 'A'
2032
+ exp_lower, // 'e'
2033
+ exp_upper, // 'E'
2034
+ fixed_lower, // 'f'
2035
+ fixed_upper, // 'F'
2036
+ general_lower, // 'g'
2037
+ general_upper, // 'G'
2038
+ chr, // 'c'
2039
+ string, // 's'
2040
+ pointer, // 'p'
2041
+ debug // '?'
2042
+ };
2043
+
2044
+ // Format specifiers for built-in and string types.
2045
+ template <typename Char = char> struct format_specs {
2046
+ int width;
2047
+ int precision;
2048
+ presentation_type type;
2049
+ align_t align : 4;
2050
+ sign_t sign : 3;
2051
+ bool alt : 1; // Alternate form ('#').
2052
+ bool localized : 1;
2053
+ detail::fill_t<Char> fill;
2054
+
2055
+ constexpr format_specs()
2056
+ : width(0),
2057
+ precision(-1),
2058
+ type(presentation_type::none),
2059
+ align(align::none),
2060
+ sign(sign::none),
2061
+ alt(false),
2062
+ localized(false) {}
2063
+ };
2064
+
2065
+ namespace detail {
2066
+
2067
+ enum class arg_id_kind { none, index, name };
2068
+
2069
+ // An argument reference.
2070
+ template <typename Char> struct arg_ref {
2071
+ FMT_CONSTEXPR arg_ref() : kind(arg_id_kind::none), val() {}
2072
+
2073
+ FMT_CONSTEXPR explicit arg_ref(int index)
2074
+ : kind(arg_id_kind::index), val(index) {}
2075
+ FMT_CONSTEXPR explicit arg_ref(basic_string_view<Char> name)
2076
+ : kind(arg_id_kind::name), val(name) {}
2077
+
2078
+ FMT_CONSTEXPR auto operator=(int idx) -> arg_ref& {
2079
+ kind = arg_id_kind::index;
2080
+ val.index = idx;
2081
+ return *this;
2082
+ }
2083
+
2084
+ arg_id_kind kind;
2085
+ union value {
2086
+ FMT_CONSTEXPR value(int idx = 0) : index(idx) {}
2087
+ FMT_CONSTEXPR value(basic_string_view<Char> n) : name(n) {}
2088
+
2089
+ int index;
2090
+ basic_string_view<Char> name;
2091
+ } val;
2092
+ };
2093
+
2094
+ // Format specifiers with width and precision resolved at formatting rather
2095
+ // than parsing time to allow reusing the same parsed specifiers with
2096
+ // different sets of arguments (precompilation of format strings).
2097
+ template <typename Char = char>
2098
+ struct dynamic_format_specs : format_specs<Char> {
2099
+ arg_ref<Char> width_ref;
2100
+ arg_ref<Char> precision_ref;
2101
+ };
2102
+
2103
+ // Converts a character to ASCII. Returns '\0' on conversion failure.
2104
+ template <typename Char, FMT_ENABLE_IF(std::is_integral<Char>::value)>
2105
+ constexpr auto to_ascii(Char c) -> char {
2106
+ return c <= 0xff ? static_cast<char>(c) : '\0';
2107
+ }
2108
+ template <typename Char, FMT_ENABLE_IF(std::is_enum<Char>::value)>
2109
+ constexpr auto to_ascii(Char c) -> char {
2110
+ return c <= 0xff ? static_cast<char>(c) : '\0';
2111
+ }
2112
+
2113
+ // Returns the number of code units in a code point or 1 on error.
2114
+ template <typename Char>
2115
+ FMT_CONSTEXPR auto code_point_length(const Char* begin) -> int {
2116
+ if (const_check(sizeof(Char) != 1)) return 1;
2117
+ auto c = static_cast<unsigned char>(*begin);
2118
+ return static_cast<int>((0x3a55000000000000ull >> (2 * (c >> 3))) & 0x3) + 1;
2119
+ }
2120
+
2121
+ // Return the result via the out param to workaround gcc bug 77539.
2122
+ template <bool IS_CONSTEXPR, typename T, typename Ptr = const T*>
2123
+ FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr& out) -> bool {
2124
+ for (out = first; out != last; ++out) {
2125
+ if (*out == value) return true;
2126
+ }
2127
+ return false;
2128
+ }
2129
+
2130
+ template <>
2131
+ inline auto find<false, char>(const char* first, const char* last, char value,
2132
+ const char*& out) -> bool {
2133
+ out = static_cast<const char*>(
2134
+ std::memchr(first, value, to_unsigned(last - first)));
2135
+ return out != nullptr;
2136
+ }
2137
+
2138
+ // Parses the range [begin, end) as an unsigned integer. This function assumes
2139
+ // that the range is non-empty and the first character is a digit.
2140
+ template <typename Char>
2141
+ FMT_CONSTEXPR auto parse_nonnegative_int(const Char*& begin, const Char* end,
2142
+ int error_value) noexcept -> int {
2143
+ FMT_ASSERT(begin != end && '0' <= *begin && *begin <= '9', "");
2144
+ unsigned value = 0, prev = 0;
2145
+ auto p = begin;
2146
+ do {
2147
+ prev = value;
2148
+ value = value * 10 + unsigned(*p - '0');
2149
+ ++p;
2150
+ } while (p != end && '0' <= *p && *p <= '9');
2151
+ auto num_digits = p - begin;
2152
+ begin = p;
2153
+ if (num_digits <= std::numeric_limits<int>::digits10)
2154
+ return static_cast<int>(value);
2155
+ // Check for overflow.
2156
+ const unsigned max = to_unsigned((std::numeric_limits<int>::max)());
2157
+ return num_digits == std::numeric_limits<int>::digits10 + 1 &&
2158
+ prev * 10ull + unsigned(p[-1] - '0') <= max
2159
+ ? static_cast<int>(value)
2160
+ : error_value;
2161
+ }
2162
+
2163
+ FMT_CONSTEXPR inline auto parse_align(char c) -> align_t {
2164
+ switch (c) {
2165
+ case '<':
2166
+ return align::left;
2167
+ case '>':
2168
+ return align::right;
2169
+ case '^':
2170
+ return align::center;
2171
+ }
2172
+ return align::none;
2173
+ }
2174
+
2175
+ template <typename Char> constexpr auto is_name_start(Char c) -> bool {
2176
+ return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_';
2177
+ }
2178
+
2179
+ template <typename Char, typename Handler>
2180
+ FMT_CONSTEXPR auto do_parse_arg_id(const Char* begin, const Char* end,
2181
+ Handler&& handler) -> const Char* {
2182
+ Char c = *begin;
2183
+ if (c >= '0' && c <= '9') {
2184
+ int index = 0;
2185
+ constexpr int max = (std::numeric_limits<int>::max)();
2186
+ if (c != '0')
2187
+ index = parse_nonnegative_int(begin, end, max);
2188
+ else
2189
+ ++begin;
2190
+ if (begin == end || (*begin != '}' && *begin != ':'))
2191
+ throw_format_error("invalid format string");
2192
+ else
2193
+ handler.on_index(index);
2194
+ return begin;
2195
+ }
2196
+ if (!is_name_start(c)) {
2197
+ throw_format_error("invalid format string");
2198
+ return begin;
2199
+ }
2200
+ auto it = begin;
2201
+ do {
2202
+ ++it;
2203
+ } while (it != end && (is_name_start(*it) || ('0' <= *it && *it <= '9')));
2204
+ handler.on_name({begin, to_unsigned(it - begin)});
2205
+ return it;
2206
+ }
2207
+
2208
+ template <typename Char, typename Handler>
2209
+ FMT_CONSTEXPR FMT_INLINE auto parse_arg_id(const Char* begin, const Char* end,
2210
+ Handler&& handler) -> const Char* {
2211
+ FMT_ASSERT(begin != end, "");
2212
+ Char c = *begin;
2213
+ if (c != '}' && c != ':') return do_parse_arg_id(begin, end, handler);
2214
+ handler.on_auto();
2215
+ return begin;
2216
+ }
2217
+
2218
+ template <typename Char> struct dynamic_spec_id_handler {
2219
+ basic_format_parse_context<Char>& ctx;
2220
+ arg_ref<Char>& ref;
2221
+
2222
+ FMT_CONSTEXPR void on_auto() {
2223
+ int id = ctx.next_arg_id();
2224
+ ref = arg_ref<Char>(id);
2225
+ ctx.check_dynamic_spec(id);
2226
+ }
2227
+ FMT_CONSTEXPR void on_index(int id) {
2228
+ ref = arg_ref<Char>(id);
2229
+ ctx.check_arg_id(id);
2230
+ ctx.check_dynamic_spec(id);
2231
+ }
2232
+ FMT_CONSTEXPR void on_name(basic_string_view<Char> id) {
2233
+ ref = arg_ref<Char>(id);
2234
+ ctx.check_arg_id(id);
2235
+ }
2236
+ };
2237
+
2238
+ // Parses [integer | "{" [arg_id] "}"].
2239
+ template <typename Char>
2240
+ FMT_CONSTEXPR auto parse_dynamic_spec(const Char* begin, const Char* end,
2241
+ int& value, arg_ref<Char>& ref,
2242
+ basic_format_parse_context<Char>& ctx)
2243
+ -> const Char* {
2244
+ FMT_ASSERT(begin != end, "");
2245
+ if ('0' <= *begin && *begin <= '9') {
2246
+ int val = parse_nonnegative_int(begin, end, -1);
2247
+ if (val != -1)
2248
+ value = val;
2249
+ else
2250
+ throw_format_error("number is too big");
2251
+ } else if (*begin == '{') {
2252
+ ++begin;
2253
+ auto handler = dynamic_spec_id_handler<Char>{ctx, ref};
2254
+ if (begin != end) begin = parse_arg_id(begin, end, handler);
2255
+ if (begin != end && *begin == '}') return ++begin;
2256
+ throw_format_error("invalid format string");
2257
+ }
2258
+ return begin;
2259
+ }
2260
+
2261
+ template <typename Char>
2262
+ FMT_CONSTEXPR auto parse_precision(const Char* begin, const Char* end,
2263
+ int& value, arg_ref<Char>& ref,
2264
+ basic_format_parse_context<Char>& ctx)
2265
+ -> const Char* {
2266
+ ++begin;
2267
+ if (begin == end || *begin == '}') {
2268
+ throw_format_error("invalid precision");
2269
+ return begin;
2270
+ }
2271
+ return parse_dynamic_spec(begin, end, value, ref, ctx);
2272
+ }
2273
+
2274
+ enum class state { start, align, sign, hash, zero, width, precision, locale };
2275
+
2276
+ // Parses standard format specifiers.
2277
+ template <typename Char>
2278
+ FMT_CONSTEXPR FMT_INLINE auto parse_format_specs(
2279
+ const Char* begin, const Char* end, dynamic_format_specs<Char>& specs,
2280
+ basic_format_parse_context<Char>& ctx, type arg_type) -> const Char* {
2281
+ auto c = '\0';
2282
+ if (end - begin > 1) {
2283
+ auto next = to_ascii(begin[1]);
2284
+ c = parse_align(next) == align::none ? to_ascii(*begin) : '\0';
2285
+ } else {
2286
+ if (begin == end) return begin;
2287
+ c = to_ascii(*begin);
2288
+ }
2289
+
2290
+ struct {
2291
+ state current_state = state::start;
2292
+ FMT_CONSTEXPR void operator()(state s, bool valid = true) {
2293
+ if (current_state >= s || !valid)
2294
+ throw_format_error("invalid format specifier");
2295
+ current_state = s;
2296
+ }
2297
+ } enter_state;
2298
+
2299
+ using pres = presentation_type;
2300
+ constexpr auto integral_set = sint_set | uint_set | bool_set | char_set;
2301
+ struct {
2302
+ const Char*& begin;
2303
+ dynamic_format_specs<Char>& specs;
2304
+ type arg_type;
2305
+
2306
+ FMT_CONSTEXPR auto operator()(pres type, int set) -> const Char* {
2307
+ if (!in(arg_type, set)) throw_format_error("invalid format specifier");
2308
+ specs.type = type;
2309
+ return begin + 1;
2310
+ }
2311
+ } parse_presentation_type{begin, specs, arg_type};
2312
+
2313
+ for (;;) {
2314
+ switch (c) {
2315
+ case '<':
2316
+ case '>':
2317
+ case '^':
2318
+ enter_state(state::align);
2319
+ specs.align = parse_align(c);
2320
+ ++begin;
2321
+ break;
2322
+ case '+':
2323
+ case '-':
2324
+ case ' ':
2325
+ enter_state(state::sign, in(arg_type, sint_set | float_set));
2326
+ switch (c) {
2327
+ case '+':
2328
+ specs.sign = sign::plus;
2329
+ break;
2330
+ case '-':
2331
+ specs.sign = sign::minus;
2332
+ break;
2333
+ case ' ':
2334
+ specs.sign = sign::space;
2335
+ break;
2336
+ }
2337
+ ++begin;
2338
+ break;
2339
+ case '#':
2340
+ enter_state(state::hash, is_arithmetic_type(arg_type));
2341
+ specs.alt = true;
2342
+ ++begin;
2343
+ break;
2344
+ case '0':
2345
+ enter_state(state::zero);
2346
+ if (!is_arithmetic_type(arg_type))
2347
+ throw_format_error("format specifier requires numeric argument");
2348
+ if (specs.align == align::none) {
2349
+ // Ignore 0 if align is specified for compatibility with std::format.
2350
+ specs.align = align::numeric;
2351
+ specs.fill[0] = Char('0');
2352
+ }
2353
+ ++begin;
2354
+ break;
2355
+ case '1':
2356
+ case '2':
2357
+ case '3':
2358
+ case '4':
2359
+ case '5':
2360
+ case '6':
2361
+ case '7':
2362
+ case '8':
2363
+ case '9':
2364
+ case '{':
2365
+ enter_state(state::width);
2366
+ begin = parse_dynamic_spec(begin, end, specs.width, specs.width_ref, ctx);
2367
+ break;
2368
+ case '.':
2369
+ enter_state(state::precision,
2370
+ in(arg_type, float_set | string_set | cstring_set));
2371
+ begin = parse_precision(begin, end, specs.precision, specs.precision_ref,
2372
+ ctx);
2373
+ break;
2374
+ case 'L':
2375
+ enter_state(state::locale, is_arithmetic_type(arg_type));
2376
+ specs.localized = true;
2377
+ ++begin;
2378
+ break;
2379
+ case 'd':
2380
+ return parse_presentation_type(pres::dec, integral_set);
2381
+ case 'o':
2382
+ return parse_presentation_type(pres::oct, integral_set);
2383
+ case 'x':
2384
+ return parse_presentation_type(pres::hex_lower, integral_set);
2385
+ case 'X':
2386
+ return parse_presentation_type(pres::hex_upper, integral_set);
2387
+ case 'b':
2388
+ return parse_presentation_type(pres::bin_lower, integral_set);
2389
+ case 'B':
2390
+ return parse_presentation_type(pres::bin_upper, integral_set);
2391
+ case 'a':
2392
+ return parse_presentation_type(pres::hexfloat_lower, float_set);
2393
+ case 'A':
2394
+ return parse_presentation_type(pres::hexfloat_upper, float_set);
2395
+ case 'e':
2396
+ return parse_presentation_type(pres::exp_lower, float_set);
2397
+ case 'E':
2398
+ return parse_presentation_type(pres::exp_upper, float_set);
2399
+ case 'f':
2400
+ return parse_presentation_type(pres::fixed_lower, float_set);
2401
+ case 'F':
2402
+ return parse_presentation_type(pres::fixed_upper, float_set);
2403
+ case 'g':
2404
+ return parse_presentation_type(pres::general_lower, float_set);
2405
+ case 'G':
2406
+ return parse_presentation_type(pres::general_upper, float_set);
2407
+ case 'c':
2408
+ return parse_presentation_type(pres::chr, integral_set);
2409
+ case 's':
2410
+ return parse_presentation_type(pres::string,
2411
+ bool_set | string_set | cstring_set);
2412
+ case 'p':
2413
+ return parse_presentation_type(pres::pointer, pointer_set | cstring_set);
2414
+ case '?':
2415
+ return parse_presentation_type(pres::debug,
2416
+ char_set | string_set | cstring_set);
2417
+ case '}':
2418
+ return begin;
2419
+ default: {
2420
+ if (*begin == '}') return begin;
2421
+ // Parse fill and alignment.
2422
+ auto fill_end = begin + code_point_length(begin);
2423
+ if (end - fill_end <= 0) {
2424
+ throw_format_error("invalid format specifier");
2425
+ return begin;
2426
+ }
2427
+ if (*begin == '{') {
2428
+ throw_format_error("invalid fill character '{'");
2429
+ return begin;
2430
+ }
2431
+ auto align = parse_align(to_ascii(*fill_end));
2432
+ enter_state(state::align, align != align::none);
2433
+ specs.fill = {begin, to_unsigned(fill_end - begin)};
2434
+ specs.align = align;
2435
+ begin = fill_end + 1;
2436
+ }
2437
+ }
2438
+ if (begin == end) return begin;
2439
+ c = to_ascii(*begin);
2440
+ }
2441
+ }
2442
+
2443
+ template <typename Char, typename Handler>
2444
+ FMT_CONSTEXPR auto parse_replacement_field(const Char* begin, const Char* end,
2445
+ Handler&& handler) -> const Char* {
2446
+ struct id_adapter {
2447
+ Handler& handler;
2448
+ int arg_id;
2449
+
2450
+ FMT_CONSTEXPR void on_auto() { arg_id = handler.on_arg_id(); }
2451
+ FMT_CONSTEXPR void on_index(int id) { arg_id = handler.on_arg_id(id); }
2452
+ FMT_CONSTEXPR void on_name(basic_string_view<Char> id) {
2453
+ arg_id = handler.on_arg_id(id);
2454
+ }
2455
+ };
2456
+
2457
+ ++begin;
2458
+ if (begin == end) return handler.on_error("invalid format string"), end;
2459
+ if (*begin == '}') {
2460
+ handler.on_replacement_field(handler.on_arg_id(), begin);
2461
+ } else if (*begin == '{') {
2462
+ handler.on_text(begin, begin + 1);
2463
+ } else {
2464
+ auto adapter = id_adapter{handler, 0};
2465
+ begin = parse_arg_id(begin, end, adapter);
2466
+ Char c = begin != end ? *begin : Char();
2467
+ if (c == '}') {
2468
+ handler.on_replacement_field(adapter.arg_id, begin);
2469
+ } else if (c == ':') {
2470
+ begin = handler.on_format_specs(adapter.arg_id, begin + 1, end);
2471
+ if (begin == end || *begin != '}')
2472
+ return handler.on_error("unknown format specifier"), end;
2473
+ } else {
2474
+ return handler.on_error("missing '}' in format string"), end;
2475
+ }
2476
+ }
2477
+ return begin + 1;
2478
+ }
2479
+
2480
+ template <bool IS_CONSTEXPR, typename Char, typename Handler>
2481
+ FMT_CONSTEXPR FMT_INLINE void parse_format_string(
2482
+ basic_string_view<Char> format_str, Handler&& handler) {
2483
+ auto begin = format_str.data();
2484
+ auto end = begin + format_str.size();
2485
+ if (end - begin < 32) {
2486
+ // Use a simple loop instead of memchr for small strings.
2487
+ const Char* p = begin;
2488
+ while (p != end) {
2489
+ auto c = *p++;
2490
+ if (c == '{') {
2491
+ handler.on_text(begin, p - 1);
2492
+ begin = p = parse_replacement_field(p - 1, end, handler);
2493
+ } else if (c == '}') {
2494
+ if (p == end || *p != '}')
2495
+ return handler.on_error("unmatched '}' in format string");
2496
+ handler.on_text(begin, p);
2497
+ begin = ++p;
2498
+ }
2499
+ }
2500
+ handler.on_text(begin, end);
2501
+ return;
2502
+ }
2503
+ struct writer {
2504
+ FMT_CONSTEXPR void operator()(const Char* from, const Char* to) {
2505
+ if (from == to) return;
2506
+ for (;;) {
2507
+ const Char* p = nullptr;
2508
+ if (!find<IS_CONSTEXPR>(from, to, Char('}'), p))
2509
+ return handler_.on_text(from, to);
2510
+ ++p;
2511
+ if (p == to || *p != '}')
2512
+ return handler_.on_error("unmatched '}' in format string");
2513
+ handler_.on_text(from, p);
2514
+ from = p + 1;
2515
+ }
2516
+ }
2517
+ Handler& handler_;
2518
+ } write = {handler};
2519
+ while (begin != end) {
2520
+ // Doing two passes with memchr (one for '{' and another for '}') is up to
2521
+ // 2.5x faster than the naive one-pass implementation on big format strings.
2522
+ const Char* p = begin;
2523
+ if (*begin != '{' && !find<IS_CONSTEXPR>(begin + 1, end, Char('{'), p))
2524
+ return write(begin, end);
2525
+ write(begin, p);
2526
+ begin = parse_replacement_field(p, end, handler);
2527
+ }
2528
+ }
2529
+
2530
+ template <typename T, bool = is_named_arg<T>::value> struct strip_named_arg {
2531
+ using type = T;
2532
+ };
2533
+ template <typename T> struct strip_named_arg<T, true> {
2534
+ using type = remove_cvref_t<decltype(T::value)>;
2535
+ };
2536
+
2537
+ template <typename T, typename ParseContext>
2538
+ FMT_CONSTEXPR auto parse_format_specs(ParseContext& ctx)
2539
+ -> decltype(ctx.begin()) {
2540
+ using char_type = typename ParseContext::char_type;
2541
+ using context = buffer_context<char_type>;
2542
+ using mapped_type = conditional_t<
2543
+ mapped_type_constant<T, context>::value != type::custom_type,
2544
+ decltype(arg_mapper<context>().map(std::declval<const T&>())),
2545
+ typename strip_named_arg<T>::type>;
2546
+ #if defined(__cpp_if_constexpr)
2547
+ if constexpr (std::is_default_constructible_v<
2548
+ formatter<mapped_type, char_type>>) {
2549
+ return formatter<mapped_type, char_type>().parse(ctx);
2550
+ } else {
2551
+ type_is_unformattable_for<T, char_type> _;
2552
+ return ctx.begin();
2553
+ }
2554
+ #else
2555
+ return formatter<mapped_type, char_type>().parse(ctx);
2556
+ #endif
2557
+ }
2558
+
2559
+ // Checks char specs and returns true iff the presentation type is char-like.
2560
+ template <typename Char>
2561
+ FMT_CONSTEXPR auto check_char_specs(const format_specs<Char>& specs) -> bool {
2562
+ if (specs.type != presentation_type::none &&
2563
+ specs.type != presentation_type::chr &&
2564
+ specs.type != presentation_type::debug) {
2565
+ return false;
2566
+ }
2567
+ if (specs.align == align::numeric || specs.sign != sign::none || specs.alt)
2568
+ throw_format_error("invalid format specifier for char");
2569
+ return true;
2570
+ }
2571
+
2572
+ #if FMT_USE_NONTYPE_TEMPLATE_ARGS
2573
+ template <int N, typename T, typename... Args, typename Char>
2574
+ constexpr auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
2575
+ if constexpr (is_statically_named_arg<T>()) {
2576
+ if (name == T::name) return N;
2577
+ }
2578
+ if constexpr (sizeof...(Args) > 0)
2579
+ return get_arg_index_by_name<N + 1, Args...>(name);
2580
+ (void)name; // Workaround an MSVC bug about "unused" parameter.
2581
+ return -1;
2582
+ }
2583
+ #endif
2584
+
2585
+ template <typename... Args, typename Char>
2586
+ FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view<Char> name) -> int {
2587
+ #if FMT_USE_NONTYPE_TEMPLATE_ARGS
2588
+ if constexpr (sizeof...(Args) > 0)
2589
+ return get_arg_index_by_name<0, Args...>(name);
2590
+ #endif
2591
+ (void)name;
2592
+ return -1;
2593
+ }
2594
+
2595
+ template <typename Char, typename... Args> class format_string_checker {
2596
+ private:
2597
+ using parse_context_type = compile_parse_context<Char>;
2598
+ static constexpr int num_args = sizeof...(Args);
2599
+
2600
+ // Format specifier parsing function.
2601
+ // In the future basic_format_parse_context will replace compile_parse_context
2602
+ // here and will use is_constant_evaluated and downcasting to access the data
2603
+ // needed for compile-time checks: https://godbolt.org/z/GvWzcTjh1.
2604
+ using parse_func = const Char* (*)(parse_context_type&);
2605
+
2606
+ type types_[num_args > 0 ? static_cast<size_t>(num_args) : 1];
2607
+ parse_context_type context_;
2608
+ parse_func parse_funcs_[num_args > 0 ? static_cast<size_t>(num_args) : 1];
2609
+
2610
+ public:
2611
+ explicit FMT_CONSTEXPR format_string_checker(basic_string_view<Char> fmt)
2612
+ : types_{mapped_type_constant<Args, buffer_context<Char>>::value...},
2613
+ context_(fmt, num_args, types_),
2614
+ parse_funcs_{&parse_format_specs<Args, parse_context_type>...} {}
2615
+
2616
+ FMT_CONSTEXPR void on_text(const Char*, const Char*) {}
2617
+
2618
+ FMT_CONSTEXPR auto on_arg_id() -> int { return context_.next_arg_id(); }
2619
+ FMT_CONSTEXPR auto on_arg_id(int id) -> int {
2620
+ return context_.check_arg_id(id), id;
2621
+ }
2622
+ FMT_CONSTEXPR auto on_arg_id(basic_string_view<Char> id) -> int {
2623
+ #if FMT_USE_NONTYPE_TEMPLATE_ARGS
2624
+ auto index = get_arg_index_by_name<Args...>(id);
2625
+ if (index < 0) on_error("named argument is not found");
2626
+ return index;
2627
+ #else
2628
+ (void)id;
2629
+ on_error("compile-time checks for named arguments require C++20 support");
2630
+ return 0;
2631
+ #endif
2632
+ }
2633
+
2634
+ FMT_CONSTEXPR void on_replacement_field(int id, const Char* begin) {
2635
+ on_format_specs(id, begin, begin); // Call parse() on empty specs.
2636
+ }
2637
+
2638
+ FMT_CONSTEXPR auto on_format_specs(int id, const Char* begin, const Char*)
2639
+ -> const Char* {
2640
+ context_.advance_to(begin);
2641
+ // id >= 0 check is a workaround for gcc 10 bug (#2065).
2642
+ return id >= 0 && id < num_args ? parse_funcs_[id](context_) : begin;
2643
+ }
2644
+
2645
+ FMT_CONSTEXPR void on_error(const char* message) {
2646
+ throw_format_error(message);
2647
+ }
2648
+ };
2649
+
2650
+ // Reports a compile-time error if S is not a valid format string.
2651
+ template <typename..., typename S, FMT_ENABLE_IF(!is_compile_string<S>::value)>
2652
+ FMT_INLINE void check_format_string(const S&) {
2653
+ #ifdef FMT_ENFORCE_COMPILE_STRING
2654
+ static_assert(is_compile_string<S>::value,
2655
+ "FMT_ENFORCE_COMPILE_STRING requires all format strings to use "
2656
+ "FMT_STRING.");
2657
+ #endif
2658
+ }
2659
+ template <typename... Args, typename S,
2660
+ FMT_ENABLE_IF(is_compile_string<S>::value)>
2661
+ void check_format_string(S format_str) {
2662
+ using char_t = typename S::char_type;
2663
+ FMT_CONSTEXPR auto s = basic_string_view<char_t>(format_str);
2664
+ using checker = format_string_checker<char_t, remove_cvref_t<Args>...>;
2665
+ FMT_CONSTEXPR bool error = (parse_format_string<true>(s, checker(s)), true);
2666
+ ignore_unused(error);
2667
+ }
2668
+
2669
+ template <typename Char = char> struct vformat_args {
2670
+ using type = basic_format_args<
2671
+ basic_format_context<std::back_insert_iterator<buffer<Char>>, Char>>;
2672
+ };
2673
+ template <> struct vformat_args<char> { using type = format_args; };
2674
+
2675
+ // Use vformat_args and avoid type_identity to keep symbols short.
2676
+ template <typename Char>
2677
+ void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
2678
+ typename vformat_args<Char>::type args, locale_ref loc = {});
2679
+
2680
+ FMT_API void vprint_mojibake(std::FILE*, string_view, format_args);
2681
+ #ifndef _WIN32
2682
+ inline void vprint_mojibake(std::FILE*, string_view, format_args) {}
2683
+ #endif
2684
+ } // namespace detail
2685
+
2686
+ FMT_BEGIN_EXPORT
2687
+
2688
+ // A formatter specialization for natively supported types.
2689
+ template <typename T, typename Char>
2690
+ struct formatter<T, Char,
2691
+ enable_if_t<detail::type_constant<T, Char>::value !=
2692
+ detail::type::custom_type>> {
2693
+ private:
2694
+ detail::dynamic_format_specs<Char> specs_;
2695
+
2696
+ public:
2697
+ template <typename ParseContext>
2698
+ FMT_CONSTEXPR auto parse(ParseContext& ctx) -> const Char* {
2699
+ auto type = detail::type_constant<T, Char>::value;
2700
+ auto end =
2701
+ detail::parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, type);
2702
+ if (type == detail::type::char_type) detail::check_char_specs(specs_);
2703
+ return end;
2704
+ }
2705
+
2706
+ template <detail::type U = detail::type_constant<T, Char>::value,
2707
+ FMT_ENABLE_IF(U == detail::type::string_type ||
2708
+ U == detail::type::cstring_type ||
2709
+ U == detail::type::char_type)>
2710
+ FMT_CONSTEXPR void set_debug_format(bool set = true) {
2711
+ specs_.type = set ? presentation_type::debug : presentation_type::none;
2712
+ }
2713
+
2714
+ template <typename FormatContext>
2715
+ FMT_CONSTEXPR auto format(const T& val, FormatContext& ctx) const
2716
+ -> decltype(ctx.out());
2717
+ };
2718
+
2719
+ template <typename Char = char> struct runtime_format_string {
2720
+ basic_string_view<Char> str;
2721
+ };
2722
+
2723
+ /** A compile-time format string. */
2724
+ template <typename Char, typename... Args> class basic_format_string {
2725
+ private:
2726
+ basic_string_view<Char> str_;
2727
+
2728
+ public:
2729
+ template <typename S,
2730
+ FMT_ENABLE_IF(
2731
+ std::is_convertible<const S&, basic_string_view<Char>>::value)>
2732
+ FMT_CONSTEVAL FMT_INLINE basic_format_string(const S& s) : str_(s) {
2733
+ static_assert(
2734
+ detail::count<
2735
+ (std::is_base_of<detail::view, remove_reference_t<Args>>::value &&
2736
+ std::is_reference<Args>::value)...>() == 0,
2737
+ "passing views as lvalues is disallowed");
2738
+ #ifdef FMT_HAS_CONSTEVAL
2739
+ if constexpr (detail::count_named_args<Args...>() ==
2740
+ detail::count_statically_named_args<Args...>()) {
2741
+ using checker =
2742
+ detail::format_string_checker<Char, remove_cvref_t<Args>...>;
2743
+ detail::parse_format_string<true>(str_, checker(s));
2744
+ }
2745
+ #else
2746
+ detail::check_format_string<Args...>(s);
2747
+ #endif
2748
+ }
2749
+ basic_format_string(runtime_format_string<Char> fmt) : str_(fmt.str) {}
2750
+
2751
+ FMT_INLINE operator basic_string_view<Char>() const { return str_; }
2752
+ FMT_INLINE auto get() const -> basic_string_view<Char> { return str_; }
2753
+ };
2754
+
2755
+ #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409
2756
+ // Workaround broken conversion on older gcc.
2757
+ template <typename...> using format_string = string_view;
2758
+ inline auto runtime(string_view s) -> string_view { return s; }
2759
+ #else
2760
+ template <typename... Args>
2761
+ using format_string = basic_format_string<char, type_identity_t<Args>...>;
2762
+ /**
2763
+ \rst
2764
+ Creates a runtime format string.
2765
+
2766
+ **Example**::
2767
+
2768
+ // Check format string at runtime instead of compile-time.
2769
+ fmt::print(fmt::runtime("{:d}"), "I am not a number");
2770
+ \endrst
2771
+ */
2772
+ inline auto runtime(string_view s) -> runtime_format_string<> { return {{s}}; }
2773
+ #endif
2774
+
2775
+ FMT_API auto vformat(string_view fmt, format_args args) -> std::string;
2776
+
2777
+ /**
2778
+ \rst
2779
+ Formats ``args`` according to specifications in ``fmt`` and returns the result
2780
+ as a string.
2781
+
2782
+ **Example**::
2783
+
2784
+ #include <fmt/core.h>
2785
+ std::string message = fmt::format("The answer is {}.", 42);
2786
+ \endrst
2787
+ */
2788
+ template <typename... T>
2789
+ FMT_NODISCARD FMT_INLINE auto format(format_string<T...> fmt, T&&... args)
2790
+ -> std::string {
2791
+ return vformat(fmt, fmt::make_format_args(args...));
2792
+ }
2793
+
2794
+ /** Formats a string and writes the output to ``out``. */
2795
+ template <typename OutputIt,
2796
+ FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
2797
+ auto vformat_to(OutputIt out, string_view fmt, format_args args) -> OutputIt {
2798
+ auto&& buf = detail::get_buffer<char>(out);
2799
+ detail::vformat_to(buf, fmt, args, {});
2800
+ return detail::get_iterator(buf, out);
2801
+ }
2802
+
2803
+ /**
2804
+ \rst
2805
+ Formats ``args`` according to specifications in ``fmt``, writes the result to
2806
+ the output iterator ``out`` and returns the iterator past the end of the output
2807
+ range. `format_to` does not append a terminating null character.
2808
+
2809
+ **Example**::
2810
+
2811
+ auto out = std::vector<char>();
2812
+ fmt::format_to(std::back_inserter(out), "{}", 42);
2813
+ \endrst
2814
+ */
2815
+ template <typename OutputIt, typename... T,
2816
+ FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
2817
+ FMT_INLINE auto format_to(OutputIt out, format_string<T...> fmt, T&&... args)
2818
+ -> OutputIt {
2819
+ return vformat_to(out, fmt, fmt::make_format_args(args...));
2820
+ }
2821
+
2822
+ template <typename OutputIt> struct format_to_n_result {
2823
+ /** Iterator past the end of the output range. */
2824
+ OutputIt out;
2825
+ /** Total (not truncated) output size. */
2826
+ size_t size;
2827
+ };
2828
+
2829
+ template <typename OutputIt, typename... T,
2830
+ FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
2831
+ auto vformat_to_n(OutputIt out, size_t n, string_view fmt, format_args args)
2832
+ -> format_to_n_result<OutputIt> {
2833
+ using traits = detail::fixed_buffer_traits;
2834
+ auto buf = detail::iterator_buffer<OutputIt, char, traits>(out, n);
2835
+ detail::vformat_to(buf, fmt, args, {});
2836
+ return {buf.out(), buf.count()};
2837
+ }
2838
+
2839
+ /**
2840
+ \rst
2841
+ Formats ``args`` according to specifications in ``fmt``, writes up to ``n``
2842
+ characters of the result to the output iterator ``out`` and returns the total
2843
+ (not truncated) output size and the iterator past the end of the output range.
2844
+ `format_to_n` does not append a terminating null character.
2845
+ \endrst
2846
+ */
2847
+ template <typename OutputIt, typename... T,
2848
+ FMT_ENABLE_IF(detail::is_output_iterator<OutputIt, char>::value)>
2849
+ FMT_INLINE auto format_to_n(OutputIt out, size_t n, format_string<T...> fmt,
2850
+ T&&... args) -> format_to_n_result<OutputIt> {
2851
+ return vformat_to_n(out, n, fmt, fmt::make_format_args(args...));
2852
+ }
2853
+
2854
+ /** Returns the number of chars in the output of ``format(fmt, args...)``. */
2855
+ template <typename... T>
2856
+ FMT_NODISCARD FMT_INLINE auto formatted_size(format_string<T...> fmt,
2857
+ T&&... args) -> size_t {
2858
+ auto buf = detail::counting_buffer<>();
2859
+ detail::vformat_to<char>(buf, fmt, fmt::make_format_args(args...), {});
2860
+ return buf.count();
2861
+ }
2862
+
2863
+ FMT_API void vprint(string_view fmt, format_args args);
2864
+ FMT_API void vprint(std::FILE* f, string_view fmt, format_args args);
2865
+
2866
+ /**
2867
+ \rst
2868
+ Formats ``args`` according to specifications in ``fmt`` and writes the output
2869
+ to ``stdout``.
2870
+
2871
+ **Example**::
2872
+
2873
+ fmt::print("Elapsed time: {0:.2f} seconds", 1.23);
2874
+ \endrst
2875
+ */
2876
+ template <typename... T>
2877
+ FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
2878
+ const auto& vargs = fmt::make_format_args(args...);
2879
+ return detail::is_utf8() ? vprint(fmt, vargs)
2880
+ : detail::vprint_mojibake(stdout, fmt, vargs);
2881
+ }
2882
+
2883
+ /**
2884
+ \rst
2885
+ Formats ``args`` according to specifications in ``fmt`` and writes the
2886
+ output to the file ``f``.
2887
+
2888
+ **Example**::
2889
+
2890
+ fmt::print(stderr, "Don't {}!", "panic");
2891
+ \endrst
2892
+ */
2893
+ template <typename... T>
2894
+ FMT_INLINE void print(std::FILE* f, format_string<T...> fmt, T&&... args) {
2895
+ const auto& vargs = fmt::make_format_args(args...);
2896
+ return detail::is_utf8() ? vprint(f, fmt, vargs)
2897
+ : detail::vprint_mojibake(f, fmt, vargs);
2898
+ }
2899
+
2900
+ /**
2901
+ Formats ``args`` according to specifications in ``fmt`` and writes the
2902
+ output to the file ``f`` followed by a newline.
2903
+ */
2904
+ template <typename... T>
2905
+ FMT_INLINE void println(std::FILE* f, format_string<T...> fmt, T&&... args) {
2906
+ return fmt::print(f, "{}\n", fmt::format(fmt, std::forward<T>(args)...));
2907
+ }
2908
+
2909
+ /**
2910
+ Formats ``args`` according to specifications in ``fmt`` and writes the output
2911
+ to ``stdout`` followed by a newline.
2912
+ */
2913
+ template <typename... T>
2914
+ FMT_INLINE void println(format_string<T...> fmt, T&&... args) {
2915
+ return fmt::println(stdout, fmt, std::forward<T>(args)...);
2916
+ }
2917
+
2918
+ FMT_END_EXPORT
2919
+ FMT_GCC_PRAGMA("GCC pop_options")
2920
+ FMT_END_NAMESPACE
2921
+
2922
+ #ifdef FMT_HEADER_ONLY
2923
+ # include "format.h"
2924
+ #endif
2925
+ #endif // FMT_CORE_H_