ranger-compiler 2.1.69 → 3.0.3

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 (363) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +991 -96
  3. package/{compiler/Lang.clj → dist/Lang.rgr} +2345 -75
  4. package/dist/README.md +116 -0
  5. package/dist/{bin/api.d.ts → api.d.ts} +430 -154
  6. package/dist/api.js +34345 -0
  7. package/{lib/Ajax.clj → dist/lib/Ajax.rgr} +1 -1
  8. package/{lib/CmdParams.clj → dist/lib/CmdParams.rgr} +72 -72
  9. package/{lib/Crypto.clj → dist/lib/Crypto.rgr} +1 -1
  10. package/{lib/DOMLib.clj → dist/lib/DOMLib.rgr} +2 -2
  11. package/{lib/Engine3D.clj → dist/lib/Engine3D.rgr} +1 -1
  12. package/{lib/ImmutableVector.clj → dist/lib/ImmutableVector.rgr} +364 -364
  13. package/{lib/IndexedDB.clj → dist/lib/IndexedDB.rgr} +1 -1
  14. package/{lib/JSON.clj → dist/lib/JSON.rgr} +105 -2
  15. package/{lib/JinxProcess.clj → dist/lib/JinxProcess.rgr} +3 -3
  16. package/{lib/Storage.clj → dist/lib/Storage.rgr} +1 -1
  17. package/{lib/Timers.clj → dist/lib/Timers.rgr} +176 -170
  18. package/{lib/ViewLib.clj → dist/lib/ViewLib.rgr} +1 -1
  19. package/dist/lib/lib/ACEEditor.rgr +5 -0
  20. package/dist/lib/lib/Ajax.rgr +196 -0
  21. package/dist/lib/lib/CmdParams.rgr +72 -0
  22. package/dist/lib/lib/Crypto.rgr +90 -0
  23. package/dist/lib/lib/DOMLib.rgr +307 -0
  24. package/{examples/3D/Engine3D.clj → dist/lib/lib/Engine3D.rgr} +870 -857
  25. package/dist/lib/lib/ImmutableVector.rgr +364 -0
  26. package/dist/lib/lib/IndexedDB.rgr +32 -0
  27. package/{compiler/JSON.clj → dist/lib/lib/JSON.rgr} +106 -3
  28. package/dist/lib/lib/JinxProcess.rgr +838 -0
  29. package/dist/lib/lib/SQL.rgr +44 -0
  30. package/dist/lib/lib/ServiceLib.rgr +9 -0
  31. package/dist/lib/lib/Storage.rgr +89 -0
  32. package/dist/lib/lib/Time.rgr +75 -0
  33. package/dist/lib/lib/Timers.rgr +176 -0
  34. package/dist/lib/lib/TypedArrays.rgr +14 -0
  35. package/dist/lib/lib/ViewLib.rgr +851 -0
  36. package/dist/lib/lib/WebLib.rgr +47 -0
  37. package/dist/lib/lib/WebServerLib.rgr +137 -0
  38. package/{lib/ranger-dir.clj → dist/lib/lib/ranger-dir.rgr} +1 -1
  39. package/{compiler/stdlib.clj → dist/lib/lib/stdlib.rgr} +42 -19
  40. package/{lib/stdops.clj → dist/lib/lib/stdops.rgr} +1 -1
  41. package/dist/lib/ranger-dir.rgr +175 -0
  42. package/{lib/stdlib.clj → dist/lib/stdlib.rgr} +2 -2
  43. package/dist/lib/stdops.rgr +168 -0
  44. package/dist/package.json +47 -0
  45. package/{bin/output.js → dist/rgrc.js} +15377 -7935
  46. package/dist/stdops.rgr +168 -0
  47. package/package.json +196 -38
  48. package/adventofcode/day1/bin/LambdaSignature1.java +0 -3
  49. package/adventofcode/day1/bin/LambdaSignature2.java +0 -3
  50. package/adventofcode/day1/bin/LambdaSignature3.java +0 -3
  51. package/adventofcode/day1/bin/day1.cpp +0 -124
  52. package/adventofcode/day1/bin/day1.go +0 -75
  53. package/adventofcode/day1/bin/day1.js +0 -45
  54. package/adventofcode/day1/bin/day1.php +0 -46
  55. package/adventofcode/day1/bin/day1.scala +0 -48
  56. package/adventofcode/day1/bin/day1.swift +0 -48
  57. package/adventofcode/day1/bin/day1_part2.cpp +0 -180
  58. package/adventofcode/day1/bin/day1_part2.go +0 -123
  59. package/adventofcode/day1/bin/day1_part2.js +0 -76
  60. package/adventofcode/day1/bin/day1_part2.php +0 -88
  61. package/adventofcode/day1/bin/day1_part2.scala +0 -81
  62. package/adventofcode/day1/bin/day1_part2.swift +0 -91
  63. package/adventofcode/day1/bin/day_one.java +0 -38
  64. package/adventofcode/day1/bin/day_one_part_two.java +0 -57
  65. package/adventofcode/day1/bin/operatorsOf.java +0 -37
  66. package/adventofcode/day1/bin/operatorsOf_5.java +0 -10
  67. package/adventofcode/day1/bin/operatorsOfboolean_5.java +0 -10
  68. package/adventofcode/day1/bin/variant.hpp +0 -2416
  69. package/adventofcode/day1/compile.bat +0 -7
  70. package/adventofcode/day1/compile2.bat +0 -7
  71. package/adventofcode/day1/day1.clj +0 -19
  72. package/adventofcode/day1/day1_part2.clj +0 -43
  73. package/adventofcode/day1/input1.txt +0 -1
  74. package/adventofcode/day2/bin/LambdaSignature1.class +0 -0
  75. package/adventofcode/day2/bin/LambdaSignature1.java +0 -3
  76. package/adventofcode/day2/bin/LambdaSignature2.class +0 -0
  77. package/adventofcode/day2/bin/LambdaSignature2.java +0 -3
  78. package/adventofcode/day2/bin/day2.cpp +0 -133
  79. package/adventofcode/day2/bin/day2.go +0 -85
  80. package/adventofcode/day2/bin/day2.js +0 -45
  81. package/adventofcode/day2/bin/day2.php +0 -59
  82. package/adventofcode/day2/bin/day2.scala +0 -54
  83. package/adventofcode/day2/bin/day2.swift +0 -62
  84. package/adventofcode/day2/bin/day2_part2.cpp +0 -150
  85. package/adventofcode/day2/bin/day2_part2.go +0 -101
  86. package/adventofcode/day2/bin/day2_part2.js +0 -54
  87. package/adventofcode/day2/bin/day2_part2.php +0 -80
  88. package/adventofcode/day2/bin/day2_part2.scala +0 -68
  89. package/adventofcode/day2/bin/day2_part2.swift +0 -82
  90. package/adventofcode/day2/bin/day_two.java +0 -61
  91. package/adventofcode/day2/bin/day_two_part_two$1$1$1.class +0 -0
  92. package/adventofcode/day2/bin/day_two_part_two$1$1.class +0 -0
  93. package/adventofcode/day2/bin/day_two_part_two$1.class +0 -0
  94. package/adventofcode/day2/bin/day_two_part_two.class +0 -0
  95. package/adventofcode/day2/bin/day_two_part_two.java +0 -80
  96. package/adventofcode/day2/bin/operatorsOf.class +0 -0
  97. package/adventofcode/day2/bin/operatorsOf.java +0 -18
  98. package/adventofcode/day2/bin/variant.hpp +0 -2416
  99. package/adventofcode/day2/compile.bat +0 -7
  100. package/adventofcode/day2/compile2.bat +0 -7
  101. package/adventofcode/day2/day2.clj +0 -60
  102. package/adventofcode/day2/day2_part2.clj +0 -69
  103. package/adventofcode/day2/input1.txt +0 -1
  104. package/adventofcode/day3/bin/Grid.java +0 -92
  105. package/adventofcode/day3/bin/GridRow.java +0 -5
  106. package/adventofcode/day3/bin/LambdaSignature1.java +0 -3
  107. package/adventofcode/day3/bin/LambdaSignature2.java +0 -3
  108. package/adventofcode/day3/bin/LambdaSignature3.java +0 -3
  109. package/adventofcode/day3/bin/day3.cpp +0 -64
  110. package/adventofcode/day3/bin/day3.go +0 -55
  111. package/adventofcode/day3/bin/day3.js +0 -42
  112. package/adventofcode/day3/bin/day3.php +0 -41
  113. package/adventofcode/day3/bin/day3.scala +0 -52
  114. package/adventofcode/day3/bin/day3.swift +0 -43
  115. package/adventofcode/day3/bin/day3_part2.cpp +0 -216
  116. package/adventofcode/day3/bin/day3_part2.go +0 -188
  117. package/adventofcode/day3/bin/day3_part2.js +0 -123
  118. package/adventofcode/day3/bin/day3_part2.php +0 -135
  119. package/adventofcode/day3/bin/day3_part2.swift +0 -131
  120. package/adventofcode/day3/bin/day_three_part_two.java +0 -43
  121. package/adventofcode/day3/bin/day_two.java +0 -42
  122. package/adventofcode/day3/bin/operatorsOf.java +0 -14
  123. package/adventofcode/day3/bin/variant.hpp +0 -2416
  124. package/adventofcode/day3/compile.bat +0 -7
  125. package/adventofcode/day3/compile2.bat +0 -7
  126. package/adventofcode/day3/day3.clj +0 -42
  127. package/adventofcode/day3/day3_part2.clj +0 -112
  128. package/adventofcode/day4/bin/LambdaSignature1.java +0 -3
  129. package/adventofcode/day4/bin/day4.cpp +0 -118
  130. package/adventofcode/day4/bin/day4.go +0 -75
  131. package/adventofcode/day4/bin/day4.js +0 -40
  132. package/adventofcode/day4/bin/day4.php +0 -52
  133. package/adventofcode/day4/bin/day4.scala +0 -47
  134. package/adventofcode/day4/bin/day4.swift +0 -56
  135. package/adventofcode/day4/bin/day4_part2.go +0 -129
  136. package/adventofcode/day4/bin/day4_part2.js +0 -72
  137. package/adventofcode/day4/bin/day_four.java +0 -41
  138. package/adventofcode/day4/bin/inputData.java +0 -7
  139. package/adventofcode/day4/bin/operatorsOf.java +0 -11
  140. package/adventofcode/day4/bin/variant.hpp +0 -2416
  141. package/adventofcode/day4/compile.bat +0 -7
  142. package/adventofcode/day4/compile2.bat +0 -7
  143. package/adventofcode/day4/day4.clj +0 -32
  144. package/adventofcode/day4/day4_part2.clj +0 -44
  145. package/adventofcode/day4/input.clj +0 -519
  146. package/adventofcode/day4/input.txt +0 -512
  147. package/bin/api.ts +0 -24471
  148. package/bin/compiler.ts +0 -24482
  149. package/compiler/ColorConsole.clj +0 -22
  150. package/compiler/ContextOperators.clj +0 -75
  151. package/compiler/FlowEnterVarDef.clj +0 -223
  152. package/compiler/InputFileSystem.clj +0 -276
  153. package/compiler/RangerDocs.clj +0 -7
  154. package/compiler/TFactory.clj +0 -146
  155. package/compiler/TFiles.clj +0 -23
  156. package/compiler/TFlow.clj +0 -39
  157. package/compiler/TNodeFactory.clj +0 -84
  158. package/compiler/TTypes.clj +0 -188
  159. package/compiler/VirtualCompiler.clj +0 -800
  160. package/compiler/bin/ng_Compiler.js +0 -23779
  161. package/compiler/commonmark_plugin.clj +0 -359
  162. package/compiler/feat2.bat +0 -2
  163. package/compiler/feats.bat +0 -9
  164. package/compiler/feature_tests.clj +0 -192
  165. package/compiler/index.js +0 -2
  166. package/compiler/issue_57.clj +0 -25
  167. package/compiler/makefile_plugin.clj +0 -135
  168. package/compiler/markdown_plugin.clj +0 -386
  169. package/compiler/maven_plugin.clj +0 -162
  170. package/compiler/ng_AndroidPageWriter.clj +0 -299
  171. package/compiler/ng_CodeNode.clj +0 -756
  172. package/compiler/ng_CodeNodeCompilerExtensions.clj +0 -839
  173. package/compiler/ng_Compiler.clj +0 -49
  174. package/compiler/ng_CompilerGeneric.clj +0 -260
  175. package/compiler/ng_CompilerOrig.clj +0 -854
  176. package/compiler/ng_DictNode.clj +0 -346
  177. package/compiler/ng_DictNode2.clj +0 -316
  178. package/compiler/ng_Execute.clj +0 -138
  179. package/compiler/ng_Execute1.clj +0 -129
  180. package/compiler/ng_FlowWork.clj +0 -3951
  181. package/compiler/ng_LiveCompiler.clj +0 -1109
  182. package/compiler/ng_RagnerJavaScriptClassWriter.clj +0 -402
  183. package/compiler/ng_RangerActiveOperators.clj +0 -86
  184. package/compiler/ng_RangerAppClassDesc.clj +0 -400
  185. package/compiler/ng_RangerAppEnums.clj +0 -86
  186. package/compiler/ng_RangerAppFunctionDesc.clj +0 -127
  187. package/compiler/ng_RangerAppMessages.clj +0 -15
  188. package/compiler/ng_RangerAppOperatorDesc.clj +0 -20
  189. package/compiler/ng_RangerAppParamDesc.clj +0 -388
  190. package/compiler/ng_RangerAppWriterContext.clj +0 -1793
  191. package/compiler/ng_RangerArgMatch.clj +0 -638
  192. package/compiler/ng_RangerCSharpClassWriter.clj +0 -484
  193. package/compiler/ng_RangerCppClassWriter.clj +0 -1023
  194. package/compiler/ng_RangerDocGenerator.clj +0 -305
  195. package/compiler/ng_RangerFlowParser.clj +0 -4992
  196. package/compiler/ng_RangerFlowParserOrig.clj +0 -4002
  197. package/compiler/ng_RangerGenericClassWriter.clj +0 -573
  198. package/compiler/ng_RangerGolangClassWriter.clj +0 -1766
  199. package/compiler/ng_RangerImmutableExtension.clj +0 -77
  200. package/compiler/ng_RangerJava7ClassWriter.clj +0 -961
  201. package/compiler/ng_RangerJavaScriptClassWriter.clj +0 -1042
  202. package/compiler/ng_RangerKotlinClassWriter.clj +0 -372
  203. package/compiler/ng_RangerLanguageWriters.clj +0 -14
  204. package/compiler/ng_RangerLispParser.clj +0 -873
  205. package/compiler/ng_RangerPHPClassWriter.clj +0 -643
  206. package/compiler/ng_RangerPlugin.clj +0 -41
  207. package/compiler/ng_RangerRangerClassWriter.clj +0 -357
  208. package/compiler/ng_RangerRustClassWriter.clj +0 -420
  209. package/compiler/ng_RangerScalaClassWriter.clj +0 -818
  210. package/compiler/ng_RangerSerializeClass.clj +0 -502
  211. package/compiler/ng_RangerServiceBuilder.clj +0 -63
  212. package/compiler/ng_RangerSwift3ClassWriter.clj +0 -809
  213. package/compiler/ng_RangerSwiftClassWriter.clj +0 -0
  214. package/compiler/ng_RangerTypeClass.clj +0 -45
  215. package/compiler/ng_SourceParser.clj +0 -241
  216. package/compiler/ng_SourceParser2.clj +0 -214
  217. package/compiler/ng_WebPageWriter.clj +0 -39
  218. package/compiler/ng_jsonParser.clj +0 -340
  219. package/compiler/ng_p_test.clj +0 -1711
  220. package/compiler/ng_parser.clj +0 -911
  221. package/compiler/ng_parser2.clj +0 -735
  222. package/compiler/ng_parser2_backup.clj +0 -1679
  223. package/compiler/ng_parser_backup.clj +0 -886
  224. package/compiler/ng_parser_ok.clj +0 -1718
  225. package/compiler/ng_parser_ok2.clj +0 -1717
  226. package/compiler/ng_parser_std_match.clj +0 -687
  227. package/compiler/ng_parser_std_match2.clj +0 -1012
  228. package/compiler/ng_parser_v2.clj +0 -1251
  229. package/compiler/ng_ui.clj +0 -403
  230. package/compiler/ng_ui_test.clj +0 -18
  231. package/compiler/ng_writer.clj +0 -338
  232. package/compiler/ng_xmlParser.clj +0 -472
  233. package/compiler/ng_xmlParser2.clj +0 -317
  234. package/compiler/ng_xmlParser3.clj +0 -251
  235. package/compiler/opdoc.bat +0 -4
  236. package/compiler/operators.md +0 -290
  237. package/compiler/p.bat +0 -4
  238. package/compiler/package.json +0 -10
  239. package/compiler/pcmd.bat +0 -4
  240. package/compiler/pcmd2.bat +0 -3
  241. package/compiler/plaintext_plugin.clj +0 -69
  242. package/compiler/plugin.bat +0 -19
  243. package/compiler/plugin2.bat +0 -4
  244. package/compiler/plugin_app.bat +0 -3
  245. package/compiler/plugin_apps.clj +0 -27
  246. package/compiler/plugins.bat +0 -10
  247. package/compiler/reveal_plugin.clj +0 -409
  248. package/compiler/simplePlugin.clj +0 -780
  249. package/compiler/t.bat +0 -3
  250. package/compiler/test_any.clj +0 -43
  251. package/compiler/test_call.clj +0 -141
  252. package/compiler/test_chain.clj +0 -79
  253. package/compiler/test_json.clj +0 -10
  254. package/compiler/test_lambda.clj +0 -153
  255. package/compiler/test_pcmd.clj +0 -32
  256. package/compiler/test_pcmd2.clj +0 -29
  257. package/compiler/test_plugin.clj +0 -237
  258. package/compiler/test_readfile.clj +0 -13
  259. package/compiler/test_reveal.clj +0 -19
  260. package/compiler/test_slides.clj +0 -312
  261. package/compiler/test_types.clj +0 -143
  262. package/compiler/test_types2.clj +0 -49
  263. package/compiler/test_types3.clj +0 -53
  264. package/compiler/test_var.clj +0 -40
  265. package/compiler/tonpm.bat +0 -14
  266. package/compiler/tonpm2.bat +0 -12
  267. package/compiler/ui_plugin.clj +0 -507
  268. package/compiler/ui_plugin2.clj +0 -427
  269. package/compiler/update-git.bat +0 -3
  270. package/compiler/vcomp.bat +0 -4
  271. package/compiler/viewbuilder_Android.clj +0 -176
  272. package/compiler/viewbuilder_Web.clj +0 -105
  273. package/dist/bin/api.js +0 -32422
  274. package/dist/bin/api.js.map +0 -1
  275. package/dist/bin/compiler.d.ts +0 -1638
  276. package/dist/bin/compiler.js +0 -32444
  277. package/dist/bin/compiler.js.map +0 -1
  278. package/examples/3D/bin/test_3d.js +0 -329
  279. package/examples/3D/test_3d.clj +0 -385
  280. package/examples/EVGColor/EVGColor.clj +0 -310
  281. package/examples/EVGColor/EVGColorContext.clj +0 -176
  282. package/examples/EVGColor/bin/EVGColor.js +0 -286
  283. package/examples/EVGColor/bin/minimized.js +0 -286
  284. package/examples/SVGPath/SVGPath.clj +0 -625
  285. package/examples/SVGPath/Vec2.clj +0 -103
  286. package/examples/SVGPath/bin/SVGPath.cpp +0 -887
  287. package/examples/SVGPath/bin/SVGPath.js +0 -682
  288. package/examples/SVGPath/bin/minimized.js +0 -578
  289. package/examples/SVGPath/bin/variant.hpp +0 -2416
  290. package/examples/minification/Vec2.clj +0 -103
  291. package/examples/minification/bin/minified.js +0 -44
  292. package/examples/minification/bin/test.js +0 -117
  293. package/examples/minification/test.clj +0 -13
  294. package/fiddle/VirtualCompiler.js +0 -23495
  295. package/fiddle/browser_editor.js +0 -13240
  296. package/fiddle/compileEnv.js +0 -1
  297. package/fiddle/compileEnv.json +0 -1
  298. package/fiddle/lang_data.js +0 -1
  299. package/index.html +0 -18
  300. package/native/httpd/HttpTester.clj +0 -33
  301. package/native/httpd/RangerWebService.clj +0 -81
  302. package/operators.md +0 -290
  303. package/tsconfig.json +0 -29
  304. package/versions/cpp/compiler.cpp +0 -15032
  305. package/versions/es6/compiler.js +0 -12860
  306. package/versions/go/compiler.go +0 -21338
  307. package/versions/java/AfterCodeNode.java +0 -4
  308. package/versions/java/ClassJoinPoint.java +0 -6
  309. package/versions/java/CodeFile.java +0 -42
  310. package/versions/java/CodeFileSystem.java +0 -72
  311. package/versions/java/CodeNode.java +0 -807
  312. package/versions/java/CodeSlice.java +0 -13
  313. package/versions/java/CodeWriter.java +0 -185
  314. package/versions/java/ColorConsole.java +0 -8
  315. package/versions/java/CompilerInterface.java +0 -213
  316. package/versions/java/DictNode.java +0 -353
  317. package/versions/java/LiveCompiler.java +0 -772
  318. package/versions/java/NodeEvalState.java +0 -24
  319. package/versions/java/OpFindResult.java +0 -6
  320. package/versions/java/RangerAppArrayValue.java +0 -7
  321. package/versions/java/RangerAppClassDesc.java +0 -217
  322. package/versions/java/RangerAppEnum.java +0 -14
  323. package/versions/java/RangerAppFunctionDesc.java +0 -20
  324. package/versions/java/RangerAppHashValue.java +0 -11
  325. package/versions/java/RangerAppInterfaceImpl.java +0 -6
  326. package/versions/java/RangerAppMethodVariants.java +0 -6
  327. package/versions/java/RangerAppParamDesc.java +0 -321
  328. package/versions/java/RangerAppTodo.java +0 -6
  329. package/versions/java/RangerAppValue.java +0 -10
  330. package/versions/java/RangerAppWriterContext.java +0 -800
  331. package/versions/java/RangerArgMatch.java +0 -317
  332. package/versions/java/RangerBackReference.java +0 -7
  333. package/versions/java/RangerCSharpClassWriter.java +0 -287
  334. package/versions/java/RangerCompilerMessage.java +0 -9
  335. package/versions/java/RangerCppClassWriter.java +0 -725
  336. package/versions/java/RangerFlowParser.java +0 -2142
  337. package/versions/java/RangerGenericClassWriter.java +0 -367
  338. package/versions/java/RangerGolangClassWriter.java +0 -1379
  339. package/versions/java/RangerJava7ClassWriter.java +0 -652
  340. package/versions/java/RangerJavaScriptClassWriter.java +0 -305
  341. package/versions/java/RangerKotlinClassWriter.java +0 -380
  342. package/versions/java/RangerLispParser.java +0 -845
  343. package/versions/java/RangerNodeValue.java +0 -9
  344. package/versions/java/RangerPHPClassWriter.java +0 -527
  345. package/versions/java/RangerParamEventHandler.java +0 -6
  346. package/versions/java/RangerParamEventList.java +0 -5
  347. package/versions/java/RangerParamEventMap.java +0 -27
  348. package/versions/java/RangerRangerClassWriter.java +0 -268
  349. package/versions/java/RangerRefForce.java +0 -7
  350. package/versions/java/RangerScalaClassWriter.java +0 -365
  351. package/versions/java/RangerSerializeClass.java +0 -148
  352. package/versions/java/RangerSwift3ClassWriter.java +0 -548
  353. package/versions/java/RangerTypeClass.java +0 -17
  354. package/versions/java/SourceCode.java +0 -65
  355. package/versions/php/compiler.php +0 -13830
  356. package/versions/swift3/compiler.swift +0 -12542
  357. /package/{lib/ACEEditor.clj → dist/lib/ACEEditor.rgr} +0 -0
  358. /package/{lib/SQL.clj → dist/lib/SQL.rgr} +0 -0
  359. /package/{lib/ServiceLib.clj → dist/lib/ServiceLib.rgr} +0 -0
  360. /package/{lib/Time.clj → dist/lib/Time.rgr} +0 -0
  361. /package/{lib/TypedArrays.clj → dist/lib/TypedArrays.rgr} +0 -0
  362. /package/{lib/WebLib.clj → dist/lib/WebLib.rgr} +0 -0
  363. /package/{lib/WebServerLib.clj → dist/lib/WebServerLib.rgr} +0 -0
@@ -1,2416 +0,0 @@
1
- // MPark.Variant
2
- //
3
- // Copyright Michael Park, 2015-2017
4
- //
5
- // Distributed under the Boost Software License, Version 1.0.
6
- // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
7
-
8
- #ifndef MPARK_VARIANT_HPP
9
- #define MPARK_VARIANT_HPP
10
-
11
- /*
12
- variant synopsis
13
-
14
- namespace std {
15
-
16
- // 20.7.2, class template variant
17
- template <class... Types>
18
- class variant {
19
- public:
20
-
21
- // 20.7.2.1, constructors
22
- constexpr variant() noexcept(see below);
23
- variant(const variant&);
24
- variant(variant&&) noexcept(see below);
25
-
26
- template <class T> constexpr variant(T&&) noexcept(see below);
27
-
28
- template <class T, class... Args>
29
- constexpr explicit variant(in_place_type_t<T>, Args&&...);
30
-
31
- template <class T, class U, class... Args>
32
- constexpr explicit variant(
33
- in_place_type_t<T>, initializer_list<U>, Args&&...);
34
-
35
- template <size_t I, class... Args>
36
- constexpr explicit variant(in_place_index_t<I>, Args&&...);
37
-
38
- template <size_t I, class U, class... Args>
39
- constexpr explicit variant(
40
- in_place_index_t<I>, initializer_list<U>, Args&&...);
41
-
42
- // 20.7.2.2, destructor
43
- ~variant();
44
-
45
- // 20.7.2.3, assignment
46
- variant& operator=(const variant&);
47
- variant& operator=(variant&&) noexcept(see below);
48
-
49
- template <class T> variant& operator=(T&&) noexcept(see below);
50
-
51
- // 20.7.2.4, modifiers
52
- template <class T, class... Args>
53
- T& emplace(Args&&...);
54
-
55
- template <class T, class U, class... Args>
56
- T& emplace(initializer_list<U>, Args&&...);
57
-
58
- template <size_t I, class... Args>
59
- variant_alternative<I, variant>& emplace(Args&&...);
60
-
61
- template <size_t I, class U, class... Args>
62
- variant_alternative<I, variant>& emplace(initializer_list<U>, Args&&...);
63
-
64
- // 20.7.2.5, value status
65
- constexpr bool valueless_by_exception() const noexcept;
66
- constexpr size_t index() const noexcept;
67
-
68
- // 20.7.2.6, swap
69
- void swap(variant&) noexcept(see below);
70
- };
71
-
72
- // 20.7.3, variant helper classes
73
- template <class T> struct variant_size; // undefined
74
-
75
- template <class T>
76
- constexpr size_t variant_size_v = variant_size<T>::value;
77
-
78
- template <class T> struct variant_size<const T>;
79
- template <class T> struct variant_size<volatile T>;
80
- template <class T> struct variant_size<const volatile T>;
81
-
82
- template <class... Types>
83
- struct variant_size<variant<Types...>>;
84
-
85
- template <size_t I, class T> struct variant_alternative; // undefined
86
-
87
- template <size_t I, class T>
88
- using variant_alternative_t = typename variant_alternative<I, T>::type;
89
-
90
- template <size_t I, class T> struct variant_alternative<I, const T>;
91
- template <size_t I, class T> struct variant_alternative<I, volatile T>;
92
- template <size_t I, class T> struct variant_alternative<I, const volatile T>;
93
-
94
- template <size_t I, class... Types>
95
- struct variant_alternative<I, variant<Types...>>;
96
-
97
- constexpr size_t variant_npos = -1;
98
-
99
- // 20.7.4, value access
100
- template <class T, class... Types>
101
- constexpr bool holds_alternative(const variant<Types...>&) noexcept;
102
-
103
- template <size_t I, class... Types>
104
- constexpr variant_alternative_t<I, variant<Types...>>&
105
- get(variant<Types...>&);
106
-
107
- template <size_t I, class... Types>
108
- constexpr variant_alternative_t<I, variant<Types...>>&&
109
- get(variant<Types...>&&);
110
-
111
- template <size_t I, class... Types>
112
- constexpr variant_alternative_t<I, variant<Types...>> const&
113
- get(const variant<Types...>&);
114
-
115
- template <size_t I, class... Types>
116
- constexpr variant_alternative_t<I, variant<Types...>> const&&
117
- get(const variant<Types...>&&);
118
-
119
- template <class T, class... Types>
120
- constexpr T& get(variant<Types...>&);
121
-
122
- template <class T, class... Types>
123
- constexpr T&& get(variant<Types...>&&);
124
-
125
- template <class T, class... Types>
126
- constexpr const T& get(const variant<Types...>&);
127
-
128
- template <class T, class... Types>
129
- constexpr const T&& get(const variant<Types...>&&);
130
-
131
- template <size_t I, class... Types>
132
- constexpr add_pointer_t<variant_alternative_t<I, variant<Types...>>>
133
- get_if(variant<Types...>*) noexcept;
134
-
135
- template <size_t I, class... Types>
136
- constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>>
137
- get_if(const variant<Types...>*) noexcept;
138
-
139
- template <class T, class... Types>
140
- constexpr add_pointer_t<T>
141
- get_if(variant<Types...>*) noexcept;
142
-
143
- template <class T, class... Types>
144
- constexpr add_pointer_t<const T>
145
- get_if(const variant<Types...>*) noexcept;
146
-
147
- // 20.7.5, relational operators
148
- template <class... Types>
149
- constexpr bool operator==(const variant<Types...>&, const variant<Types...>&);
150
-
151
- template <class... Types>
152
- constexpr bool operator!=(const variant<Types...>&, const variant<Types...>&);
153
-
154
- template <class... Types>
155
- constexpr bool operator<(const variant<Types...>&, const variant<Types...>&);
156
-
157
- template <class... Types>
158
- constexpr bool operator>(const variant<Types...>&, const variant<Types...>&);
159
-
160
- template <class... Types>
161
- constexpr bool operator<=(const variant<Types...>&, const variant<Types...>&);
162
-
163
- template <class... Types>
164
- constexpr bool operator>=(const variant<Types...>&, const variant<Types...>&);
165
-
166
- // 20.7.6, visitation
167
- template <class Visitor, class... Variants>
168
- constexpr see below visit(Visitor&&, Variants&&...);
169
-
170
- // 20.7.7, class monostate
171
- struct monostate;
172
-
173
- // 20.7.8, monostate relational operators
174
- constexpr bool operator<(monostate, monostate) noexcept;
175
- constexpr bool operator>(monostate, monostate) noexcept;
176
- constexpr bool operator<=(monostate, monostate) noexcept;
177
- constexpr bool operator>=(monostate, monostate) noexcept;
178
- constexpr bool operator==(monostate, monostate) noexcept;
179
- constexpr bool operator!=(monostate, monostate) noexcept;
180
-
181
- // 20.7.9, specialized algorithms
182
- template <class... Types>
183
- void swap(variant<Types...>&, variant<Types...>&) noexcept(see below);
184
-
185
- // 20.7.10, class bad_variant_access
186
- class bad_variant_access;
187
-
188
- // 20.7.11, hash support
189
- template <class T> struct hash;
190
- template <class... Types> struct hash<variant<Types...>>;
191
- template <> struct hash<monostate>;
192
-
193
- } // namespace std
194
-
195
- */
196
-
197
- #include <cstddef>
198
- #include <exception>
199
- #include <functional>
200
- #include <initializer_list>
201
- #include <new>
202
- #include <type_traits>
203
- #include <utility>
204
-
205
- // MPark.Variant
206
- //
207
- // Copyright Michael Park, 2015-2017
208
- //
209
- // Distributed under the Boost Software License, Version 1.0.
210
- // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
211
-
212
- #ifndef MPARK_CONFIG_HPP
213
- #define MPARK_CONFIG_HPP
214
-
215
- // MSVC 2015 Update 3.
216
- #if __cplusplus < 201103L && (!defined(_MSC_VER) || _MSC_FULL_VER < 190024215)
217
- #error "MPark.Variant requires C++11 support."
218
- #endif
219
-
220
- #ifndef __has_builtin
221
- #define __has_builtin(x) 0
222
- #endif
223
-
224
- #ifndef __has_include
225
- #define __has_include(x) 0
226
- #endif
227
-
228
- #ifndef __has_feature
229
- #define __has_feature(x) 0
230
- #endif
231
-
232
- #if __has_builtin(__builtin_addressof) || \
233
- (defined(__GNUC__) && __GNUC__ >= 7) || defined(_MSC_VER)
234
- #define MPARK_BUILTIN_ADDRESSOF
235
- #endif
236
-
237
- #if __has_builtin(__builtin_unreachable)
238
- #define MPARK_BUILTIN_UNREACHABLE
239
- #endif
240
-
241
- #if __has_builtin(__type_pack_element)
242
- #define MPARK_TYPE_PACK_ELEMENT
243
- #endif
244
-
245
- #if defined(__cpp_constexpr) && __cpp_constexpr >= 201304
246
- #define MPARK_CPP14_CONSTEXPR
247
- #endif
248
-
249
- #if __has_feature(cxx_exceptions) || defined(__cpp_exceptions) || \
250
- (defined(_MSC_VER) && defined(_CPPUNWIND))
251
- #define MPARK_EXCEPTIONS
252
- #endif
253
-
254
- #if defined(__cpp_generic_lambdas) || defined(_MSC_VER)
255
- #define MPARK_GENERIC_LAMBDAS
256
- #endif
257
-
258
- #if defined(__cpp_lib_integer_sequence)
259
- #define MPARK_INTEGER_SEQUENCE
260
- #endif
261
-
262
- #if defined(__cpp_return_type_deduction) || defined(_MSC_VER)
263
- #define MPARK_RETURN_TYPE_DEDUCTION
264
- #endif
265
-
266
- #if defined(__cpp_lib_transparent_operators) || defined(_MSC_VER)
267
- #define MPARK_TRANSPARENT_OPERATORS
268
- #endif
269
-
270
- #if defined(__cpp_variable_templates) || defined(_MSC_VER)
271
- #define MPARK_VARIABLE_TEMPLATES
272
- #endif
273
-
274
- #if !defined(__GLIBCXX__) || __has_include(<codecvt>) // >= libstdc++-5
275
- #define MPARK_TRIVIALITY_TYPE_TRAITS
276
- #endif
277
-
278
- #endif // MPARK_CONFIG_HPP
279
-
280
- // MPark.Variant
281
- //
282
- // Copyright Michael Park, 2015-2017
283
- //
284
- // Distributed under the Boost Software License, Version 1.0.
285
- // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
286
-
287
- #ifndef MPARK_IN_PLACE_HPP
288
- #define MPARK_IN_PLACE_HPP
289
-
290
- #include <cstddef>
291
-
292
-
293
- namespace mpark {
294
-
295
- struct in_place_t { explicit in_place_t() = default; };
296
-
297
- template <std::size_t I>
298
- struct in_place_index_t { explicit in_place_index_t() = default; };
299
-
300
- template <typename T>
301
- struct in_place_type_t { explicit in_place_type_t() = default; };
302
-
303
- #ifdef MPARK_VARIABLE_TEMPLATES
304
- constexpr in_place_t in_place{};
305
-
306
- template <std::size_t I> constexpr in_place_index_t<I> in_place_index{};
307
-
308
- template <typename T> constexpr in_place_type_t<T> in_place_type{};
309
- #endif
310
-
311
- } // namespace mpark
312
-
313
- #endif // MPARK_IN_PLACE_HPP
314
-
315
- // MPark.Variant
316
- //
317
- // Copyright Michael Park, 2015-2017
318
- //
319
- // Distributed under the Boost Software License, Version 1.0.
320
- // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
321
-
322
- #ifndef MPARK_LIB_HPP
323
- #define MPARK_LIB_HPP
324
-
325
- #include <memory>
326
- #include <functional>
327
- #include <type_traits>
328
- #include <utility>
329
-
330
-
331
- #define RETURN(...) \
332
- noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) { \
333
- return __VA_ARGS__; \
334
- }
335
-
336
- namespace mpark {
337
- namespace lib {
338
- template <typename T>
339
- struct identity { using type = T; };
340
-
341
- inline namespace cpp14 {
342
- template <typename T, std::size_t N>
343
- struct array {
344
- constexpr const T &operator[](std::size_t index) const {
345
- return data[index];
346
- }
347
-
348
- T data[N == 0 ? 1 : N];
349
- };
350
-
351
- template <typename T>
352
- using add_pointer_t = typename std::add_pointer<T>::type;
353
-
354
- template <typename... Ts>
355
- using common_type_t = typename std::common_type<Ts...>::type;
356
-
357
- template <typename T>
358
- using decay_t = typename std::decay<T>::type;
359
-
360
- template <bool B, typename T = void>
361
- using enable_if_t = typename std::enable_if<B, T>::type;
362
-
363
- template <typename T>
364
- using remove_const_t = typename std::remove_const<T>::type;
365
-
366
- template <typename T>
367
- using remove_reference_t = typename std::remove_reference<T>::type;
368
-
369
- template <typename T>
370
- inline constexpr T &&forward(remove_reference_t<T> &t) noexcept {
371
- return static_cast<T &&>(t);
372
- }
373
-
374
- template <typename T>
375
- inline constexpr T &&forward(remove_reference_t<T> &&t) noexcept {
376
- static_assert(!std::is_lvalue_reference<T>::value,
377
- "can not forward an rvalue as an lvalue");
378
- return static_cast<T &&>(t);
379
- }
380
-
381
- template <typename T>
382
- inline constexpr remove_reference_t<T> &&move(T &&t) noexcept {
383
- return static_cast<remove_reference_t<T> &&>(t);
384
- }
385
-
386
- #ifdef MPARK_INTEGER_SEQUENCE
387
- using std::integer_sequence;
388
- using std::index_sequence;
389
- using std::make_index_sequence;
390
- using std::index_sequence_for;
391
- #else
392
- template <typename T, T... Is>
393
- struct integer_sequence {
394
- using value_type = T;
395
- static constexpr std::size_t size() noexcept { return sizeof...(Is); }
396
- };
397
-
398
- template <std::size_t... Is>
399
- using index_sequence = integer_sequence<std::size_t, Is...>;
400
-
401
- template <typename Lhs, typename Rhs>
402
- struct make_index_sequence_concat;
403
-
404
- template <std::size_t... Lhs, std::size_t... Rhs>
405
- struct make_index_sequence_concat<index_sequence<Lhs...>,
406
- index_sequence<Rhs...>>
407
- : identity<index_sequence<Lhs..., (sizeof...(Lhs) + Rhs)...>> {};
408
-
409
- template <std::size_t N>
410
- struct make_index_sequence_impl;
411
-
412
- template <std::size_t N>
413
- using make_index_sequence = typename make_index_sequence_impl<N>::type;
414
-
415
- template <std::size_t N>
416
- struct make_index_sequence_impl
417
- : make_index_sequence_concat<make_index_sequence<N / 2>,
418
- make_index_sequence<N - (N / 2)>> {};
419
-
420
- template <>
421
- struct make_index_sequence_impl<0> : identity<index_sequence<>> {};
422
-
423
- template <>
424
- struct make_index_sequence_impl<1> : identity<index_sequence<0>> {};
425
-
426
- template <typename... Ts>
427
- using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
428
- #endif
429
-
430
- // <functional>
431
- #ifdef MPARK_TRANSPARENT_OPERATORS
432
- using equal_to = std::equal_to<>;
433
- #else
434
- struct equal_to {
435
- template <typename Lhs, typename Rhs>
436
- inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
437
- RETURN(lib::forward<Lhs>(lhs) == lib::forward<Rhs>(rhs))
438
- };
439
- #endif
440
-
441
- #ifdef MPARK_TRANSPARENT_OPERATORS
442
- using not_equal_to = std::not_equal_to<>;
443
- #else
444
- struct not_equal_to {
445
- template <typename Lhs, typename Rhs>
446
- inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
447
- RETURN(lib::forward<Lhs>(lhs) != lib::forward<Rhs>(rhs))
448
- };
449
- #endif
450
-
451
- #ifdef MPARK_TRANSPARENT_OPERATORS
452
- using less = std::less<>;
453
- #else
454
- struct less {
455
- template <typename Lhs, typename Rhs>
456
- inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
457
- RETURN(lib::forward<Lhs>(lhs) < lib::forward<Rhs>(rhs))
458
- };
459
- #endif
460
-
461
- #ifdef MPARK_TRANSPARENT_OPERATORS
462
- using greater = std::greater<>;
463
- #else
464
- struct greater {
465
- template <typename Lhs, typename Rhs>
466
- inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
467
- RETURN(lib::forward<Lhs>(lhs) > lib::forward<Rhs>(rhs))
468
- };
469
- #endif
470
-
471
- #ifdef MPARK_TRANSPARENT_OPERATORS
472
- using less_equal = std::less_equal<>;
473
- #else
474
- struct less_equal {
475
- template <typename Lhs, typename Rhs>
476
- inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
477
- RETURN(lib::forward<Lhs>(lhs) <= lib::forward<Rhs>(rhs))
478
- };
479
- #endif
480
-
481
- #ifdef MPARK_TRANSPARENT_OPERATORS
482
- using greater_equal = std::greater_equal<>;
483
- #else
484
- struct greater_equal {
485
- template <typename Lhs, typename Rhs>
486
- inline constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const
487
- RETURN(lib::forward<Lhs>(lhs) >= lib::forward<Rhs>(rhs))
488
- };
489
- #endif
490
- } // namespace cpp14
491
-
492
- inline namespace cpp17 {
493
-
494
- // <type_traits>
495
- template <bool B>
496
- using bool_constant = std::integral_constant<bool, B>;
497
-
498
- template <typename...>
499
- struct voider : identity<void> {};
500
-
501
- template <typename... Ts>
502
- using void_t = typename voider<Ts...>::type;
503
-
504
- namespace detail {
505
- namespace swappable {
506
-
507
- using std::swap;
508
-
509
- template <typename T>
510
- struct is_swappable_impl {
511
- private:
512
- template <typename U,
513
- typename = decltype(swap(std::declval<U &>(),
514
- std::declval<U &>()))>
515
- inline static std::true_type test(int);
516
-
517
- template <typename U>
518
- inline static std::false_type test(...);
519
-
520
- public:
521
- using type = decltype(test<T>(0));
522
- };
523
-
524
- template <typename T>
525
- using is_swappable = typename is_swappable_impl<T>::type;
526
-
527
- template <typename T, bool = is_swappable<T>::value>
528
- struct is_nothrow_swappable {
529
- static constexpr bool value =
530
- noexcept(swap(std::declval<T &>(), std::declval<T &>()));
531
- };
532
-
533
- template <typename T>
534
- struct is_nothrow_swappable<T, false> : std::false_type {};
535
-
536
- } // namespace swappable
537
- } // namespace detail
538
-
539
- template <typename T>
540
- using is_swappable = detail::swappable::is_swappable<T>;
541
-
542
- template <typename T>
543
- using is_nothrow_swappable = detail::swappable::is_nothrow_swappable<T>;
544
-
545
- // <functional>
546
- #ifdef _MSC_VER
547
- #pragma warning(push)
548
- #pragma warning(disable : 4100)
549
- #endif
550
- template <typename F, typename... As>
551
- inline constexpr auto invoke(F &&f, As &&... as)
552
- RETURN(lib::forward<F>(f)(lib::forward<As>(as)...))
553
- #ifdef _MSC_VER
554
- #pragma warning(pop)
555
- #endif
556
-
557
- template <typename B, typename T, typename D>
558
- inline constexpr auto invoke(T B::*pmv, D &&d)
559
- RETURN(lib::forward<D>(d).*pmv)
560
-
561
- template <typename Pmv, typename Ptr>
562
- inline constexpr auto invoke(Pmv pmv, Ptr &&ptr)
563
- RETURN((*lib::forward<Ptr>(ptr)).*pmv)
564
-
565
- template <typename B, typename T, typename D, typename... As>
566
- inline constexpr auto invoke(T B::*pmf, D &&d, As &&... as)
567
- RETURN((lib::forward<D>(d).*pmf)(lib::forward<As>(as)...))
568
-
569
- template <typename Pmf, typename Ptr, typename... As>
570
- inline constexpr auto invoke(Pmf pmf, Ptr &&ptr, As &&... as)
571
- RETURN(((*lib::forward<Ptr>(ptr)).*pmf)(lib::forward<As>(as)...))
572
-
573
- namespace detail {
574
-
575
- template <typename Void, typename, typename...>
576
- struct invoke_result {};
577
-
578
- template <typename F, typename... Args>
579
- struct invoke_result<void_t<decltype(lib::invoke(
580
- std::declval<F>(), std::declval<Args>()...))>,
581
- F,
582
- Args...>
583
- : identity<decltype(
584
- lib::invoke(std::declval<F>(), std::declval<Args>()...))> {};
585
-
586
- } // namespace detail
587
-
588
- template <typename F, typename... Args>
589
- using invoke_result = detail::invoke_result<void, F, Args...>;
590
-
591
- template <typename F, typename... Args>
592
- using invoke_result_t = typename invoke_result<F, Args...>::type;
593
-
594
- namespace detail {
595
-
596
- template <typename Void, typename, typename...>
597
- struct is_invocable : std::false_type {};
598
-
599
- template <typename F, typename... Args>
600
- struct is_invocable<void_t<invoke_result_t<F, Args...>>, F, Args...>
601
- : std::true_type {};
602
-
603
- template <typename Void, typename, typename, typename...>
604
- struct is_invocable_r : std::false_type {};
605
-
606
- template <typename R, typename F, typename... Args>
607
- struct is_invocable_r<void_t<invoke_result_t<F, Args...>>,
608
- R,
609
- F,
610
- Args...>
611
- : std::is_convertible<invoke_result_t<F, Args...>, R> {};
612
-
613
- } // namespace detail
614
-
615
- template <typename F, typename... Args>
616
- using is_invocable = detail::is_invocable<void, F, Args...>;
617
-
618
- template <typename R, typename F, typename... Args>
619
- using is_invocable_r = detail::is_invocable_r<void, R, F, Args...>;
620
-
621
- // <memory>
622
- #ifdef MPARK_BUILTIN_ADDRESSOF
623
- template <typename T>
624
- inline constexpr T *addressof(T &arg) {
625
- return __builtin_addressof(arg);
626
- }
627
- #else
628
- namespace detail {
629
-
630
- namespace has_addressof_impl {
631
-
632
- struct fail;
633
-
634
- template <typename T>
635
- inline fail operator&(T &&);
636
-
637
- template <typename T>
638
- inline static constexpr bool impl() {
639
- return (std::is_class<T>::value || std::is_union<T>::value) &&
640
- !std::is_same<decltype(&std::declval<T &>()), fail>::value;
641
- }
642
-
643
- } // namespace has_addressof_impl
644
-
645
- template <typename T>
646
- using has_addressof = bool_constant<has_addressof_impl::impl<T>()>;
647
-
648
- template <typename T>
649
- inline constexpr T *addressof(T &arg, std::true_type) {
650
- return std::addressof(arg);
651
- }
652
-
653
- template <typename T>
654
- inline constexpr T *addressof(T &arg, std::false_type) {
655
- return &arg;
656
- }
657
-
658
- } // namespace detail
659
-
660
- template <typename T>
661
- inline constexpr T *addressof(T &arg) {
662
- return detail::addressof(arg, detail::has_addressof<T>{});
663
- }
664
- #endif
665
-
666
- template <typename T>
667
- inline constexpr T *addressof(const T &&) = delete;
668
-
669
- } // namespace cpp17
670
-
671
- template <typename T>
672
- struct remove_all_extents : identity<T> {};
673
-
674
- template <typename T, std::size_t N>
675
- struct remove_all_extents<array<T, N>> : remove_all_extents<T> {};
676
-
677
- template <typename T>
678
- using remove_all_extents_t = typename remove_all_extents<T>::type;
679
-
680
- template <std::size_t N>
681
- using size_constant = std::integral_constant<std::size_t, N>;
682
-
683
- template <bool... Bs>
684
- using bool_sequence = integer_sequence<bool, Bs...>;
685
-
686
- template <std::size_t I, typename T>
687
- struct indexed_type : size_constant<I>, identity<T> {};
688
-
689
- template <bool... Bs>
690
- using all =
691
- std::is_same<bool_sequence<true, Bs...>, bool_sequence<Bs..., true>>;
692
-
693
- #ifdef MPARK_TYPE_PACK_ELEMENT
694
- template <std::size_t I, typename... Ts>
695
- using type_pack_element_t = __type_pack_element<I, Ts...>;
696
- #else
697
- template <std::size_t I, typename... Ts>
698
- struct type_pack_element_impl {
699
- private:
700
- template <typename>
701
- struct set;
702
-
703
- template <std::size_t... Is>
704
- struct set<index_sequence<Is...>> : indexed_type<Is, Ts>... {};
705
-
706
- template <typename T>
707
- inline static std::enable_if<true, T> impl(indexed_type<I, T>);
708
-
709
- inline static std::enable_if<false> impl(...);
710
-
711
- public:
712
- using type = decltype(impl(set<index_sequence_for<Ts...>>{}));
713
- };
714
-
715
- template <std::size_t I, typename... Ts>
716
- using type_pack_element = typename type_pack_element_impl<I, Ts...>::type;
717
-
718
- template <std::size_t I, typename... Ts>
719
- using type_pack_element_t = typename type_pack_element<I, Ts...>::type;
720
- #endif
721
-
722
- #ifdef MPARK_TRIVIALITY_TYPE_TRAITS
723
- using std::is_trivially_copy_constructible;
724
- using std::is_trivially_move_constructible;
725
- using std::is_trivially_copy_assignable;
726
- using std::is_trivially_move_assignable;
727
- #else
728
- template <typename T>
729
- struct is_trivially_copy_constructible
730
- : bool_constant<
731
- std::is_copy_constructible<T>::value && __has_trivial_copy(T)> {};
732
-
733
- template <typename T>
734
- struct is_trivially_move_constructible : bool_constant<__is_trivial(T)> {};
735
-
736
- template <typename T>
737
- struct is_trivially_copy_assignable
738
- : bool_constant<
739
- std::is_copy_assignable<T>::value && __has_trivial_assign(T)> {};
740
-
741
- template <typename T>
742
- struct is_trivially_move_assignable : bool_constant<__is_trivial(T)> {};
743
- #endif
744
-
745
- } // namespace lib
746
- } // namespace mpark
747
-
748
- #undef RETURN
749
-
750
- #endif // MPARK_LIB_HPP
751
-
752
-
753
- namespace mpark {
754
-
755
- #ifdef MPARK_RETURN_TYPE_DEDUCTION
756
-
757
- #define AUTO auto
758
- #define AUTO_RETURN(...) { return __VA_ARGS__; }
759
-
760
- #define AUTO_REFREF auto &&
761
- #define AUTO_REFREF_RETURN(...) { return __VA_ARGS__; }
762
-
763
- #define DECLTYPE_AUTO decltype(auto)
764
- #define DECLTYPE_AUTO_RETURN(...) { return __VA_ARGS__; }
765
-
766
- #else
767
-
768
- #define AUTO auto
769
- #define AUTO_RETURN(...) \
770
- -> lib::decay_t<decltype(__VA_ARGS__)> { return __VA_ARGS__; }
771
-
772
- #define AUTO_REFREF auto
773
- #define AUTO_REFREF_RETURN(...) \
774
- -> decltype((__VA_ARGS__)) { \
775
- static_assert(std::is_reference<decltype((__VA_ARGS__))>::value, ""); \
776
- return __VA_ARGS__; \
777
- }
778
-
779
- #define DECLTYPE_AUTO auto
780
- #define DECLTYPE_AUTO_RETURN(...) \
781
- -> decltype(__VA_ARGS__) { return __VA_ARGS__; }
782
-
783
- #endif
784
-
785
- class bad_variant_access : public std::exception {
786
- public:
787
- virtual const char *what() const noexcept { return "bad_variant_access"; }
788
- };
789
-
790
- [[noreturn]] inline void throw_bad_variant_access() {
791
- #ifdef MPARK_EXCEPTIONS
792
- throw bad_variant_access{};
793
- #else
794
- std::terminate();
795
- #ifdef MPARK_BUILTIN_UNREACHABLE
796
- __builtin_unreachable();
797
- #endif
798
- #endif
799
- }
800
-
801
- template <typename... Ts>
802
- class variant;
803
-
804
- template <typename T>
805
- struct variant_size;
806
-
807
- #ifdef MPARK_VARIABLE_TEMPLATES
808
- template <typename T>
809
- constexpr std::size_t variant_size_v = variant_size<T>::value;
810
- #endif
811
-
812
- template <typename T>
813
- struct variant_size<const T> : variant_size<T> {};
814
-
815
- template <typename T>
816
- struct variant_size<volatile T> : variant_size<T> {};
817
-
818
- template <typename T>
819
- struct variant_size<const volatile T> : variant_size<T> {};
820
-
821
- template <typename... Ts>
822
- struct variant_size<variant<Ts...>> : lib::size_constant<sizeof...(Ts)> {};
823
-
824
- template <std::size_t I, typename T>
825
- struct variant_alternative;
826
-
827
- template <std::size_t I, typename T>
828
- using variant_alternative_t = typename variant_alternative<I, T>::type;
829
-
830
- template <std::size_t I, typename T>
831
- struct variant_alternative<I, const T>
832
- : std::add_const<variant_alternative_t<I, T>> {};
833
-
834
- template <std::size_t I, typename T>
835
- struct variant_alternative<I, volatile T>
836
- : std::add_volatile<variant_alternative_t<I, T>> {};
837
-
838
- template <std::size_t I, typename T>
839
- struct variant_alternative<I, const volatile T>
840
- : std::add_cv<variant_alternative_t<I, T>> {};
841
-
842
- template <std::size_t I, typename... Ts>
843
- struct variant_alternative<I, variant<Ts...>> {
844
- static_assert(I < sizeof...(Ts),
845
- "Index out of bounds in std::variant_alternative<>");
846
- using type = lib::type_pack_element_t<I, Ts...>;
847
- };
848
-
849
- constexpr std::size_t variant_npos = static_cast<std::size_t>(-1);
850
-
851
- namespace detail {
852
-
853
- constexpr std::size_t not_found = static_cast<std::size_t>(-1);
854
- constexpr std::size_t ambiguous = static_cast<std::size_t>(-2);
855
-
856
- #ifdef MPARK_CPP14_CONSTEXPR
857
- template <typename T, typename... Ts>
858
- inline constexpr std::size_t find_index() {
859
- constexpr lib::array<bool, sizeof...(Ts)> matches = {
860
- {std::is_same<T, Ts>::value...}
861
- };
862
- std::size_t result = not_found;
863
- for (std::size_t i = 0; i < sizeof...(Ts); ++i) {
864
- if (matches[i]) {
865
- if (result != not_found) {
866
- return ambiguous;
867
- }
868
- result = i;
869
- }
870
- }
871
- return result;
872
- }
873
- #else
874
- inline constexpr std::size_t find_index_impl(std::size_t result,
875
- std::size_t) {
876
- return result;
877
- }
878
-
879
- template <typename... Bs>
880
- inline constexpr std::size_t find_index_impl(std::size_t result,
881
- std::size_t idx,
882
- bool b,
883
- Bs... bs) {
884
- return b ? (result != not_found ? ambiguous
885
- : find_index_impl(idx, idx + 1, bs...))
886
- : find_index_impl(result, idx + 1, bs...);
887
- }
888
-
889
- template <typename T, typename... Ts>
890
- inline constexpr std::size_t find_index() {
891
- return find_index_impl(not_found, 0, std::is_same<T, Ts>::value...);
892
- }
893
- #endif
894
-
895
- template <std::size_t I>
896
- using find_index_sfinae_impl =
897
- lib::enable_if_t<I != not_found && I != ambiguous,
898
- lib::size_constant<I>>;
899
-
900
- template <typename T, typename... Ts>
901
- using find_index_sfinae = find_index_sfinae_impl<find_index<T, Ts...>()>;
902
-
903
- template <std::size_t I>
904
- struct find_index_checked_impl : lib::size_constant<I> {
905
- static_assert(I != not_found, "the specified type is not found.");
906
- static_assert(I != ambiguous, "the specified type is ambiguous.");
907
- };
908
-
909
- template <typename T, typename... Ts>
910
- using find_index_checked = find_index_checked_impl<find_index<T, Ts...>()>;
911
-
912
- struct valueless_t {};
913
-
914
- enum class Trait { TriviallyAvailable, Available, Unavailable };
915
-
916
- template <typename T,
917
- template <typename> class IsTriviallyAvailable,
918
- template <typename> class IsAvailable>
919
- inline constexpr Trait trait() {
920
- return IsTriviallyAvailable<T>::value
921
- ? Trait::TriviallyAvailable
922
- : IsAvailable<T>::value ? Trait::Available
923
- : Trait::Unavailable;
924
- }
925
-
926
- #ifdef MPARK_CPP14_CONSTEXPR
927
- template <typename... Traits>
928
- inline constexpr Trait common_trait(Traits... traits) {
929
- Trait result = Trait::TriviallyAvailable;
930
- for (Trait t : {traits...}) {
931
- if (static_cast<int>(t) > static_cast<int>(result)) {
932
- result = t;
933
- }
934
- }
935
- return result;
936
- }
937
- #else
938
- inline constexpr Trait common_trait_impl(Trait result) { return result; }
939
-
940
- template <typename... Traits>
941
- inline constexpr Trait common_trait_impl(Trait result,
942
- Trait t,
943
- Traits... ts) {
944
- return static_cast<int>(t) > static_cast<int>(result)
945
- ? common_trait_impl(t, ts...)
946
- : common_trait_impl(result, ts...);
947
- }
948
-
949
- template <typename... Traits>
950
- inline constexpr Trait common_trait(Traits... ts) {
951
- return common_trait_impl(Trait::TriviallyAvailable, ts...);
952
- }
953
- #endif
954
-
955
- template <typename... Ts>
956
- struct traits {
957
- static constexpr Trait copy_constructible_trait =
958
- common_trait(trait<Ts,
959
- lib::is_trivially_copy_constructible,
960
- std::is_copy_constructible>()...);
961
-
962
- static constexpr Trait move_constructible_trait =
963
- common_trait(trait<Ts,
964
- lib::is_trivially_move_constructible,
965
- std::is_move_constructible>()...);
966
-
967
- static constexpr Trait copy_assignable_trait =
968
- common_trait(copy_constructible_trait,
969
- trait<Ts,
970
- lib::is_trivially_copy_assignable,
971
- std::is_copy_assignable>()...);
972
-
973
- static constexpr Trait move_assignable_trait =
974
- common_trait(move_constructible_trait,
975
- trait<Ts,
976
- lib::is_trivially_move_assignable,
977
- std::is_move_assignable>()...);
978
-
979
- static constexpr Trait destructible_trait =
980
- common_trait(trait<Ts,
981
- std::is_trivially_destructible,
982
- std::is_destructible>()...);
983
- };
984
-
985
- namespace access {
986
-
987
- struct recursive_union {
988
- #ifdef MPARK_RETURN_TYPE_DEDUCTION
989
- template <typename V>
990
- inline static constexpr auto &&get_alt(V &&v, in_place_index_t<0>) {
991
- return lib::forward<V>(v).head_;
992
- }
993
-
994
- template <typename V, std::size_t I>
995
- inline static constexpr auto &&get_alt(V &&v, in_place_index_t<I>) {
996
- return get_alt(lib::forward<V>(v).tail_, in_place_index_t<I - 1>{});
997
- }
998
- #else
999
- template <std::size_t I, bool Dummy = true>
1000
- struct get_alt_impl {
1001
- template <typename V>
1002
- inline constexpr AUTO_REFREF operator()(V &&v) const
1003
- AUTO_REFREF_RETURN(get_alt_impl<I - 1>{}(lib::forward<V>(v).tail_))
1004
- };
1005
-
1006
- template <bool Dummy>
1007
- struct get_alt_impl<0, Dummy> {
1008
- template <typename V>
1009
- inline constexpr AUTO_REFREF operator()(V &&v) const
1010
- AUTO_REFREF_RETURN(lib::forward<V>(v).head_)
1011
- };
1012
-
1013
- template <typename V, std::size_t I>
1014
- inline static constexpr AUTO_REFREF get_alt(V &&v, in_place_index_t<I>)
1015
- AUTO_REFREF_RETURN(get_alt_impl<I>{}(lib::forward<V>(v)))
1016
- #endif
1017
- };
1018
-
1019
- struct base {
1020
- template <std::size_t I, typename V>
1021
- inline static constexpr AUTO_REFREF get_alt(V &&v)
1022
- AUTO_REFREF_RETURN(recursive_union::get_alt(
1023
- data(lib::forward<V>(v)), in_place_index_t<I>{}))
1024
- };
1025
-
1026
- struct variant {
1027
- template <std::size_t I, typename V>
1028
- inline static constexpr AUTO_REFREF get_alt(V &&v)
1029
- AUTO_REFREF_RETURN(base::get_alt<I>(lib::forward<V>(v).impl_))
1030
- };
1031
-
1032
- } // namespace access
1033
-
1034
- namespace visitation {
1035
-
1036
- struct base {
1037
- private:
1038
- template <typename T>
1039
- inline static constexpr const T &at(const T &elem) {
1040
- return elem;
1041
- }
1042
-
1043
- template <typename T, std::size_t N, typename... Is>
1044
- inline static constexpr const lib::remove_all_extents_t<T> &at(
1045
- const lib::array<T, N> &elems, std::size_t i, Is... is) {
1046
- return at(elems[i], is...);
1047
- }
1048
-
1049
- template <typename F, typename... Fs>
1050
- inline static constexpr int visit_visitor_return_type_check() {
1051
- static_assert(lib::all<std::is_same<F, Fs>::value...>::value,
1052
- "`mpark::visit` requires the visitor to have a single "
1053
- "return type.");
1054
- return 0;
1055
- }
1056
-
1057
- template <typename... Fs>
1058
- inline static constexpr lib::array<
1059
- lib::common_type_t<lib::decay_t<Fs>...>,
1060
- sizeof...(Fs)>
1061
- make_farray(Fs &&... fs) {
1062
- using result = lib::array<lib::common_type_t<lib::decay_t<Fs>...>,
1063
- sizeof...(Fs)>;
1064
- return visit_visitor_return_type_check<lib::decay_t<Fs>...>(),
1065
- result{{lib::forward<Fs>(fs)...}};
1066
- }
1067
-
1068
- template <std::size_t... Is>
1069
- struct dispatcher {
1070
- template <typename F, typename... Vs>
1071
- struct impl {
1072
- inline static constexpr DECLTYPE_AUTO dispatch(F f, Vs... vs)
1073
- DECLTYPE_AUTO_RETURN(lib::invoke(
1074
- static_cast<F>(f),
1075
- access::base::get_alt<Is>(static_cast<Vs>(vs))...))
1076
- };
1077
- };
1078
-
1079
- template <typename F, typename... Vs, std::size_t... Is>
1080
- inline static constexpr AUTO make_dispatch(lib::index_sequence<Is...>)
1081
- AUTO_RETURN(&dispatcher<Is...>::template impl<F, Vs...>::dispatch)
1082
-
1083
- template <std::size_t I, typename F, typename... Vs>
1084
- inline static constexpr AUTO make_fdiagonal_impl()
1085
- AUTO_RETURN(make_dispatch<F, Vs...>(
1086
- lib::index_sequence<lib::indexed_type<I, Vs>::value...>{}))
1087
-
1088
- template <typename F, typename... Vs, std::size_t... Is>
1089
- inline static constexpr AUTO make_fdiagonal_impl(
1090
- lib::index_sequence<Is...>)
1091
- AUTO_RETURN(make_farray(make_fdiagonal_impl<Is, F, Vs...>()...))
1092
-
1093
- template <typename F, typename V, typename... Vs>
1094
- inline static constexpr /* auto * */ auto make_fdiagonal()
1095
- -> decltype(make_fdiagonal_impl<F, V, Vs...>(
1096
- lib::make_index_sequence<lib::decay_t<V>::size()>{})) {
1097
- static_assert(lib::all<(lib::decay_t<V>::size() ==
1098
- lib::decay_t<Vs>::size())...>::value,
1099
- "all of the variants must be the same size.");
1100
- return make_fdiagonal_impl<F, V, Vs...>(
1101
- lib::make_index_sequence<lib::decay_t<V>::size()>{});
1102
- }
1103
-
1104
- #ifdef MPARK_RETURN_TYPE_DEDUCTION
1105
- template <typename F, typename... Vs, std::size_t... Is>
1106
- inline static constexpr auto make_fmatrix_impl(
1107
- lib::index_sequence<Is...> is) {
1108
- return make_dispatch<F, Vs...>(is);
1109
- }
1110
-
1111
- template <typename F,
1112
- typename... Vs,
1113
- std::size_t... Is,
1114
- std::size_t... Js,
1115
- typename... Ls>
1116
- inline static constexpr auto make_fmatrix_impl(
1117
- lib::index_sequence<Is...>, lib::index_sequence<Js...>, Ls... ls) {
1118
- return make_farray(make_fmatrix_impl<F, Vs...>(
1119
- lib::index_sequence<Is..., Js>{}, ls...)...);
1120
- }
1121
-
1122
- template <typename F, typename... Vs>
1123
- inline static constexpr auto make_fmatrix() {
1124
- return make_fmatrix_impl<F, Vs...>(
1125
- lib::index_sequence<>{},
1126
- lib::make_index_sequence<lib::decay_t<Vs>::size()>{}...);
1127
- }
1128
- #else
1129
- template <typename F, typename... Vs>
1130
- struct make_fmatrix_impl {
1131
- template <typename...>
1132
- struct impl;
1133
-
1134
- template <std::size_t... Is>
1135
- struct impl<lib::index_sequence<Is...>> {
1136
- inline constexpr AUTO operator()() const
1137
- AUTO_RETURN(
1138
- make_dispatch<F, Vs...>(lib::index_sequence<Is...>{}))
1139
- };
1140
-
1141
- template <std::size_t... Is, std::size_t... Js, typename... Ls>
1142
- struct impl<lib::index_sequence<Is...>,
1143
- lib::index_sequence<Js...>,
1144
- Ls...> {
1145
- inline constexpr AUTO operator()() const
1146
- AUTO_RETURN(make_farray(
1147
- impl<lib::index_sequence<Is..., Js>, Ls...>{}()...))
1148
- };
1149
- };
1150
-
1151
- template <typename F, typename... Vs>
1152
- inline static constexpr AUTO make_fmatrix()
1153
- AUTO_RETURN(
1154
- typename make_fmatrix_impl<F, Vs...>::template impl<
1155
- lib::index_sequence<>,
1156
- lib::make_index_sequence<lib::decay_t<Vs>::size()>...>{}())
1157
- #endif
1158
-
1159
- public:
1160
- template <typename Visitor, typename... Vs>
1161
- inline static constexpr DECLTYPE_AUTO visit_alt_at(std::size_t index,
1162
- Visitor &&visitor,
1163
- Vs &&... vs)
1164
- DECLTYPE_AUTO_RETURN(
1165
- at(make_fdiagonal<Visitor &&,
1166
- decltype(as_base(lib::forward<Vs>(vs)))...>(),
1167
- index)(lib::forward<Visitor>(visitor),
1168
- as_base(lib::forward<Vs>(vs))...))
1169
-
1170
- template <typename Visitor, typename... Vs>
1171
- inline static constexpr DECLTYPE_AUTO visit_alt(Visitor &&visitor,
1172
- Vs &&... vs)
1173
- DECLTYPE_AUTO_RETURN(
1174
- at(make_fmatrix<Visitor &&,
1175
- decltype(as_base(lib::forward<Vs>(vs)))...>(),
1176
- vs.index()...)(lib::forward<Visitor>(visitor),
1177
- as_base(lib::forward<Vs>(vs))...))
1178
- };
1179
-
1180
- struct variant {
1181
- private:
1182
- template <typename Visitor, typename... Values>
1183
- struct visit_exhaustive_visitor_check {
1184
- static_assert(
1185
- lib::is_invocable<Visitor, Values...>::value,
1186
- "`mpark::visit` requires the visitor to be exhaustive.");
1187
-
1188
- #ifdef _MSC_VER
1189
- #pragma warning(push)
1190
- #pragma warning(disable : 4100)
1191
- #endif
1192
- inline constexpr DECLTYPE_AUTO operator()(Visitor &&visitor,
1193
- Values &&... values) const
1194
- DECLTYPE_AUTO_RETURN(lib::invoke(lib::forward<Visitor>(visitor),
1195
- lib::forward<Values>(values)...))
1196
- #ifdef _MSC_VER
1197
- #pragma warning(pop)
1198
- #endif
1199
- };
1200
-
1201
- template <typename Visitor>
1202
- struct value_visitor {
1203
- Visitor &&visitor_;
1204
-
1205
- template <typename... Alts>
1206
- inline constexpr DECLTYPE_AUTO operator()(Alts &&... alts) const
1207
- DECLTYPE_AUTO_RETURN(
1208
- visit_exhaustive_visitor_check<
1209
- Visitor,
1210
- decltype((lib::forward<Alts>(alts).value))...>{}(
1211
- lib::forward<Visitor>(visitor_),
1212
- lib::forward<Alts>(alts).value...))
1213
- };
1214
-
1215
- template <typename Visitor>
1216
- inline static constexpr AUTO make_value_visitor(Visitor &&visitor)
1217
- AUTO_RETURN(value_visitor<Visitor>{lib::forward<Visitor>(visitor)})
1218
-
1219
- public:
1220
- template <typename Visitor, typename... Vs>
1221
- inline static constexpr DECLTYPE_AUTO visit_alt_at(std::size_t index,
1222
- Visitor &&visitor,
1223
- Vs &&... vs)
1224
- DECLTYPE_AUTO_RETURN(
1225
- base::visit_alt_at(index,
1226
- lib::forward<Visitor>(visitor),
1227
- lib::forward<Vs>(vs).impl_...))
1228
-
1229
- template <typename Visitor, typename... Vs>
1230
- inline static constexpr DECLTYPE_AUTO visit_alt(Visitor &&visitor,
1231
- Vs &&... vs)
1232
- DECLTYPE_AUTO_RETURN(base::visit_alt(lib::forward<Visitor>(visitor),
1233
- lib::forward<Vs>(vs).impl_...))
1234
-
1235
- template <typename Visitor, typename... Vs>
1236
- inline static constexpr DECLTYPE_AUTO visit_value_at(std::size_t index,
1237
- Visitor &&visitor,
1238
- Vs &&... vs)
1239
- DECLTYPE_AUTO_RETURN(
1240
- visit_alt_at(index,
1241
- make_value_visitor(lib::forward<Visitor>(visitor)),
1242
- lib::forward<Vs>(vs)...))
1243
-
1244
- template <typename Visitor, typename... Vs>
1245
- inline static constexpr DECLTYPE_AUTO visit_value(Visitor &&visitor,
1246
- Vs &&... vs)
1247
- DECLTYPE_AUTO_RETURN(
1248
- visit_alt(make_value_visitor(lib::forward<Visitor>(visitor)),
1249
- lib::forward<Vs>(vs)...))
1250
- };
1251
-
1252
- } // namespace visitation
1253
-
1254
- template <std::size_t Index, typename T>
1255
- struct alt {
1256
- using value_type = T;
1257
-
1258
- #ifdef _MSC_VER
1259
- #pragma warning(push)
1260
- #pragma warning(disable : 4244)
1261
- #endif
1262
- template <typename... Args>
1263
- inline explicit constexpr alt(in_place_t, Args &&... args)
1264
- : value(lib::forward<Args>(args)...) {}
1265
- #ifdef _MSC_VER
1266
- #pragma warning(pop)
1267
- #endif
1268
-
1269
- T value;
1270
- };
1271
-
1272
- template <Trait DestructibleTrait, std::size_t Index, typename... Ts>
1273
- union recursive_union;
1274
-
1275
- template <Trait DestructibleTrait, std::size_t Index>
1276
- union recursive_union<DestructibleTrait, Index> {};
1277
-
1278
- #define MPARK_VARIANT_RECURSIVE_UNION(destructible_trait, destructor) \
1279
- template <std::size_t Index, typename T, typename... Ts> \
1280
- union recursive_union<destructible_trait, Index, T, Ts...> { \
1281
- public: \
1282
- inline explicit constexpr recursive_union(valueless_t) noexcept \
1283
- : dummy_{} {} \
1284
- \
1285
- template <typename... Args> \
1286
- inline explicit constexpr recursive_union(in_place_index_t<0>, \
1287
- Args &&... args) \
1288
- : head_(in_place_t{}, lib::forward<Args>(args)...) {} \
1289
- \
1290
- template <std::size_t I, typename... Args> \
1291
- inline explicit constexpr recursive_union(in_place_index_t<I>, \
1292
- Args &&... args) \
1293
- : tail_(in_place_index_t<I - 1>{}, lib::forward<Args>(args)...) {} \
1294
- \
1295
- recursive_union(const recursive_union &) = default; \
1296
- recursive_union(recursive_union &&) = default; \
1297
- \
1298
- destructor \
1299
- \
1300
- recursive_union &operator=(const recursive_union &) = default; \
1301
- recursive_union &operator=(recursive_union &&) = default; \
1302
- \
1303
- private: \
1304
- char dummy_; \
1305
- alt<Index, T> head_; \
1306
- recursive_union<destructible_trait, Index + 1, Ts...> tail_; \
1307
- \
1308
- friend struct access::recursive_union; \
1309
- }
1310
-
1311
- MPARK_VARIANT_RECURSIVE_UNION(Trait::TriviallyAvailable,
1312
- ~recursive_union() = default;);
1313
- MPARK_VARIANT_RECURSIVE_UNION(Trait::Available,
1314
- ~recursive_union() {});
1315
- MPARK_VARIANT_RECURSIVE_UNION(Trait::Unavailable,
1316
- ~recursive_union() = delete;);
1317
-
1318
- #undef MPARK_VARIANT_RECURSIVE_UNION
1319
-
1320
- using index_t = unsigned int;
1321
-
1322
- template <Trait DestructibleTrait, typename... Ts>
1323
- class base {
1324
- public:
1325
- inline explicit constexpr base(valueless_t tag) noexcept
1326
- : data_(tag), index_(static_cast<index_t>(-1)) {}
1327
-
1328
- template <std::size_t I, typename... Args>
1329
- inline explicit constexpr base(in_place_index_t<I>, Args &&... args)
1330
- : data_(in_place_index_t<I>{}, lib::forward<Args>(args)...),
1331
- index_(I) {}
1332
-
1333
- inline constexpr bool valueless_by_exception() const noexcept {
1334
- return index_ == static_cast<index_t>(-1);
1335
- }
1336
-
1337
- inline constexpr std::size_t index() const noexcept {
1338
- return valueless_by_exception() ? variant_npos : index_;
1339
- }
1340
-
1341
- protected:
1342
- using data_t = recursive_union<DestructibleTrait, 0, Ts...>;
1343
-
1344
- friend inline constexpr base &as_base(base &b) { return b; }
1345
- friend inline constexpr const base &as_base(const base &b) { return b; }
1346
- friend inline constexpr base &&as_base(base &&b) { return lib::move(b); }
1347
- friend inline constexpr const base &&as_base(const base &&b) { return lib::move(b); }
1348
-
1349
- friend inline constexpr data_t &data(base &b) { return b.data_; }
1350
- friend inline constexpr const data_t &data(const base &b) { return b.data_; }
1351
- friend inline constexpr data_t &&data(base &&b) { return lib::move(b).data_; }
1352
- friend inline constexpr const data_t &&data(const base &&b) { return lib::move(b).data_; }
1353
-
1354
- inline static constexpr std::size_t size() { return sizeof...(Ts); }
1355
-
1356
- data_t data_;
1357
- index_t index_;
1358
-
1359
- friend struct access::base;
1360
- friend struct visitation::base;
1361
- };
1362
-
1363
- struct dtor {
1364
- #ifdef _MSC_VER
1365
- #pragma warning(push)
1366
- #pragma warning(disable : 4100)
1367
- #endif
1368
- template <typename Alt>
1369
- inline void operator()(Alt &alt) const noexcept { alt.~Alt(); }
1370
- #ifdef _MSC_VER
1371
- #pragma warning(pop)
1372
- #endif
1373
- };
1374
-
1375
- #if defined(_MSC_VER) && _MSC_VER < 1910
1376
- #define INHERITING_CTOR(type, base) \
1377
- template <typename... Args> \
1378
- inline explicit constexpr type(Args &&... args) \
1379
- : base(lib::forward<Args>(args)...) {}
1380
- #else
1381
- #define INHERITING_CTOR(type, base) using base::base;
1382
- #endif
1383
-
1384
- template <typename Traits, Trait = Traits::destructible_trait>
1385
- class destructor;
1386
-
1387
- #define MPARK_VARIANT_DESTRUCTOR(destructible_trait, definition, destroy) \
1388
- template <typename... Ts> \
1389
- class destructor<traits<Ts...>, destructible_trait> \
1390
- : public base<destructible_trait, Ts...> { \
1391
- using super = base<destructible_trait, Ts...>; \
1392
- \
1393
- public: \
1394
- INHERITING_CTOR(destructor, super) \
1395
- using super::operator=; \
1396
- \
1397
- destructor(const destructor &) = default; \
1398
- destructor(destructor &&) = default; \
1399
- definition \
1400
- destructor &operator=(const destructor &) = default; \
1401
- destructor &operator=(destructor &&) = default; \
1402
- \
1403
- protected: \
1404
- destroy \
1405
- }
1406
-
1407
- MPARK_VARIANT_DESTRUCTOR(
1408
- Trait::TriviallyAvailable,
1409
- ~destructor() = default;,
1410
- inline void destroy() noexcept {
1411
- this->index_ = static_cast<index_t>(-1);
1412
- });
1413
-
1414
- MPARK_VARIANT_DESTRUCTOR(
1415
- Trait::Available,
1416
- ~destructor() { destroy(); },
1417
- inline void destroy() noexcept {
1418
- if (!this->valueless_by_exception()) {
1419
- visitation::base::visit_alt(dtor{}, *this);
1420
- }
1421
- this->index_ = static_cast<index_t>(-1);
1422
- });
1423
-
1424
- MPARK_VARIANT_DESTRUCTOR(
1425
- Trait::Unavailable,
1426
- ~destructor() = delete;,
1427
- inline void destroy() noexcept = delete;);
1428
-
1429
- #undef MPARK_VARIANT_DESTRUCTOR
1430
-
1431
- template <typename Traits>
1432
- class constructor : public destructor<Traits> {
1433
- using super = destructor<Traits>;
1434
-
1435
- public:
1436
- INHERITING_CTOR(constructor, super)
1437
- using super::operator=;
1438
-
1439
- protected:
1440
- #ifndef MPARK_GENERIC_LAMBDAS
1441
- struct ctor {
1442
- template <typename LhsAlt, typename RhsAlt>
1443
- inline void operator()(LhsAlt &lhs_alt, RhsAlt &&rhs_alt) const {
1444
- constructor::construct_alt(lhs_alt,
1445
- lib::forward<RhsAlt>(rhs_alt).value);
1446
- }
1447
- };
1448
- #endif
1449
-
1450
- template <std::size_t I, typename T, typename... Args>
1451
- inline static T &construct_alt(alt<I, T> &a, Args &&... args) {
1452
- ::new (static_cast<void *>(lib::addressof(a)))
1453
- alt<I, T>(in_place_t{}, lib::forward<Args>(args)...);
1454
- return a.value;
1455
- }
1456
-
1457
- template <typename Rhs>
1458
- inline static void generic_construct(constructor &lhs, Rhs &&rhs) {
1459
- lhs.destroy();
1460
- if (!rhs.valueless_by_exception()) {
1461
- visitation::base::visit_alt_at(
1462
- rhs.index(),
1463
- #ifdef MPARK_GENERIC_LAMBDAS
1464
- [](auto &lhs_alt, auto &&rhs_alt) {
1465
- constructor::construct_alt(
1466
- lhs_alt, lib::forward<decltype(rhs_alt)>(rhs_alt).value);
1467
- }
1468
- #else
1469
- ctor{}
1470
- #endif
1471
- ,
1472
- lhs,
1473
- lib::forward<Rhs>(rhs));
1474
- lhs.index_ = rhs.index_;
1475
- }
1476
- }
1477
- };
1478
-
1479
- template <typename Traits, Trait = Traits::move_constructible_trait>
1480
- class move_constructor;
1481
-
1482
- #define MPARK_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait, definition) \
1483
- template <typename... Ts> \
1484
- class move_constructor<traits<Ts...>, move_constructible_trait> \
1485
- : public constructor<traits<Ts...>> { \
1486
- using super = constructor<traits<Ts...>>; \
1487
- \
1488
- public: \
1489
- INHERITING_CTOR(move_constructor, super) \
1490
- using super::operator=; \
1491
- \
1492
- move_constructor(const move_constructor &) = default; \
1493
- definition \
1494
- ~move_constructor() = default; \
1495
- move_constructor &operator=(const move_constructor &) = default; \
1496
- move_constructor &operator=(move_constructor &&) = default; \
1497
- }
1498
-
1499
- MPARK_VARIANT_MOVE_CONSTRUCTOR(
1500
- Trait::TriviallyAvailable,
1501
- move_constructor(move_constructor &&that) = default;);
1502
-
1503
- MPARK_VARIANT_MOVE_CONSTRUCTOR(
1504
- Trait::Available,
1505
- move_constructor(move_constructor &&that) noexcept(
1506
- lib::all<std::is_nothrow_move_constructible<Ts>::value...>::value)
1507
- : move_constructor(valueless_t{}) {
1508
- this->generic_construct(*this, lib::move(that));
1509
- });
1510
-
1511
- MPARK_VARIANT_MOVE_CONSTRUCTOR(
1512
- Trait::Unavailable,
1513
- move_constructor(move_constructor &&) = delete;);
1514
-
1515
- #undef MPARK_VARIANT_MOVE_CONSTRUCTOR
1516
-
1517
- template <typename Traits, Trait = Traits::copy_constructible_trait>
1518
- class copy_constructor;
1519
-
1520
- #define MPARK_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait, definition) \
1521
- template <typename... Ts> \
1522
- class copy_constructor<traits<Ts...>, copy_constructible_trait> \
1523
- : public move_constructor<traits<Ts...>> { \
1524
- using super = move_constructor<traits<Ts...>>; \
1525
- \
1526
- public: \
1527
- INHERITING_CTOR(copy_constructor, super) \
1528
- using super::operator=; \
1529
- \
1530
- definition \
1531
- copy_constructor(copy_constructor &&) = default; \
1532
- ~copy_constructor() = default; \
1533
- copy_constructor &operator=(const copy_constructor &) = default; \
1534
- copy_constructor &operator=(copy_constructor &&) = default; \
1535
- }
1536
-
1537
- MPARK_VARIANT_COPY_CONSTRUCTOR(
1538
- Trait::TriviallyAvailable,
1539
- copy_constructor(const copy_constructor &that) = default;);
1540
-
1541
- MPARK_VARIANT_COPY_CONSTRUCTOR(
1542
- Trait::Available,
1543
- copy_constructor(const copy_constructor &that)
1544
- : copy_constructor(valueless_t{}) {
1545
- this->generic_construct(*this, that);
1546
- });
1547
-
1548
- MPARK_VARIANT_COPY_CONSTRUCTOR(
1549
- Trait::Unavailable,
1550
- copy_constructor(const copy_constructor &) = delete;);
1551
-
1552
- #undef MPARK_VARIANT_COPY_CONSTRUCTOR
1553
-
1554
- template <typename Traits>
1555
- class assignment : public copy_constructor<Traits> {
1556
- using super = copy_constructor<Traits>;
1557
-
1558
- public:
1559
- INHERITING_CTOR(assignment, super)
1560
- using super::operator=;
1561
-
1562
- template <std::size_t I, typename... Args>
1563
- inline /* auto & */ auto emplace(Args &&... args)
1564
- -> decltype(this->construct_alt(access::base::get_alt<I>(*this),
1565
- lib::forward<Args>(args)...)) {
1566
- this->destroy();
1567
- auto &result = this->construct_alt(access::base::get_alt<I>(*this),
1568
- lib::forward<Args>(args)...);
1569
- this->index_ = I;
1570
- return result;
1571
- }
1572
-
1573
- protected:
1574
- #ifndef MPARK_GENERIC_LAMBDAS
1575
- template <typename That>
1576
- struct assigner {
1577
- template <typename ThisAlt, typename ThatAlt>
1578
- inline void operator()(ThisAlt &this_alt, ThatAlt &&that_alt) const {
1579
- self->assign_alt(this_alt, lib::forward<ThatAlt>(that_alt).value);
1580
- }
1581
- assignment *self;
1582
- };
1583
- #endif
1584
-
1585
- template <std::size_t I, typename T, typename Arg>
1586
- inline void assign_alt(alt<I, T> &a, Arg &&arg) {
1587
- if (this->index() == I) {
1588
- #ifdef _MSC_VER
1589
- #pragma warning(push)
1590
- #pragma warning(disable : 4244)
1591
- #endif
1592
- a.value = lib::forward<Arg>(arg);
1593
- #ifdef _MSC_VER
1594
- #pragma warning(pop)
1595
- #endif
1596
- } else {
1597
- struct {
1598
- void operator()(std::true_type) const {
1599
- this_->emplace<I>(lib::forward<Arg>(arg_));
1600
- }
1601
- void operator()(std::false_type) const {
1602
- this_->emplace<I>(T(lib::forward<Arg>(arg_)));
1603
- }
1604
- assignment *this_;
1605
- Arg &&arg_;
1606
- } impl{this, lib::forward<Arg>(arg)};
1607
- impl(lib::bool_constant<
1608
- std::is_nothrow_constructible<T, Arg>::value ||
1609
- !std::is_nothrow_move_constructible<T>::value>{});
1610
- }
1611
- }
1612
-
1613
- template <typename That>
1614
- inline void generic_assign(That &&that) {
1615
- if (this->valueless_by_exception() && that.valueless_by_exception()) {
1616
- // do nothing.
1617
- } else if (that.valueless_by_exception()) {
1618
- this->destroy();
1619
- } else {
1620
- visitation::base::visit_alt_at(
1621
- that.index(),
1622
- #ifdef MPARK_GENERIC_LAMBDAS
1623
- [this](auto &this_alt, auto &&that_alt) {
1624
- this->assign_alt(
1625
- this_alt, lib::forward<decltype(that_alt)>(that_alt).value);
1626
- }
1627
- #else
1628
- assigner<That>{this}
1629
- #endif
1630
- ,
1631
- *this,
1632
- lib::forward<That>(that));
1633
- }
1634
- }
1635
- };
1636
-
1637
- template <typename Traits, Trait = Traits::move_assignable_trait>
1638
- class move_assignment;
1639
-
1640
- #define MPARK_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait, definition) \
1641
- template <typename... Ts> \
1642
- class move_assignment<traits<Ts...>, move_assignable_trait> \
1643
- : public assignment<traits<Ts...>> { \
1644
- using super = assignment<traits<Ts...>>; \
1645
- \
1646
- public: \
1647
- INHERITING_CTOR(move_assignment, super) \
1648
- using super::operator=; \
1649
- \
1650
- move_assignment(const move_assignment &) = default; \
1651
- move_assignment(move_assignment &&) = default; \
1652
- ~move_assignment() = default; \
1653
- move_assignment &operator=(const move_assignment &) = default; \
1654
- definition \
1655
- }
1656
-
1657
- MPARK_VARIANT_MOVE_ASSIGNMENT(
1658
- Trait::TriviallyAvailable,
1659
- move_assignment &operator=(move_assignment &&that) = default;);
1660
-
1661
- MPARK_VARIANT_MOVE_ASSIGNMENT(
1662
- Trait::Available,
1663
- move_assignment &
1664
- operator=(move_assignment &&that) noexcept(
1665
- lib::all<(std::is_nothrow_move_constructible<Ts>::value &&
1666
- std::is_nothrow_move_assignable<Ts>::value)...>::value) {
1667
- this->generic_assign(lib::move(that));
1668
- return *this;
1669
- });
1670
-
1671
- MPARK_VARIANT_MOVE_ASSIGNMENT(
1672
- Trait::Unavailable,
1673
- move_assignment &operator=(move_assignment &&) = delete;);
1674
-
1675
- #undef MPARK_VARIANT_MOVE_ASSIGNMENT
1676
-
1677
- template <typename Traits, Trait = Traits::copy_assignable_trait>
1678
- class copy_assignment;
1679
-
1680
- #define MPARK_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait, definition) \
1681
- template <typename... Ts> \
1682
- class copy_assignment<traits<Ts...>, copy_assignable_trait> \
1683
- : public move_assignment<traits<Ts...>> { \
1684
- using super = move_assignment<traits<Ts...>>; \
1685
- \
1686
- public: \
1687
- INHERITING_CTOR(copy_assignment, super) \
1688
- using super::operator=; \
1689
- \
1690
- copy_assignment(const copy_assignment &) = default; \
1691
- copy_assignment(copy_assignment &&) = default; \
1692
- ~copy_assignment() = default; \
1693
- definition \
1694
- copy_assignment &operator=(copy_assignment &&) = default; \
1695
- }
1696
-
1697
- MPARK_VARIANT_COPY_ASSIGNMENT(
1698
- Trait::TriviallyAvailable,
1699
- copy_assignment &operator=(const copy_assignment &that) = default;);
1700
-
1701
- MPARK_VARIANT_COPY_ASSIGNMENT(
1702
- Trait::Available,
1703
- copy_assignment &operator=(const copy_assignment &that) {
1704
- this->generic_assign(that);
1705
- return *this;
1706
- });
1707
-
1708
- MPARK_VARIANT_COPY_ASSIGNMENT(
1709
- Trait::Unavailable,
1710
- copy_assignment &operator=(const copy_assignment &) = delete;);
1711
-
1712
- #undef MPARK_VARIANT_COPY_ASSIGNMENT
1713
-
1714
- template <typename... Ts>
1715
- class impl : public copy_assignment<traits<Ts...>> {
1716
- using super = copy_assignment<traits<Ts...>>;
1717
-
1718
- public:
1719
- INHERITING_CTOR(impl, super)
1720
- using super::operator=;
1721
-
1722
- template <std::size_t I, typename Arg>
1723
- inline void assign(Arg &&arg) {
1724
- this->assign_alt(access::base::get_alt<I>(*this),
1725
- lib::forward<Arg>(arg));
1726
- }
1727
-
1728
- inline void swap(impl &that) {
1729
- if (this->valueless_by_exception() && that.valueless_by_exception()) {
1730
- // do nothing.
1731
- } else if (this->index() == that.index()) {
1732
- visitation::base::visit_alt_at(this->index(),
1733
- #ifdef MPARK_GENERIC_LAMBDAS
1734
- [](auto &this_alt, auto &that_alt) {
1735
- using std::swap;
1736
- swap(this_alt.value,
1737
- that_alt.value);
1738
- }
1739
- #else
1740
- swapper{}
1741
- #endif
1742
- ,
1743
- *this,
1744
- that);
1745
- } else {
1746
- impl *lhs = this;
1747
- impl *rhs = lib::addressof(that);
1748
- if (lhs->move_nothrow() && !rhs->move_nothrow()) {
1749
- std::swap(lhs, rhs);
1750
- }
1751
- impl tmp(lib::move(*rhs));
1752
- #ifdef MPARK_EXCEPTIONS
1753
- // EXTENSION: When the move construction of `lhs` into `rhs` throws
1754
- // and `tmp` is nothrow move constructible then we move `tmp` back
1755
- // into `rhs` and provide the strong exception safety guarantee.
1756
- try {
1757
- this->generic_construct(*rhs, lib::move(*lhs));
1758
- } catch (...) {
1759
- if (tmp.move_nothrow()) {
1760
- this->generic_construct(*rhs, lib::move(tmp));
1761
- }
1762
- throw;
1763
- }
1764
- #else
1765
- this->generic_construct(*rhs, lib::move(*lhs));
1766
- #endif
1767
- this->generic_construct(*lhs, lib::move(tmp));
1768
- }
1769
- }
1770
-
1771
- private:
1772
- #ifndef MPARK_GENERIC_LAMBDAS
1773
- struct swapper {
1774
- template <typename ThisAlt, typename ThatAlt>
1775
- inline void operator()(ThisAlt &this_alt, ThatAlt &that_alt) const {
1776
- using std::swap;
1777
- swap(this_alt.value, that_alt.value);
1778
- }
1779
- };
1780
- #endif
1781
-
1782
- inline constexpr bool move_nothrow() const {
1783
- return this->valueless_by_exception() ||
1784
- lib::array<bool, sizeof...(Ts)>{
1785
- {std::is_nothrow_move_constructible<Ts>::value...}
1786
- }[this->index()];
1787
- }
1788
- };
1789
-
1790
- template <std::size_t I, typename T>
1791
- struct overload_leaf {
1792
- using F = lib::size_constant<I> (*)(T);
1793
- operator F() const { return nullptr; }
1794
- };
1795
-
1796
- template <typename... Ts>
1797
- struct overload_impl {
1798
- private:
1799
- template <typename>
1800
- struct impl;
1801
-
1802
- template <std::size_t... Is>
1803
- struct impl<lib::index_sequence<Is...>> : overload_leaf<Is, Ts>... {};
1804
-
1805
- public:
1806
- using type = impl<lib::index_sequence_for<Ts...>>;
1807
- };
1808
-
1809
- template <typename... Ts>
1810
- using overload = typename overload_impl<Ts...>::type;
1811
-
1812
- template <typename T, typename... Ts>
1813
- using best_match = lib::invoke_result_t<overload<Ts...>, T &&>;
1814
-
1815
- template <typename T>
1816
- struct is_in_place_index : std::false_type {};
1817
-
1818
- template <std::size_t I>
1819
- struct is_in_place_index<in_place_index_t<I>> : std::true_type {};
1820
-
1821
- template <typename T>
1822
- struct is_in_place_type : std::false_type {};
1823
-
1824
- template <typename T>
1825
- struct is_in_place_type<in_place_type_t<T>> : std::true_type {};
1826
-
1827
- } // detail
1828
-
1829
- template <typename... Ts>
1830
- class variant {
1831
- static_assert(0 < sizeof...(Ts),
1832
- "variant must consist of at least one alternative.");
1833
-
1834
- static_assert(lib::all<!std::is_array<Ts>::value...>::value,
1835
- "variant can not have an array type as an alternative.");
1836
-
1837
- static_assert(lib::all<!std::is_reference<Ts>::value...>::value,
1838
- "variant can not have a reference type as an alternative.");
1839
-
1840
- static_assert(lib::all<!std::is_void<Ts>::value...>::value,
1841
- "variant can not have a void type as an alternative.");
1842
-
1843
- public:
1844
- template <
1845
- typename Front = lib::type_pack_element_t<0, Ts...>,
1846
- lib::enable_if_t<std::is_default_constructible<Front>::value, int> = 0>
1847
- inline constexpr variant() noexcept(
1848
- std::is_nothrow_default_constructible<Front>::value)
1849
- : impl_(in_place_index_t<0>{}) {}
1850
-
1851
- variant(const variant &) = default;
1852
- variant(variant &&) = default;
1853
-
1854
- template <
1855
- typename Arg,
1856
- typename Decayed = lib::decay_t<Arg>,
1857
- lib::enable_if_t<!std::is_same<Decayed, variant>::value, int> = 0,
1858
- lib::enable_if_t<!detail::is_in_place_index<Decayed>::value, int> = 0,
1859
- lib::enable_if_t<!detail::is_in_place_type<Decayed>::value, int> = 0,
1860
- std::size_t I = detail::best_match<Arg, Ts...>::value,
1861
- typename T = lib::type_pack_element_t<I, Ts...>,
1862
- lib::enable_if_t<std::is_constructible<T, Arg>::value, int> = 0>
1863
- inline constexpr variant(Arg &&arg) noexcept(
1864
- std::is_nothrow_constructible<T, Arg>::value)
1865
- : impl_(in_place_index_t<I>{}, lib::forward<Arg>(arg)) {}
1866
-
1867
- template <
1868
- std::size_t I,
1869
- typename... Args,
1870
- typename T = lib::type_pack_element_t<I, Ts...>,
1871
- lib::enable_if_t<std::is_constructible<T, Args...>::value, int> = 0>
1872
- inline explicit constexpr variant(
1873
- in_place_index_t<I>,
1874
- Args &&... args) noexcept(std::is_nothrow_constructible<T,
1875
- Args...>::value)
1876
- : impl_(in_place_index_t<I>{}, lib::forward<Args>(args)...) {}
1877
-
1878
- template <
1879
- std::size_t I,
1880
- typename Up,
1881
- typename... Args,
1882
- typename T = lib::type_pack_element_t<I, Ts...>,
1883
- lib::enable_if_t<std::is_constructible<T,
1884
- std::initializer_list<Up> &,
1885
- Args...>::value,
1886
- int> = 0>
1887
- inline explicit constexpr variant(
1888
- in_place_index_t<I>,
1889
- std::initializer_list<Up> il,
1890
- Args &&... args) noexcept(std::
1891
- is_nothrow_constructible<
1892
- T,
1893
- std::initializer_list<Up> &,
1894
- Args...>::value)
1895
- : impl_(in_place_index_t<I>{}, il, lib::forward<Args>(args)...) {}
1896
-
1897
- template <
1898
- typename T,
1899
- typename... Args,
1900
- std::size_t I = detail::find_index_sfinae<T, Ts...>::value,
1901
- lib::enable_if_t<std::is_constructible<T, Args...>::value, int> = 0>
1902
- inline explicit constexpr variant(
1903
- in_place_type_t<T>,
1904
- Args &&... args) noexcept(std::is_nothrow_constructible<T,
1905
- Args...>::value)
1906
- : impl_(in_place_index_t<I>{}, lib::forward<Args>(args)...) {}
1907
-
1908
- template <
1909
- typename T,
1910
- typename Up,
1911
- typename... Args,
1912
- std::size_t I = detail::find_index_sfinae<T, Ts...>::value,
1913
- lib::enable_if_t<std::is_constructible<T,
1914
- std::initializer_list<Up> &,
1915
- Args...>::value,
1916
- int> = 0>
1917
- inline explicit constexpr variant(
1918
- in_place_type_t<T>,
1919
- std::initializer_list<Up> il,
1920
- Args &&... args) noexcept(std::
1921
- is_nothrow_constructible<
1922
- T,
1923
- std::initializer_list<Up> &,
1924
- Args...>::value)
1925
- : impl_(in_place_index_t<I>{}, il, lib::forward<Args>(args)...) {}
1926
-
1927
- ~variant() = default;
1928
-
1929
- variant &operator=(const variant &) = default;
1930
- variant &operator=(variant &&) = default;
1931
-
1932
- template <typename Arg,
1933
- lib::enable_if_t<!std::is_same<lib::decay_t<Arg>, variant>::value,
1934
- int> = 0,
1935
- std::size_t I = detail::best_match<Arg, Ts...>::value,
1936
- typename T = lib::type_pack_element_t<I, Ts...>,
1937
- lib::enable_if_t<(std::is_assignable<T &, Arg>::value &&
1938
- std::is_constructible<T, Arg>::value),
1939
- int> = 0>
1940
- inline variant &operator=(Arg &&arg) noexcept(
1941
- (std::is_nothrow_assignable<T &, Arg>::value &&
1942
- std::is_nothrow_constructible<T, Arg>::value)) {
1943
- impl_.template assign<I>(lib::forward<Arg>(arg));
1944
- return *this;
1945
- }
1946
-
1947
- template <
1948
- std::size_t I,
1949
- typename... Args,
1950
- typename T = lib::type_pack_element_t<I, Ts...>,
1951
- lib::enable_if_t<std::is_constructible<T, Args...>::value, int> = 0>
1952
- inline T &emplace(Args &&... args) {
1953
- return impl_.template emplace<I>(lib::forward<Args>(args)...);
1954
- }
1955
-
1956
- template <
1957
- std::size_t I,
1958
- typename Up,
1959
- typename... Args,
1960
- typename T = lib::type_pack_element_t<I, Ts...>,
1961
- lib::enable_if_t<std::is_constructible<T,
1962
- std::initializer_list<Up> &,
1963
- Args...>::value,
1964
- int> = 0>
1965
- inline T &emplace(std::initializer_list<Up> il, Args &&... args) {
1966
- return impl_.template emplace<I>(il, lib::forward<Args>(args)...);
1967
- }
1968
-
1969
- template <
1970
- typename T,
1971
- typename... Args,
1972
- std::size_t I = detail::find_index_sfinae<T, Ts...>::value,
1973
- lib::enable_if_t<std::is_constructible<T, Args...>::value, int> = 0>
1974
- inline T &emplace(Args &&... args) {
1975
- return impl_.template emplace<I>(lib::forward<Args>(args)...);
1976
- }
1977
-
1978
- template <
1979
- typename T,
1980
- typename Up,
1981
- typename... Args,
1982
- std::size_t I = detail::find_index_sfinae<T, Ts...>::value,
1983
- lib::enable_if_t<std::is_constructible<T,
1984
- std::initializer_list<Up> &,
1985
- Args...>::value,
1986
- int> = 0>
1987
- inline T &emplace(std::initializer_list<Up> il, Args &&... args) {
1988
- return impl_.template emplace<I>(il, lib::forward<Args>(args)...);
1989
- }
1990
-
1991
- inline constexpr bool valueless_by_exception() const noexcept {
1992
- return impl_.valueless_by_exception();
1993
- }
1994
-
1995
- inline constexpr std::size_t index() const noexcept {
1996
- return impl_.index();
1997
- }
1998
-
1999
- template <
2000
- bool Dummy = true,
2001
- lib::enable_if_t<lib::all<Dummy,
2002
- (std::is_move_constructible<Ts>::value &&
2003
- lib::is_swappable<Ts>::value)...>::value,
2004
- int> = 0>
2005
- inline void swap(variant &that) noexcept(
2006
- lib::all<(std::is_nothrow_move_constructible<Ts>::value &&
2007
- lib::is_nothrow_swappable<Ts>::value)...>::value) {
2008
- impl_.swap(that.impl_);
2009
- }
2010
-
2011
- private:
2012
- detail::impl<Ts...> impl_;
2013
-
2014
- friend struct detail::access::variant;
2015
- friend struct detail::visitation::variant;
2016
- };
2017
-
2018
- template <std::size_t I, typename... Ts>
2019
- inline constexpr bool holds_alternative(const variant<Ts...> &v) noexcept {
2020
- return v.index() == I;
2021
- }
2022
-
2023
- template <typename T, typename... Ts>
2024
- inline constexpr bool holds_alternative(const variant<Ts...> &v) noexcept {
2025
- return holds_alternative<detail::find_index_checked<T, Ts...>::value>(v);
2026
- }
2027
-
2028
- namespace detail {
2029
- template <std::size_t I, typename V>
2030
- struct generic_get_impl {
2031
- constexpr generic_get_impl(int) {}
2032
-
2033
- constexpr AUTO_REFREF operator()(V &&v) const
2034
- AUTO_REFREF_RETURN(
2035
- access::variant::get_alt<I>(lib::forward<V>(v)).value)
2036
- };
2037
-
2038
- template <std::size_t I, typename V>
2039
- inline constexpr AUTO_REFREF generic_get(V &&v)
2040
- AUTO_REFREF_RETURN(generic_get_impl<I, V>(
2041
- holds_alternative<I>(v) ? 0 : (throw_bad_variant_access(), 0))(
2042
- lib::forward<V>(v)))
2043
- } // namespace detail
2044
-
2045
- template <std::size_t I, typename... Ts>
2046
- inline constexpr variant_alternative_t<I, variant<Ts...>> &get(
2047
- variant<Ts...> &v) {
2048
- return detail::generic_get<I>(v);
2049
- }
2050
-
2051
- template <std::size_t I, typename... Ts>
2052
- inline constexpr variant_alternative_t<I, variant<Ts...>> &&get(
2053
- variant<Ts...> &&v) {
2054
- return detail::generic_get<I>(lib::move(v));
2055
- }
2056
-
2057
- template <std::size_t I, typename... Ts>
2058
- inline constexpr const variant_alternative_t<I, variant<Ts...>> &get(
2059
- const variant<Ts...> &v) {
2060
- return detail::generic_get<I>(v);
2061
- }
2062
-
2063
- template <std::size_t I, typename... Ts>
2064
- inline constexpr const variant_alternative_t<I, variant<Ts...>> &&get(
2065
- const variant<Ts...> &&v) {
2066
- return detail::generic_get<I>(lib::move(v));
2067
- }
2068
-
2069
- template <typename T, typename... Ts>
2070
- inline constexpr T &get(variant<Ts...> &v) {
2071
- return get<detail::find_index_checked<T, Ts...>::value>(v);
2072
- }
2073
-
2074
- template <typename T, typename... Ts>
2075
- inline constexpr T &&get(variant<Ts...> &&v) {
2076
- return get<detail::find_index_checked<T, Ts...>::value>(lib::move(v));
2077
- }
2078
-
2079
- template <typename T, typename... Ts>
2080
- inline constexpr const T &get(const variant<Ts...> &v) {
2081
- return get<detail::find_index_checked<T, Ts...>::value>(v);
2082
- }
2083
-
2084
- template <typename T, typename... Ts>
2085
- inline constexpr const T &&get(const variant<Ts...> &&v) {
2086
- return get<detail::find_index_checked<T, Ts...>::value>(lib::move(v));
2087
- }
2088
-
2089
- namespace detail {
2090
-
2091
- template <std::size_t I, typename V>
2092
- inline constexpr /* auto * */ AUTO generic_get_if(V *v) noexcept
2093
- AUTO_RETURN(v && holds_alternative<I>(*v)
2094
- ? lib::addressof(access::variant::get_alt<I>(*v).value)
2095
- : nullptr)
2096
-
2097
- } // namespace detail
2098
-
2099
- template <std::size_t I, typename... Ts>
2100
- inline constexpr lib::add_pointer_t<variant_alternative_t<I, variant<Ts...>>>
2101
- get_if(variant<Ts...> *v) noexcept {
2102
- return detail::generic_get_if<I>(v);
2103
- }
2104
-
2105
- template <std::size_t I, typename... Ts>
2106
- inline constexpr lib::add_pointer_t<
2107
- const variant_alternative_t<I, variant<Ts...>>>
2108
- get_if(const variant<Ts...> *v) noexcept {
2109
- return detail::generic_get_if<I>(v);
2110
- }
2111
-
2112
- template <typename T, typename... Ts>
2113
- inline constexpr lib::add_pointer_t<T>
2114
- get_if(variant<Ts...> *v) noexcept {
2115
- return get_if<detail::find_index_checked<T, Ts...>::value>(v);
2116
- }
2117
-
2118
- template <typename T, typename... Ts>
2119
- inline constexpr lib::add_pointer_t<const T>
2120
- get_if(const variant<Ts...> *v) noexcept {
2121
- return get_if<detail::find_index_checked<T, Ts...>::value>(v);
2122
- }
2123
-
2124
- template <typename... Ts>
2125
- inline constexpr bool operator==(const variant<Ts...> &lhs,
2126
- const variant<Ts...> &rhs) {
2127
- using detail::visitation::variant;
2128
- using lib::equal_to;
2129
- #ifdef MPARK_CPP14_CONSTEXPR
2130
- if (lhs.index() != rhs.index()) return false;
2131
- if (lhs.valueless_by_exception()) return true;
2132
- return variant::visit_value_at(lhs.index(), equal_to{}, lhs, rhs);
2133
- #else
2134
- return lhs.index() == rhs.index() &&
2135
- (lhs.valueless_by_exception() ||
2136
- variant::visit_value_at(lhs.index(), equal_to{}, lhs, rhs));
2137
- #endif
2138
- }
2139
-
2140
- template <typename... Ts>
2141
- inline constexpr bool operator!=(const variant<Ts...> &lhs,
2142
- const variant<Ts...> &rhs) {
2143
- using detail::visitation::variant;
2144
- using lib::not_equal_to;
2145
- #ifdef MPARK_CPP14_CONSTEXPR
2146
- if (lhs.index() != rhs.index()) return true;
2147
- if (lhs.valueless_by_exception()) return false;
2148
- return variant::visit_value_at(lhs.index(), not_equal_to{}, lhs, rhs);
2149
- #else
2150
- return lhs.index() != rhs.index() ||
2151
- (!lhs.valueless_by_exception() &&
2152
- variant::visit_value_at(lhs.index(), not_equal_to{}, lhs, rhs));
2153
- #endif
2154
- }
2155
-
2156
- template <typename... Ts>
2157
- inline constexpr bool operator<(const variant<Ts...> &lhs,
2158
- const variant<Ts...> &rhs) {
2159
- using detail::visitation::variant;
2160
- using lib::less;
2161
- #ifdef MPARK_CPP14_CONSTEXPR
2162
- if (rhs.valueless_by_exception()) return false;
2163
- if (lhs.valueless_by_exception()) return true;
2164
- if (lhs.index() < rhs.index()) return true;
2165
- if (lhs.index() > rhs.index()) return false;
2166
- return variant::visit_value_at(lhs.index(), less{}, lhs, rhs);
2167
- #else
2168
- return !rhs.valueless_by_exception() &&
2169
- (lhs.valueless_by_exception() || lhs.index() < rhs.index() ||
2170
- (lhs.index() == rhs.index() &&
2171
- variant::visit_value_at(lhs.index(), less{}, lhs, rhs)));
2172
- #endif
2173
- }
2174
-
2175
- template <typename... Ts>
2176
- inline constexpr bool operator>(const variant<Ts...> &lhs,
2177
- const variant<Ts...> &rhs) {
2178
- using detail::visitation::variant;
2179
- using lib::greater;
2180
- #ifdef MPARK_CPP14_CONSTEXPR
2181
- if (lhs.valueless_by_exception()) return false;
2182
- if (rhs.valueless_by_exception()) return true;
2183
- if (lhs.index() > rhs.index()) return true;
2184
- if (lhs.index() < rhs.index()) return false;
2185
- return variant::visit_value_at(lhs.index(), greater{}, lhs, rhs);
2186
- #else
2187
- return !lhs.valueless_by_exception() &&
2188
- (rhs.valueless_by_exception() || lhs.index() > rhs.index() ||
2189
- (lhs.index() == rhs.index() &&
2190
- variant::visit_value_at(lhs.index(), greater{}, lhs, rhs)));
2191
- #endif
2192
- }
2193
-
2194
- template <typename... Ts>
2195
- inline constexpr bool operator<=(const variant<Ts...> &lhs,
2196
- const variant<Ts...> &rhs) {
2197
- using detail::visitation::variant;
2198
- using lib::less_equal;
2199
- #ifdef MPARK_CPP14_CONSTEXPR
2200
- if (lhs.valueless_by_exception()) return true;
2201
- if (rhs.valueless_by_exception()) return false;
2202
- if (lhs.index() < rhs.index()) return true;
2203
- if (lhs.index() > rhs.index()) return false;
2204
- return variant::visit_value_at(lhs.index(), less_equal{}, lhs, rhs);
2205
- #else
2206
- return lhs.valueless_by_exception() ||
2207
- (!rhs.valueless_by_exception() &&
2208
- (lhs.index() < rhs.index() ||
2209
- (lhs.index() == rhs.index() &&
2210
- variant::visit_value_at(lhs.index(), less_equal{}, lhs, rhs))));
2211
- #endif
2212
- }
2213
-
2214
- template <typename... Ts>
2215
- inline constexpr bool operator>=(const variant<Ts...> &lhs,
2216
- const variant<Ts...> &rhs) {
2217
- using detail::visitation::variant;
2218
- using lib::greater_equal;
2219
- #ifdef MPARK_CPP14_CONSTEXPR
2220
- if (rhs.valueless_by_exception()) return true;
2221
- if (lhs.valueless_by_exception()) return false;
2222
- if (lhs.index() > rhs.index()) return true;
2223
- if (lhs.index() < rhs.index()) return false;
2224
- return variant::visit_value_at(lhs.index(), greater_equal{}, lhs, rhs);
2225
- #else
2226
- return rhs.valueless_by_exception() ||
2227
- (!lhs.valueless_by_exception() &&
2228
- (lhs.index() > rhs.index() ||
2229
- (lhs.index() == rhs.index() &&
2230
- variant::visit_value_at(
2231
- lhs.index(), greater_equal{}, lhs, rhs))));
2232
- #endif
2233
- }
2234
-
2235
- struct monostate {};
2236
-
2237
- inline constexpr bool operator<(monostate, monostate) noexcept {
2238
- return false;
2239
- }
2240
-
2241
- inline constexpr bool operator>(monostate, monostate) noexcept {
2242
- return false;
2243
- }
2244
-
2245
- inline constexpr bool operator<=(monostate, monostate) noexcept {
2246
- return true;
2247
- }
2248
-
2249
- inline constexpr bool operator>=(monostate, monostate) noexcept {
2250
- return true;
2251
- }
2252
-
2253
- inline constexpr bool operator==(monostate, monostate) noexcept {
2254
- return true;
2255
- }
2256
-
2257
- inline constexpr bool operator!=(monostate, monostate) noexcept {
2258
- return false;
2259
- }
2260
-
2261
- #ifdef MPARK_CPP14_CONSTEXPR
2262
- namespace detail {
2263
-
2264
- inline constexpr bool all(std::initializer_list<bool> bs) {
2265
- for (bool b : bs) {
2266
- if (!b) {
2267
- return false;
2268
- }
2269
- }
2270
- return true;
2271
- }
2272
-
2273
- } // namespace detail
2274
-
2275
- template <typename Visitor, typename... Vs>
2276
- inline constexpr decltype(auto) visit(Visitor &&visitor, Vs &&... vs) {
2277
- return (detail::all({!vs.valueless_by_exception()...})
2278
- ? (void)0
2279
- : throw_bad_variant_access()),
2280
- detail::visitation::variant::visit_value(
2281
- lib::forward<Visitor>(visitor), lib::forward<Vs>(vs)...);
2282
- }
2283
- #else
2284
- namespace detail {
2285
-
2286
- template <std::size_t N>
2287
- inline constexpr bool all_impl(const lib::array<bool, N> &bs,
2288
- std::size_t idx) {
2289
- return idx >= N || (bs[idx] && all_impl(bs, idx + 1));
2290
- }
2291
-
2292
- template <std::size_t N>
2293
- inline constexpr bool all(const lib::array<bool, N> &bs) {
2294
- return all_impl(bs, 0);
2295
- }
2296
-
2297
- } // namespace detail
2298
-
2299
- template <typename Visitor, typename... Vs>
2300
- inline constexpr DECLTYPE_AUTO visit(Visitor &&visitor, Vs &&... vs)
2301
- DECLTYPE_AUTO_RETURN(
2302
- (detail::all(
2303
- lib::array<bool, sizeof...(Vs)>{{!vs.valueless_by_exception()...}})
2304
- ? (void)0
2305
- : throw_bad_variant_access()),
2306
- detail::visitation::variant::visit_value(lib::forward<Visitor>(visitor),
2307
- lib::forward<Vs>(vs)...))
2308
- #endif
2309
-
2310
- template <typename... Ts>
2311
- inline auto swap(variant<Ts...> &lhs,
2312
- variant<Ts...> &rhs) noexcept(noexcept(lhs.swap(rhs)))
2313
- -> decltype(lhs.swap(rhs)) {
2314
- lhs.swap(rhs);
2315
- }
2316
-
2317
- namespace detail {
2318
-
2319
- template <typename T, typename...>
2320
- using enabled_type = T;
2321
-
2322
- namespace hash {
2323
-
2324
- template <typename H, typename K>
2325
- constexpr bool meets_requirements() {
2326
- return std::is_copy_constructible<H>::value &&
2327
- std::is_move_constructible<H>::value &&
2328
- lib::is_invocable_r<std::size_t, H, const K &>::value;
2329
- }
2330
-
2331
- template <typename K>
2332
- constexpr bool is_enabled() {
2333
- using H = std::hash<K>;
2334
- return meets_requirements<H, K>() &&
2335
- std::is_default_constructible<H>::value &&
2336
- std::is_copy_assignable<H>::value &&
2337
- std::is_move_assignable<H>::value;
2338
- }
2339
-
2340
- } // namespace hash
2341
-
2342
- } // namespace detail
2343
-
2344
- #undef AUTO
2345
- #undef AUTO_RETURN
2346
-
2347
- #undef AUTO_REFREF
2348
- #undef AUTO_REFREF_RETURN
2349
-
2350
- #undef DECLTYPE_AUTO
2351
- #undef DECLTYPE_AUTO_RETURN
2352
-
2353
- } // namespace mpark
2354
-
2355
- namespace std {
2356
-
2357
- template <typename... Ts>
2358
- struct hash<mpark::detail::enabled_type<
2359
- mpark::variant<Ts...>,
2360
- mpark::lib::enable_if_t<mpark::lib::all<mpark::detail::hash::is_enabled<
2361
- mpark::lib::remove_const_t<Ts>>()...>::value>>> {
2362
- using argument_type = mpark::variant<Ts...>;
2363
- using result_type = std::size_t;
2364
-
2365
- inline result_type operator()(const argument_type &v) const {
2366
- using mpark::detail::visitation::variant;
2367
- std::size_t result =
2368
- v.valueless_by_exception()
2369
- ? 299792458 // Random value chosen by the universe upon creation
2370
- : variant::visit_alt(
2371
- #ifdef MPARK_GENERIC_LAMBDAS
2372
- [](const auto &alt) {
2373
- using alt_type = mpark::lib::decay_t<decltype(alt)>;
2374
- using value_type = mpark::lib::remove_const_t<
2375
- typename alt_type::value_type>;
2376
- return hash<value_type>{}(alt.value);
2377
- }
2378
- #else
2379
- hasher{}
2380
- #endif
2381
- ,
2382
- v);
2383
- return hash_combine(result, hash<std::size_t>{}(v.index()));
2384
- }
2385
-
2386
- private:
2387
- #ifndef MPARK_GENERIC_LAMBDAS
2388
- struct hasher {
2389
- template <typename Alt>
2390
- inline std::size_t operator()(const Alt &alt) const {
2391
- using alt_type = mpark::lib::decay_t<Alt>;
2392
- using value_type =
2393
- mpark::lib::remove_const_t<typename alt_type::value_type>;
2394
- return hash<value_type>{}(alt.value);
2395
- }
2396
- };
2397
- #endif
2398
-
2399
- static std::size_t hash_combine(std::size_t lhs, std::size_t rhs) {
2400
- return lhs ^= rhs + 0x9e3779b9 + (lhs << 6) + (lhs >> 2);
2401
- }
2402
- };
2403
-
2404
- template <>
2405
- struct hash<mpark::monostate> {
2406
- using argument_type = mpark::monostate;
2407
- using result_type = std::size_t;
2408
-
2409
- inline result_type operator()(const argument_type &) const noexcept {
2410
- return 66740831; // return a fundamentally attractive random value.
2411
- }
2412
- };
2413
-
2414
- } // namespace std
2415
-
2416
- #endif // MPARK_VARIANT_HPP