From Jason Turner

[text]

Large diff (385.1 KB) - rendering may be slow on some devices

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp42hv2pzu/{from.md → to.md} +9777 -0
tmp/tmp42hv2pzu/{from.md → to.md} RENAMED
@@ -0,0 +1,9777 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Text processing library <a id="text">[[text]]</a>
2
+
3
+ ## General <a id="text.general">[[text.general]]</a>
4
+
5
+ This Clause describes components for dealing with text. These components
6
+ are summarized in [[text.summary]].
7
+
8
+ **Table: Text library summary** <a id="text.summary">[text.summary]</a>
9
+
10
+ | Subclause | | Header |
11
+ | ------------------ | ---------------------------------- | ------------------------------------------------------------ |
12
+ | [[charconv]] | Primitive numeric conversions | `<charconv>` |
13
+ | [[localization]] | Localization library | `<locale>`, `<clocale>` |
14
+ | [[format]] | Formatting | `<format>` |
15
+ | [[text.encoding]] | Text encodings identification | `<text_encoding>` |
16
+ | [[re]] | Regular expressions library | `<regex>` |
17
+ | [[text.c.strings]] | Null-terminated sequence utilities | `<cctype>`, `<cstdlib>`, `<cuchar>`, `<cwchar>`, `<cwctype>` |
18
+
19
+
20
+ ## Primitive numeric conversions <a id="charconv">[[charconv]]</a>
21
+
22
+ ### Header `<charconv>` synopsis <a id="charconv.syn">[[charconv.syn]]</a>
23
+
24
+ When a function is specified with a type placeholder of `integer-type`,
25
+ the implementation provides overloads for `char` and all cv-unqualified
26
+ signed and unsigned integer types in lieu of `integer-type`. When a
27
+ function is specified with a type placeholder of `floating-point-type`,
28
+ the implementation provides overloads for all cv-unqualified
29
+ floating-point types [[basic.fundamental]] in lieu of
30
+ `floating-point-type`.
31
+
32
+ ``` cpp
33
+ namespace std {
34
+ // floating-point format for primitive numerical conversion
35
+ enum class chars_format {
36
+ scientific = unspecified,
37
+ fixed = unspecified,
38
+ hex = unspecified,
39
+ general = fixed | scientific
40
+ };
41
+
42
+ // [charconv.to.chars], primitive numerical output conversion
43
+ struct to_chars_result { // freestanding
44
+ char* ptr;
45
+ errc ec;
46
+ friend bool operator==(const to_chars_result&, const to_chars_result&) = default;
47
+ constexpr explicit operator bool() const noexcept { return ec == errc{}; }
48
+ };
49
+
50
+ constexpr to_chars_result to_chars(char* first, char* last, // freestanding
51
+ integer-type value, int base = 10);
52
+ to_chars_result to_chars(char* first, char* last, // freestanding
53
+ bool value, int base = 10) = delete;
54
+
55
+ to_chars_result to_chars(char* first, char* last, // freestanding-deleted
56
+ floating-point-type value);
57
+ to_chars_result to_chars(char* first, char* last, // freestanding-deleted
58
+ floating-point-type value, chars_format fmt);
59
+ to_chars_result to_chars(char* first, char* last, // freestanding-deleted
60
+ floating-point-type value, chars_format fmt, int precision);
61
+
62
+ // [charconv.from.chars], primitive numerical input conversion
63
+ struct from_chars_result { // freestanding
64
+ const char* ptr;
65
+ errc ec;
66
+ friend bool operator==(const from_chars_result&, const from_chars_result&) = default;
67
+ constexpr explicit operator bool() const noexcept { return ec == errc{}; }
68
+ };
69
+
70
+ constexpr from_chars_result from_chars(const char* first, const char* last, // freestanding
71
+ integer-type& value, int base = 10);
72
+
73
+ from_chars_result from_chars(const char* first, const char* last, // freestanding-deleted
74
+ floating-point-type& value,
75
+ chars_format fmt = chars_format::general);
76
+ }
77
+ ```
78
+
79
+ The type `chars_format` is a bitmask type [[bitmask.types]] with
80
+ elements `scientific`, `fixed`, and `hex`.
81
+
82
+ The types `to_chars_result` and `from_chars_result` have the data
83
+ members and special members specified above. They have no base classes
84
+ or members other than those specified.
85
+
86
+ ### Primitive numeric output conversion <a id="charconv.to.chars">[[charconv.to.chars]]</a>
87
+
88
+ All functions named `to_chars` convert `value` into a character string
89
+ by successively filling the range \[`first`, `last`), where \[`first`,
90
+ `last`) is required to be a valid range. If the member `ec` of the
91
+ return value is such that the value is equal to the value of a
92
+ value-initialized `errc`, the conversion was successful and the member
93
+ `ptr` is the one-past-the-end pointer of the characters written.
94
+ Otherwise, the member `ec` has the value `errc::value_too_large`, the
95
+ member `ptr` has the value `last`, and the contents of the range
96
+ \[`first`, `last`) are unspecified.
97
+
98
+ The functions that take a floating-point `value` but not a `precision`
99
+ parameter ensure that the string representation consists of the smallest
100
+ number of characters such that there is at least one digit before the
101
+ radix point (if present) and parsing the representation using the
102
+ corresponding `from_chars` function recovers `value` exactly.
103
+
104
+ [*Note 1*: This guarantee applies only if `to_chars` and `from_chars`
105
+ are executed on the same implementation. — *end note*]
106
+
107
+ If there are several such representations, the representation with the
108
+ smallest difference from the floating-point argument value is chosen,
109
+ resolving any remaining ties using rounding according to
110
+ `round_to_nearest` [[round.style]].
111
+
112
+ The functions taking a `chars_format` parameter determine the conversion
113
+ specifier for `printf` as follows: The conversion specifier is `f` if
114
+ `fmt` is `chars_format::fixed`, `e` if `fmt` is
115
+ `chars_format::scientific`, `a` (without leading `"0x"` in the result)
116
+ if `fmt` is `chars_format::hex`, and `g` if `fmt` is
117
+ `chars_format::general`.
118
+
119
+ ``` cpp
120
+ constexpr to_chars_result to_chars(char* first, char* last, integer-type value, int base = 10);
121
+ ```
122
+
123
+ *Preconditions:* `base` has a value between 2 and 36 (inclusive).
124
+
125
+ *Effects:* The value of `value` is converted to a string of digits in
126
+ the given base (with no redundant leading zeroes). Digits in the range
127
+ 10..35 (inclusive) are represented as lowercase characters `a`..`z`. If
128
+ `value` is less than zero, the representation starts with `’-’`.
129
+
130
+ *Throws:* Nothing.
131
+
132
+ ``` cpp
133
+ to_chars_result to_chars(char* first, char* last, floating-point-type value);
134
+ ```
135
+
136
+ *Effects:* `value` is converted to a string in the style of `printf` in
137
+ the `"C"` locale. The conversion specifier is `f` or `e`, chosen
138
+ according to the requirement for a shortest representation (see above);
139
+ a tie is resolved in favor of `f`.
140
+
141
+ *Throws:* Nothing.
142
+
143
+ ``` cpp
144
+ to_chars_result to_chars(char* first, char* last, floating-point-type value, chars_format fmt);
145
+ ```
146
+
147
+ *Preconditions:* `fmt` has the value of one of the enumerators of
148
+ `chars_format`.
149
+
150
+ *Effects:* `value` is converted to a string in the style of `printf` in
151
+ the `"C"` locale.
152
+
153
+ *Throws:* Nothing.
154
+
155
+ ``` cpp
156
+ to_chars_result to_chars(char* first, char* last, floating-point-type value,
157
+ chars_format fmt, int precision);
158
+ ```
159
+
160
+ *Preconditions:* `fmt` has the value of one of the enumerators of
161
+ `chars_format`.
162
+
163
+ *Effects:* `value` is converted to a string in the style of `printf` in
164
+ the `"C"` locale with the given precision.
165
+
166
+ *Throws:* Nothing.
167
+
168
+ See also: ISO C 7.23.6.2
169
+
170
+ ### Primitive numeric input conversion <a id="charconv.from.chars">[[charconv.from.chars]]</a>
171
+
172
+ All functions named `from_chars` analyze the string \[`first`, `last`)
173
+ for a pattern, where \[`first`, `last`) is required to be a valid range.
174
+ If no characters match the pattern, `value` is unmodified, the member
175
+ `ptr` of the return value is `first` and the member `ec` is equal to
176
+ `errc::invalid_argument`.
177
+
178
+ [*Note 1*: If the pattern allows for an optional sign, but the string
179
+ has no digit characters following the sign, no characters match the
180
+ pattern. — *end note*]
181
+
182
+ Otherwise, the characters matching the pattern are interpreted as a
183
+ representation of a value of the type of `value`. The member `ptr` of
184
+ the return value points to the first character not matching the pattern,
185
+ or has the value `last` if all characters match. If the parsed value is
186
+ not in the range representable by the type of `value`, `value` is
187
+ unmodified and the member `ec` of the return value is equal to
188
+ `errc::result_out_of_range`. Otherwise, `value` is set to the parsed
189
+ value, after rounding according to `round_to_nearest` [[round.style]],
190
+ and the member `ec` is value-initialized.
191
+
192
+ ``` cpp
193
+ constexpr from_chars_result from_chars(const char* first, const char* last,
194
+ integer-type& value, int base = 10);
195
+ ```
196
+
197
+ *Preconditions:* `base` has a value between 2 and 36 (inclusive).
198
+
199
+ *Effects:* The pattern is the expected form of the subject sequence in
200
+ the `"C"` locale for the given nonzero base, as described for `strtol`,
201
+ except that no `"0x"` or `"0X"` prefix shall appear if the value of
202
+ `base` is 16, and except that `’-’` is the only sign that may appear,
203
+ and only if `value` has a signed type.
204
+
205
+ *Throws:* Nothing.
206
+
207
+ ``` cpp
208
+ from_chars_result from_chars(const char* first, const char* last, floating-point-type& value,
209
+ chars_format fmt = chars_format::general);
210
+ ```
211
+
212
+ *Preconditions:* `fmt` has the value of one of the enumerators of
213
+ `chars_format`.
214
+
215
+ *Effects:* The pattern is the expected form of the subject sequence in
216
+ the `"C"` locale, as described for `strtod`, except that
217
+
218
+ - the sign `’+’` may only appear in the exponent part;
219
+ - if `fmt` has `chars_format::scientific` set but not
220
+ `chars_format::fixed`, the otherwise optional exponent part shall
221
+ appear;
222
+ - if `fmt` has `chars_format::fixed` set but not
223
+ `chars_format::scientific`, the optional exponent part shall not
224
+ appear; and
225
+ - if `fmt` is `chars_format::hex`, the prefix `"0x"` or `"0X"` is
226
+ assumed. \[*Example 1*: The string `0x123` is parsed to have the value
227
+ `0` with remaining characters `x123`. — *end example*]
228
+
229
+ In any case, the resulting `value` is one of at most two floating-point
230
+ values closest to the value of the string matching the pattern.
231
+
232
+ *Throws:* Nothing.
233
+
234
+ See also: ISO C 7.24.2.6, 7.24.2.8
235
+
236
+ ## Localization library <a id="localization">[[localization]]</a>
237
+
238
+ ### General <a id="localization.general">[[localization.general]]</a>
239
+
240
+ Subclause [[localization]] describes components that C++ programs may
241
+ use to encapsulate (and therefore be more portable when confronting)
242
+ cultural differences. The locale facility includes internationalization
243
+ support for character classification and string collation, numeric,
244
+ monetary, and date/time formatting and parsing, and message retrieval.
245
+
246
+ The following subclauses describe components for locales themselves, the
247
+ standard facets, and facilities from the C library, as summarized in
248
+ [[localization.summary]].
249
+
250
+ **Table: Localization library summary** <a id="localization.summary">[localization.summary]</a>
251
+
252
+ | Subclause | | Header |
253
+ | --------------------- | ---------------------------- | ----------- |
254
+ | [[locales]] | Locales | `<locale>` |
255
+ | [[locale.categories]] | Standard `locale` categories | |
256
+ | [[c.locales]] | C library locales | `<clocale>` |
257
+
258
+
259
+ ### Header `<locale>` synopsis <a id="locale.syn">[[locale.syn]]</a>
260
+
261
+ ``` cpp
262
+ namespace std {
263
+ // [locale], locale
264
+ class locale;
265
+ template<class Facet> const Facet& use_facet(const locale&);
266
+ template<class Facet> bool has_facet(const locale&) noexcept;
267
+
268
+ // [locale.convenience], convenience interfaces
269
+ template<class charT> bool isspace (charT c, const locale& loc);
270
+ template<class charT> bool isprint (charT c, const locale& loc);
271
+ template<class charT> bool iscntrl (charT c, const locale& loc);
272
+ template<class charT> bool isupper (charT c, const locale& loc);
273
+ template<class charT> bool islower (charT c, const locale& loc);
274
+ template<class charT> bool isalpha (charT c, const locale& loc);
275
+ template<class charT> bool isdigit (charT c, const locale& loc);
276
+ template<class charT> bool ispunct (charT c, const locale& loc);
277
+ template<class charT> bool isxdigit(charT c, const locale& loc);
278
+ template<class charT> bool isalnum (charT c, const locale& loc);
279
+ template<class charT> bool isgraph (charT c, const locale& loc);
280
+ template<class charT> bool isblank (charT c, const locale& loc);
281
+ template<class charT> charT toupper(charT c, const locale& loc);
282
+ template<class charT> charT tolower(charT c, const locale& loc);
283
+
284
+ // [category.ctype], ctype
285
+ class ctype_base;
286
+ template<class charT> class ctype;
287
+ template<> class ctype<char>; // specialization
288
+ template<class charT> class ctype_byname;
289
+ class codecvt_base;
290
+ template<class internT, class externT, class stateT> class codecvt;
291
+ template<class internT, class externT, class stateT> class codecvt_byname;
292
+
293
+ // [category.numeric], numeric
294
+ template<class charT, class InputIterator = istreambuf_iterator<charT>>
295
+ class num_get;
296
+ template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
297
+ class num_put;
298
+ template<class charT>
299
+ class numpunct;
300
+ template<class charT>
301
+ class numpunct_byname;
302
+
303
+ // [category.collate], collation
304
+ template<class charT> class collate;
305
+ template<class charT> class collate_byname;
306
+
307
+ // [category.time], date and time
308
+ class time_base;
309
+ template<class charT, class InputIterator = istreambuf_iterator<charT>>
310
+ class time_get;
311
+ template<class charT, class InputIterator = istreambuf_iterator<charT>>
312
+ class time_get_byname;
313
+ template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
314
+ class time_put;
315
+ template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
316
+ class time_put_byname;
317
+
318
+ // [category.monetary], money
319
+ class money_base;
320
+ template<class charT, class InputIterator = istreambuf_iterator<charT>>
321
+ class money_get;
322
+ template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
323
+ class money_put;
324
+ template<class charT, bool Intl = false>
325
+ class moneypunct;
326
+ template<class charT, bool Intl = false>
327
+ class moneypunct_byname;
328
+
329
+ // [category.messages], message retrieval
330
+ class messages_base;
331
+ template<class charT> class messages;
332
+ template<class charT> class messages_byname;
333
+ }
334
+ ```
335
+
336
+ The header `<locale>` defines classes and declares functions that
337
+ encapsulate and manipulate the information peculiar to a locale.[^1]
338
+
339
+ ### Locales <a id="locales">[[locales]]</a>
340
+
341
+ #### Class `locale` <a id="locale">[[locale]]</a>
342
+
343
+ ##### General <a id="locale.general">[[locale.general]]</a>
344
+
345
+ ``` cpp
346
+ namespace std {
347
+ class locale {
348
+ public:
349
+ // [locale.types], types
350
+ // [locale.facet], class locale::facet
351
+ class facet;
352
+ // [locale.id], class locale::id
353
+ class id;
354
+ // [locale.category], type locale::category
355
+ using category = int;
356
+ static const category // values assigned here are for exposition only
357
+ none = 0,
358
+ collate = 0x010, ctype = 0x020,
359
+ monetary = 0x040, numeric = 0x080,
360
+ time = 0x100, messages = 0x200,
361
+ all = collate | ctype | monetary | numeric | time | messages;
362
+
363
+ // [locale.cons], construct/copy/destroy
364
+ locale() noexcept;
365
+ locale(const locale& other) noexcept;
366
+ explicit locale(const char* std_name);
367
+ explicit locale(const string& std_name);
368
+ locale(const locale& other, const char* std_name, category);
369
+ locale(const locale& other, const string& std_name, category);
370
+ template<class Facet> locale(const locale& other, Facet* f);
371
+ locale(const locale& other, const locale& one, category);
372
+ ~locale(); // not virtual
373
+ const locale& operator=(const locale& other) noexcept;
374
+
375
+ // [locale.members], locale operations
376
+ template<class Facet> locale combine(const locale& other) const;
377
+ string name() const;
378
+ text_encoding encoding() const;
379
+
380
+ bool operator==(const locale& other) const;
381
+
382
+ template<class charT, class traits, class Allocator>
383
+ bool operator()(const basic_string<charT, traits, Allocator>& s1,
384
+ const basic_string<charT, traits, Allocator>& s2) const;
385
+
386
+ // [locale.statics], global locale objects
387
+ static locale global(const locale&);
388
+ static const locale& classic();
389
+ };
390
+ }
391
+ ```
392
+
393
+ Class `locale` implements a type-safe polymorphic set of facets, indexed
394
+ by facet *type*. In other words, a facet has a dual role: in one sense,
395
+ it’s just a class interface; at the same time, it’s an index into a
396
+ locale’s set of facets.
397
+
398
+ Access to the facets of a `locale` is via two function templates,
399
+ `use_facet<>` and `has_facet<>`.
400
+
401
+ [*Example 1*:
402
+
403
+ An iostream `operator<<` can be implemented as:[^2]
404
+
405
+ ``` cpp
406
+ template<class charT, class traits>
407
+ basic_ostream<charT, traits>&
408
+ operator<< (basic_ostream<charT, traits>& s, Date d) {
409
+ typename basic_ostream<charT, traits>::sentry cerberos(s);
410
+ if (cerberos) {
411
+ tm tmbuf; d.extract(tmbuf);
412
+ bool failed =
413
+ use_facet<time_put<charT, ostreambuf_iterator<charT, traits>>>(
414
+ s.getloc()).put(s, s, s.fill(), &tmbuf, 'x').failed();
415
+ if (failed)
416
+ s.setstate(s.badbit); // can throw
417
+ }
418
+ return s;
419
+ }
420
+ ```
421
+
422
+ — *end example*]
423
+
424
+ In the call to `use_facet<Facet>(loc)`, the type argument chooses a
425
+ facet, making available all members of the named type. If `Facet` is not
426
+ present in a locale, it throws the standard exception `bad_cast`. A C++
427
+ program can check if a locale implements a particular facet with the
428
+ function template `has_facet<Facet>()`. User-defined facets may be
429
+ installed in a locale, and used identically as may standard facets.
430
+
431
+ [*Note 1*:
432
+
433
+ All locale semantics are accessed via `use_facet<>` and `has_facet<>`,
434
+ except that:
435
+
436
+ - A member operator template
437
+ ``` cpp
438
+ operator()(const basic_string<C, T, A>&, const basic_string<C, T, A>&)
439
+ ```
440
+
441
+ is provided so that a locale can be used as a predicate argument to
442
+ the standard collections, to collate strings.
443
+ - Convenient global interfaces are provided for traditional `ctype`
444
+ functions such as `isdigit()` and `isspace()`, so that given a locale
445
+ object `loc` a C++ program can call `isspace(c, loc)`. (This eases
446
+ upgrading existing extractors [[istream.formatted]].)
447
+
448
+ — *end note*]
449
+
450
+ Once a facet reference is obtained from a locale object by calling
451
+ `use_facet<>`, that reference remains usable, and the results from
452
+ member functions of it may be cached and re-used, as long as some locale
453
+ object refers to that facet.
454
+
455
+ In successive calls to a locale facet member function on a facet object
456
+ installed in the same locale, the returned result shall be identical.
457
+
458
+ A `locale` constructed from a name string (such as `"POSIX"`), or from
459
+ parts of two named locales, has a name; all others do not. Named locales
460
+ may be compared for equality; an unnamed locale is equal only to (copies
461
+ of) itself. For an unnamed locale, `locale::name()` returns the string
462
+ `"*"`.
463
+
464
+ Whether there is one global locale object for the entire program or one
465
+ global locale object per thread is *implementation-defined*.
466
+ Implementations should provide one global locale object per thread. If
467
+ there is a single global locale object for the entire program,
468
+ implementations are not required to avoid data races on it
469
+ [[res.on.data.races]].
470
+
471
+ ##### Types <a id="locale.types">[[locale.types]]</a>
472
+
473
+ ###### Type `locale::category` <a id="locale.category">[[locale.category]]</a>
474
+
475
+ ``` cpp
476
+ using category = int;
477
+ ```
478
+
479
+ *Valid* `category` values include the `locale` member bitmask elements
480
+ `collate`, `ctype`, `monetary`, `numeric`, `time`, and `messages`, each
481
+ of which represents a single locale category. In addition, `locale`
482
+ member bitmask constant `none` is defined as zero and represents no
483
+ category. And `locale` member bitmask constant `all` is defined such
484
+ that the expression
485
+
486
+ ``` cpp
487
+ (collate | ctype | monetary | numeric | time | messages | all) == all
488
+ ```
489
+
490
+ is `true`, and represents the union of all categories. Further, the
491
+ expression `(X | Y)`, where `X` and `Y` each represent a single
492
+ category, represents the union of the two categories.
493
+
494
+ `locale` member functions expecting a `category` argument require one of
495
+ the `category` values defined above, or the union of two or more such
496
+ values. Such a `category` value identifies a set of locale categories.
497
+ Each locale category, in turn, identifies a set of locale facets,
498
+ including at least those shown in [[locale.category.facets]].
499
+
500
+ **Table: Locale category facets** <a id="locale.category.facets">[locale.category.facets]</a>
501
+
502
+ | Category | Includes facets |
503
+ | -------- | ----------------------------------------------------- |
504
+ | collate | `collate<char>`, `collate<wchar_t>` |
505
+ | ctype | `ctype<char>`, `ctype<wchar_t>` |
506
+ | | `codecvt<char, char, mbstate_t>` |
507
+ | | `codecvt<wchar_t, char, mbstate_t>` |
508
+ | monetary | `moneypunct<char>`, `moneypunct<wchar_t>` |
509
+ | | `moneypunct<char, true>`, `moneypunct<wchar_t, true>` |
510
+ | | `money_get<char>`, `money_get<wchar_t>` |
511
+ | | `money_put<char>`, `money_put<wchar_t>` |
512
+ | numeric | `numpunct<char>`, `numpunct<wchar_t>` |
513
+ | | `num_get<char>`, `num_get<wchar_t>` |
514
+ | | `num_put<char>`, `num_put<wchar_t>` |
515
+ | time | `time_get<char>`, `time_get<wchar_t>` |
516
+ | | `time_put<char>`, `time_put<wchar_t>` |
517
+ | messages | `messages<char>`, `messages<wchar_t>` |
518
+
519
+
520
+ For any locale `loc` either constructed, or returned by
521
+ `locale::classic()`, and any facet `Facet` shown in
522
+ [[locale.category.facets]], `has_facet<Facet>(loc)` is `true`. Each
523
+ `locale` member function which takes a `locale::category` argument
524
+ operates on the corresponding set of facets.
525
+
526
+ An implementation is required to provide those specializations for facet
527
+ templates identified as members of a category, and for those shown in
528
+ [[locale.spec]].
529
+
530
+ **Table: Required specializations** <a id="locale.spec">[locale.spec]</a>
531
+
532
+ | Category | Includes facets |
533
+ | -------- | --------------------------------------------------------- |
534
+ | collate | `collate_byname<char>`, `collate_byname<wchar_t>` |
535
+ | ctype | `ctype_byname<char>`, `ctype_byname<wchar_t>` |
536
+ | | `codecvt_byname<char, char, mbstate_t>` |
537
+ | | `codecvt_byname<wchar_t, char, mbstate_t>` |
538
+ | monetary | `moneypunct_byname<char, International>` |
539
+ | | `moneypunct_byname<wchar_t, International>` |
540
+ | | `money_get<C, InputIterator>` |
541
+ | | `money_put<C, OutputIterator>` |
542
+ | numeric | `numpunct_byname<char>`, `numpunct_byname<wchar_t>` |
543
+ | | `num_get<C, InputIterator>`, `num_put<C, OutputIterator>` |
544
+ | time | `time_get<char, InputIterator>` |
545
+ | | `time_get_byname<char, InputIterator>` |
546
+ | | `time_get<wchar_t, InputIterator>` |
547
+ | | `time_get_byname<wchar_t, InputIterator>` |
548
+ | | `time_put<char, OutputIterator>` |
549
+ | | `time_put_byname<char, OutputIterator>` |
550
+ | | `time_put<wchar_t, OutputIterator>` |
551
+ | | `time_put_byname<wchar_t, OutputIterator>` |
552
+ | messages | `messages_byname<char>`, `messages_byname<wchar_t>` |
553
+
554
+
555
+ The provided implementation of members of facets `num_get<charT>` and
556
+ `num_put<charT>` calls `use_facet<F>(l)` only for facet `F` of types
557
+ `numpunct<charT>` and `ctype<charT>`, and for locale `l` the value
558
+ obtained by calling member `getloc()` on the `ios_base&` argument to
559
+ these functions.
560
+
561
+ In declarations of facets, a template parameter with name
562
+ `InputIterator` or `OutputIterator` indicates the set of all possible
563
+ specializations on parameters that meet the *Cpp17InputIterator*
564
+ requirements or *Cpp17OutputIterator* requirements, respectively
565
+ [[iterator.requirements]]. A template parameter with name `C` represents
566
+ the set of types containing `char`, `wchar_t`, and any other
567
+ *implementation-defined* character container types
568
+ [[defns.character.container]] that meet the requirements for a character
569
+ on which any of the iostream components can be instantiated. A template
570
+ parameter with name `International` represents the set of all possible
571
+ specializations on a bool parameter.
572
+
573
+ ###### Class `locale::facet` <a id="locale.facet">[[locale.facet]]</a>
574
+
575
+ ``` cpp
576
+ namespace std {
577
+ class locale::facet {
578
+ protected:
579
+ explicit facet(size_t refs = 0);
580
+ virtual ~facet();
581
+ facet(const facet&) = delete;
582
+ void operator=(const facet&) = delete;
583
+ };
584
+ }
585
+ ```
586
+
587
+ Class `facet` is the base class for locale feature sets. A class is a
588
+ *facet* if it is publicly derived from another facet, or if it is a
589
+ class derived from `locale::facet` and contains a publicly accessible
590
+ declaration as follows:[^3]
591
+
592
+ ``` cpp
593
+ static ::std::locale::id id;
594
+ ```
595
+
596
+ Template parameters in this Clause which are required to be facets are
597
+ those named `Facet` in declarations. A program that passes a type that
598
+ is *not* a facet, or a type that refers to a volatile-qualified facet,
599
+ as an (explicit or deduced) template parameter to a locale function
600
+ expecting a facet, is ill-formed. A const-qualified facet is a valid
601
+ template argument to any locale function that expects a `Facet` template
602
+ parameter.
603
+
604
+ The `refs` argument to the constructor is used for lifetime management.
605
+ For `refs == 0`, the implementation performs
606
+ `delete static_cast<locale::facet*>(f)` (where `f` is a pointer to the
607
+ facet) when the last `locale` object containing the facet is destroyed;
608
+ for `refs == 1`, the implementation never destroys the facet.
609
+
610
+ Constructors of all facets defined in this Clause take such an argument
611
+ and pass it along to their `facet` base class constructor. All
612
+ one-argument constructors defined in this Clause are explicit,
613
+ preventing their participation in implicit conversions.
614
+
615
+ For some standard facets a standard “…`_byname`” class, derived from it,
616
+ implements the virtual function semantics equivalent to that facet of
617
+ the locale constructed by `locale(const char*)` with the same name. Each
618
+ such facet provides a constructor that takes a `const char*` argument,
619
+ which names the locale, and a `refs` argument, which is passed to the
620
+ base class constructor. Each such facet also provides a constructor that
621
+ takes a `string` argument `str` and a `refs` argument, which has the
622
+ same effect as calling the first constructor with the two arguments
623
+ `str.c_str()` and `refs`. If there is no “…`_byname`” version of a
624
+ facet, the base class implements named locale semantics itself by
625
+ reference to other facets.
626
+
627
+ ###### Class `locale::id` <a id="locale.id">[[locale.id]]</a>
628
+
629
+ ``` cpp
630
+ namespace std {
631
+ class locale::id {
632
+ public:
633
+ id();
634
+ void operator=(const id&) = delete;
635
+ id(const id&) = delete;
636
+ };
637
+ }
638
+ ```
639
+
640
+ The class `locale::id` provides identification of a locale facet
641
+ interface, used as an index for lookup and to encapsulate
642
+ initialization.
643
+
644
+ [*Note 2*: Because facets are used by iostreams, potentially while
645
+ static constructors are running, their initialization cannot depend on
646
+ programmed static initialization. One initialization strategy is for
647
+ `locale` to initialize each facet’s `id` member the first time an
648
+ instance of the facet is installed into a locale. This depends only on
649
+ static storage being zero before constructors run
650
+ [[basic.start.static]]. — *end note*]
651
+
652
+ ##### Constructors and destructor <a id="locale.cons">[[locale.cons]]</a>
653
+
654
+ ``` cpp
655
+ locale() noexcept;
656
+ ```
657
+
658
+ *Effects:* Constructs a copy of the argument last passed to
659
+ `locale::global(locale&)`, if it has been called; else, the resulting
660
+ facets have virtual function semantics identical to those of
661
+ `locale::classic()`.
662
+
663
+ [*Note 1*: This constructor yields a copy of the current global locale.
664
+ It is commonly used as a default argument for function parameters of
665
+ type `const locale&`. — *end note*]
666
+
667
+ ``` cpp
668
+ explicit locale(const char* std_name);
669
+ ```
670
+
671
+ *Effects:* Constructs a locale using standard C locale names, e.g.,
672
+ `"POSIX"`. The resulting locale implements semantics defined to be
673
+ associated with that name.
674
+
675
+ *Throws:* `runtime_error` if the argument is not valid, or is null.
676
+
677
+ *Remarks:* The set of valid string argument values is `"C"`, `""`, and
678
+ any *implementation-defined* values.
679
+
680
+ ``` cpp
681
+ explicit locale(const string& std_name);
682
+ ```
683
+
684
+ *Effects:* Equivalent to `locale(std_name.c_str())`.
685
+
686
+ ``` cpp
687
+ locale(const locale& other, const char* std_name, category cats);
688
+ ```
689
+
690
+ *Preconditions:* `cats` is a valid `category` value [[locale.category]].
691
+
692
+ *Effects:* Constructs a locale as a copy of `other` except for the
693
+ facets identified by the `category` argument, which instead implement
694
+ the same semantics as `locale(std_name)`.
695
+
696
+ *Throws:* `runtime_error` if the second argument is not valid, or is
697
+ null.
698
+
699
+ *Remarks:* The locale has a name if and only if `other` has a name.
700
+
701
+ ``` cpp
702
+ locale(const locale& other, const string& std_name, category cats);
703
+ ```
704
+
705
+ *Effects:* Equivalent to `locale(other, std_name.c_str(), cats)`.
706
+
707
+ ``` cpp
708
+ template<class Facet> locale(const locale& other, Facet* f);
709
+ ```
710
+
711
+ *Effects:* Constructs a locale incorporating all facets from the first
712
+ argument except that of type `Facet`, and installs the second argument
713
+ as the remaining facet. If `f` is null, the resulting object is a copy
714
+ of `other`.
715
+
716
+ *Remarks:* If `f` is null, the resulting locale has the same name as
717
+ `other`. Otherwise, the resulting locale has no name.
718
+
719
+ ``` cpp
720
+ locale(const locale& other, const locale& one, category cats);
721
+ ```
722
+
723
+ *Preconditions:* `cats` is a valid `category` value.
724
+
725
+ *Effects:* Constructs a locale incorporating all facets from the first
726
+ argument except those that implement `cats`, which are instead
727
+ incorporated from the second argument.
728
+
729
+ *Remarks:* If `cats` is equal to `locale::none`, the resulting locale
730
+ has a name if and only if the first argument has a name. Otherwise, the
731
+ resulting locale has a name if and only if the first two arguments both
732
+ have names.
733
+
734
+ ``` cpp
735
+ const locale& operator=(const locale& other) noexcept;
736
+ ```
737
+
738
+ *Effects:* Creates a copy of `other`, replacing the current value.
739
+
740
+ *Returns:* `*this`.
741
+
742
+ ##### Members <a id="locale.members">[[locale.members]]</a>
743
+
744
+ ``` cpp
745
+ template<class Facet> locale combine(const locale& other) const;
746
+ ```
747
+
748
+ *Effects:* Constructs a locale incorporating all facets from `*this`
749
+ except for that one facet of `other` that is identified by `Facet`.
750
+
751
+ *Returns:* The newly created locale.
752
+
753
+ *Throws:* `runtime_error` if `has_facet<Facet>(other)` is `false`.
754
+
755
+ *Remarks:* The resulting locale has no name.
756
+
757
+ ``` cpp
758
+ string name() const;
759
+ ```
760
+
761
+ *Returns:* The name of `*this`, if it has one; otherwise, the string
762
+ `"*"`.
763
+
764
+ ``` cpp
765
+ text_encoding encoding() const;
766
+ ```
767
+
768
+ *Mandates:* `CHAR_BIT == 8` is `true`.
769
+
770
+ *Returns:* A `text_encoding` object representing the
771
+ implementation-defined encoding scheme associated with the locale
772
+ `*this`.
773
+
774
+ ##### Operators <a id="locale.operators">[[locale.operators]]</a>
775
+
776
+ ``` cpp
777
+ bool operator==(const locale& other) const;
778
+ ```
779
+
780
+ *Returns:* `true` if both arguments are the same locale, or one is a
781
+ copy of the other, or each has a name and the names are identical;
782
+ `false` otherwise.
783
+
784
+ ``` cpp
785
+ template<class charT, class traits, class Allocator>
786
+ bool operator()(const basic_string<charT, traits, Allocator>& s1,
787
+ const basic_string<charT, traits, Allocator>& s2) const;
788
+ ```
789
+
790
+ *Effects:* Compares two strings according to the `std::collate<charT>`
791
+ facet.
792
+
793
+ *Returns:*
794
+
795
+ ``` cpp
796
+ use_facet<std::collate<charT>>(*this).compare(s1.data(), s1.data() + s1.size(),
797
+ s2.data(), s2.data() + s2.size()) < 0
798
+ ```
799
+
800
+ *Remarks:* This member operator template (and therefore `locale` itself)
801
+ meets the requirements for a comparator predicate template
802
+ argument [[algorithms]] applied to strings.
803
+
804
+ [*Example 1*:
805
+
806
+ A vector of strings `v` can be collated according to collation rules in
807
+ locale `loc` simply by [[alg.sort]], [[vector]]:
808
+
809
+ ``` cpp
810
+ std::sort(v.begin(), v.end(), loc);
811
+ ```
812
+
813
+ — *end example*]
814
+
815
+ ##### Static members <a id="locale.statics">[[locale.statics]]</a>
816
+
817
+ ``` cpp
818
+ static locale global(const locale& loc);
819
+ ```
820
+
821
+ *Effects:* Sets the global locale to its argument. Causes future calls
822
+ to the constructor `locale()` to return a copy of the argument. If the
823
+ argument has a name, does
824
+
825
+ ``` cpp
826
+ setlocale(LC_ALL, loc.name().c_str());
827
+ ```
828
+
829
+ otherwise, the effect on the C locale, if any, is
830
+ *implementation-defined*.
831
+
832
+ *Returns:* The previous value of `locale()`.
833
+
834
+ *Remarks:* No library function other than `locale::global()` affects the
835
+ value returned by `locale()`.
836
+
837
+ [*Note 2*: See  [[c.locales]] for data race considerations when
838
+ `setlocale` is invoked. — *end note*]
839
+
840
+ ``` cpp
841
+ static const locale& classic();
842
+ ```
843
+
844
+ The `"C"` locale.
845
+
846
+ *Returns:* A locale that implements the classic `"C"` locale semantics,
847
+ equivalent to the value `locale("C")`.
848
+
849
+ *Remarks:* This locale, its facets, and their member functions, do not
850
+ change with time.
851
+
852
+ #### `locale` globals <a id="locale.global.templates">[[locale.global.templates]]</a>
853
+
854
+ ``` cpp
855
+ template<class Facet> const Facet& use_facet(const locale& loc);
856
+ ```
857
+
858
+ *Mandates:* `Facet` is a facet class whose definition contains the
859
+ public static member `id` as defined in  [[locale.facet]].
860
+
861
+ *Returns:* A reference to the corresponding facet of `loc`, if present.
862
+
863
+ *Throws:* `bad_cast` if `has_facet<Facet>(loc)` is `false`.
864
+
865
+ *Remarks:* The reference returned remains valid at least as long as any
866
+ copy of `loc` exists.
867
+
868
+ ``` cpp
869
+ template<class Facet> bool has_facet(const locale& loc) noexcept;
870
+ ```
871
+
872
+ *Returns:* `true` if the facet requested is present in `loc`; otherwise
873
+ `false`.
874
+
875
+ #### Convenience interfaces <a id="locale.convenience">[[locale.convenience]]</a>
876
+
877
+ ##### Character classification <a id="classification">[[classification]]</a>
878
+
879
+ ``` cpp
880
+ template<class charT> bool isspace (charT c, const locale& loc);
881
+ template<class charT> bool isprint (charT c, const locale& loc);
882
+ template<class charT> bool iscntrl (charT c, const locale& loc);
883
+ template<class charT> bool isupper (charT c, const locale& loc);
884
+ template<class charT> bool islower (charT c, const locale& loc);
885
+ template<class charT> bool isalpha (charT c, const locale& loc);
886
+ template<class charT> bool isdigit (charT c, const locale& loc);
887
+ template<class charT> bool ispunct (charT c, const locale& loc);
888
+ template<class charT> bool isxdigit(charT c, const locale& loc);
889
+ template<class charT> bool isalnum (charT c, const locale& loc);
890
+ template<class charT> bool isgraph (charT c, const locale& loc);
891
+ template<class charT> bool isblank (charT c, const locale& loc);
892
+ ```
893
+
894
+ Each of these functions `isF` returns the result of the expression:
895
+
896
+ ``` cpp
897
+ use_facet<ctype<charT>>(loc).is(ctype_base::F, c)
898
+ ```
899
+
900
+ where `F` is the `ctype_base::mask` value corresponding to that function
901
+ [[category.ctype]].[^4]
902
+
903
+ ##### Character conversions <a id="conversions.character">[[conversions.character]]</a>
904
+
905
+ ``` cpp
906
+ template<class charT> charT toupper(charT c, const locale& loc);
907
+ ```
908
+
909
+ *Returns:* `use_facet<ctype<charT>>(loc).toupper(c)`.
910
+
911
+ ``` cpp
912
+ template<class charT> charT tolower(charT c, const locale& loc);
913
+ ```
914
+
915
+ *Returns:* `use_facet<ctype<charT>>(loc).tolower(c)`.
916
+
917
+ ### Standard `locale` categories <a id="locale.categories">[[locale.categories]]</a>
918
+
919
+ #### General <a id="locale.categories.general">[[locale.categories.general]]</a>
920
+
921
+ Each of the standard categories includes a family of facets. Some of
922
+ these implement formatting or parsing of a datum, for use by standard or
923
+ users’ iostream operators `<<` and `>>`, as members `put()` and `get()`,
924
+ respectively. Each such member function takes an `ios_base&` argument
925
+ whose members `flags()`, `precision()`, and `width()`, specify the
926
+ format of the corresponding datum [[ios.base]]. Those functions which
927
+ need to use other facets call its member `getloc()` to retrieve the
928
+ locale imbued there. Formatting facets use the character argument `fill`
929
+ to fill out the specified width where necessary.
930
+
931
+ The `put()` members make no provision for error reporting. (Any failures
932
+ of the OutputIterator argument can be extracted from the returned
933
+ iterator.) The `get()` members take an `ios_base::iostate&` argument
934
+ whose value they ignore, but set to `ios_base::failbit` in case of a
935
+ parse error.
936
+
937
+ Within [[locale.categories]] it is unspecified whether one virtual
938
+ function calls another virtual function.
939
+
940
+ #### The `ctype` category <a id="category.ctype">[[category.ctype]]</a>
941
+
942
+ ##### General <a id="category.ctype.general">[[category.ctype.general]]</a>
943
+
944
+ ``` cpp
945
+ namespace std {
946
+ class ctype_base {
947
+ public:
948
+ using mask = see below;
949
+
950
+ // numeric values are for exposition only.
951
+ static constexpr mask space = 1 << 0;
952
+ static constexpr mask print = 1 << 1;
953
+ static constexpr mask cntrl = 1 << 2;
954
+ static constexpr mask upper = 1 << 3;
955
+ static constexpr mask lower = 1 << 4;
956
+ static constexpr mask alpha = 1 << 5;
957
+ static constexpr mask digit = 1 << 6;
958
+ static constexpr mask punct = 1 << 7;
959
+ static constexpr mask xdigit = 1 << 8;
960
+ static constexpr mask blank = 1 << 9;
961
+ static constexpr mask alnum = alpha | digit;
962
+ static constexpr mask graph = alnum | punct;
963
+ };
964
+ }
965
+ ```
966
+
967
+ The type `mask` is a bitmask type [[bitmask.types]].
968
+
969
+ ##### Class template `ctype` <a id="locale.ctype">[[locale.ctype]]</a>
970
+
971
+ ###### General <a id="locale.ctype.general">[[locale.ctype.general]]</a>
972
+
973
+ ``` cpp
974
+ namespace std {
975
+ template<class charT>
976
+ class ctype : public locale::facet, public ctype_base {
977
+ public:
978
+ using char_type = charT;
979
+
980
+ explicit ctype(size_t refs = 0);
981
+
982
+ bool is(mask m, charT c) const;
983
+ const charT* is(const charT* low, const charT* high, mask* vec) const;
984
+ const charT* scan_is(mask m, const charT* low, const charT* high) const;
985
+ const charT* scan_not(mask m, const charT* low, const charT* high) const;
986
+ charT toupper(charT c) const;
987
+ const charT* toupper(charT* low, const charT* high) const;
988
+ charT tolower(charT c) const;
989
+ const charT* tolower(charT* low, const charT* high) const;
990
+
991
+ charT widen(char c) const;
992
+ const char* widen(const char* low, const char* high, charT* to) const;
993
+ char narrow(charT c, char dfault) const;
994
+ const charT* narrow(const charT* low, const charT* high, char dfault, char* to) const;
995
+
996
+ static locale::id id;
997
+
998
+ protected:
999
+ ~ctype();
1000
+ virtual bool do_is(mask m, charT c) const;
1001
+ virtual const charT* do_is(const charT* low, const charT* high, mask* vec) const;
1002
+ virtual const charT* do_scan_is(mask m, const charT* low, const charT* high) const;
1003
+ virtual const charT* do_scan_not(mask m, const charT* low, const charT* high) const;
1004
+ virtual charT do_toupper(charT) const;
1005
+ virtual const charT* do_toupper(charT* low, const charT* high) const;
1006
+ virtual charT do_tolower(charT) const;
1007
+ virtual const charT* do_tolower(charT* low, const charT* high) const;
1008
+ virtual charT do_widen(char) const;
1009
+ virtual const char* do_widen(const char* low, const char* high, charT* dest) const;
1010
+ virtual char do_narrow(charT, char dfault) const;
1011
+ virtual const charT* do_narrow(const charT* low, const charT* high,
1012
+ char dfault, char* dest) const;
1013
+ };
1014
+ }
1015
+ ```
1016
+
1017
+ Class `ctype` encapsulates the C library `<cctype>` features. `istream`
1018
+ members are required to use `ctype<>` for character classing during
1019
+ input parsing.
1020
+
1021
+ The specializations required in [[locale.category.facets]]
1022
+ [[locale.category]], namely `ctype<char>` and `ctype<wchar_t>`,
1023
+ implement character classing appropriate to the implementation’s native
1024
+ character set.
1025
+
1026
+ ###### `ctype` members <a id="locale.ctype.members">[[locale.ctype.members]]</a>
1027
+
1028
+ ``` cpp
1029
+ bool is(mask m, charT c) const;
1030
+ const charT* is(const charT* low, const charT* high, mask* vec) const;
1031
+ ```
1032
+
1033
+ *Returns:* `do_is(m, c)` or `do_is(low, high, vec)`.
1034
+
1035
+ ``` cpp
1036
+ const charT* scan_is(mask m, const charT* low, const charT* high) const;
1037
+ ```
1038
+
1039
+ *Returns:* `do_scan_is(m, low, high)`.
1040
+
1041
+ ``` cpp
1042
+ const charT* scan_not(mask m, const charT* low, const charT* high) const;
1043
+ ```
1044
+
1045
+ *Returns:* `do_scan_not(m, low, high)`.
1046
+
1047
+ ``` cpp
1048
+ charT toupper(charT c) const;
1049
+ const charT* toupper(charT* low, const charT* high) const;
1050
+ ```
1051
+
1052
+ *Returns:* `do_toupper(c)` or `do_toupper(low, high)`.
1053
+
1054
+ ``` cpp
1055
+ charT tolower(charT c) const;
1056
+ const charT* tolower(charT* low, const charT* high) const;
1057
+ ```
1058
+
1059
+ *Returns:* `do_tolower(c)` or `do_tolower(low, high)`.
1060
+
1061
+ ``` cpp
1062
+ charT widen(char c) const;
1063
+ const char* widen(const char* low, const char* high, charT* to) const;
1064
+ ```
1065
+
1066
+ *Returns:* `do_widen(c)` or `do_widen(low, high, to)`.
1067
+
1068
+ ``` cpp
1069
+ char narrow(charT c, char dfault) const;
1070
+ const charT* narrow(const charT* low, const charT* high, char dfault, char* to) const;
1071
+ ```
1072
+
1073
+ *Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`.
1074
+
1075
+ ###### `ctype` virtual functions <a id="locale.ctype.virtuals">[[locale.ctype.virtuals]]</a>
1076
+
1077
+ ``` cpp
1078
+ bool do_is(mask m, charT c) const;
1079
+ const charT* do_is(const charT* low, const charT* high, mask* vec) const;
1080
+ ```
1081
+
1082
+ *Effects:* Classifies a character or sequence of characters. For each
1083
+ argument character, identifies a value `M` of type `ctype_base::mask`.
1084
+ The second form identifies a value `M` of type `ctype_base::mask` for
1085
+ each `*p` where `(low <= p && p < high)`, and places it into
1086
+ `vec[p - low]`.
1087
+
1088
+ *Returns:* The first form returns the result of the expression
1089
+ `(M & m) != 0`; i.e., `true` if the character has the characteristics
1090
+ specified. The second form returns `high`.
1091
+
1092
+ ``` cpp
1093
+ const charT* do_scan_is(mask m, const charT* low, const charT* high) const;
1094
+ ```
1095
+
1096
+ *Effects:* Locates a character in a buffer that conforms to a
1097
+ classification `m`.
1098
+
1099
+ *Returns:* The smallest pointer `p` in the range \[`low`, `high`) such
1100
+ that `is(m, *p)` would return `true`; otherwise, returns `high`.
1101
+
1102
+ ``` cpp
1103
+ const charT* do_scan_not(mask m, const charT* low, const charT* high) const;
1104
+ ```
1105
+
1106
+ *Effects:* Locates a character in a buffer that fails to conform to a
1107
+ classification `m`.
1108
+
1109
+ *Returns:* The smallest pointer `p`, if any, in the range \[`low`,
1110
+ `high`) such that `is(m, *p)` would return `false`; otherwise, returns
1111
+ `high`.
1112
+
1113
+ ``` cpp
1114
+ charT do_toupper(charT c) const;
1115
+ const charT* do_toupper(charT* low, const charT* high) const;
1116
+ ```
1117
+
1118
+ *Effects:* Converts a character or characters to upper case. The second
1119
+ form replaces each character `*p` in the range \[`low`, `high`) for
1120
+ which a corresponding upper-case character exists, with that character.
1121
+
1122
+ *Returns:* The first form returns the corresponding upper-case character
1123
+ if it is known to exist, or its argument if not. The second form returns
1124
+ `high`.
1125
+
1126
+ ``` cpp
1127
+ charT do_tolower(charT c) const;
1128
+ const charT* do_tolower(charT* low, const charT* high) const;
1129
+ ```
1130
+
1131
+ *Effects:* Converts a character or characters to lower case. The second
1132
+ form replaces each character `*p` in the range \[`low`, `high`) and for
1133
+ which a corresponding lower-case character exists, with that character.
1134
+
1135
+ *Returns:* The first form returns the corresponding lower-case character
1136
+ if it is known to exist, or its argument if not. The second form returns
1137
+ `high`.
1138
+
1139
+ ``` cpp
1140
+ charT do_widen(char c) const;
1141
+ const char* do_widen(const char* low, const char* high, charT* dest) const;
1142
+ ```
1143
+
1144
+ *Effects:* Applies the simplest reasonable transformation from a `char`
1145
+ value or sequence of `char` values to the corresponding `charT` value or
1146
+ values.[^5]
1147
+
1148
+ The only characters for which unique transformations are required are
1149
+ those in the basic character set [[lex.charset]].
1150
+
1151
+ For any named `ctype` category with a `ctype<char>` facet `ctc` and
1152
+ valid `ctype_base::mask` value `M`,
1153
+ `(ctc.is(M, c) || !is(M, do_widen(c)) )` is `true`.[^6]
1154
+
1155
+ The second form transforms each character `*p` in the range \[`low`,
1156
+ `high`), placing the result in `dest[p - low]`.
1157
+
1158
+ *Returns:* The first form returns the transformed value. The second form
1159
+ returns `high`.
1160
+
1161
+ ``` cpp
1162
+ char do_narrow(charT c, char dfault) const;
1163
+ const charT* do_narrow(const charT* low, const charT* high, char dfault, char* dest) const;
1164
+ ```
1165
+
1166
+ *Effects:* Applies the simplest reasonable transformation from a `charT`
1167
+ value or sequence of `charT` values to the corresponding `char` value or
1168
+ values.
1169
+
1170
+ For any character `c` in the basic character set [[lex.charset]] the
1171
+ transformation is such that
1172
+
1173
+ ``` cpp
1174
+ do_widen(do_narrow(c, 0)) == c
1175
+ ```
1176
+
1177
+ For any named `ctype` category with a `ctype<char>` facet `ctc` however,
1178
+ and `ctype_base::mask` value `M`,
1179
+
1180
+ ``` cpp
1181
+ (is(M, c) || !ctc.is(M, do_narrow(c, dfault)) )
1182
+ ```
1183
+
1184
+ is `true` (unless `do_narrow` returns `dfault`). In addition, for any
1185
+ digit character `c`, the expression `(do_narrow(c, dfault) - ’0’)`
1186
+ evaluates to the digit value of the character. The second form
1187
+ transforms each character `*p` in the range \[`low`, `high`), placing
1188
+ the result (or `dfault` if no simple transformation is readily
1189
+ available) in `dest[p - low]`.
1190
+
1191
+ *Returns:* The first form returns the transformed value; or `dfault` if
1192
+ no mapping is readily available. The second form returns `high`.
1193
+
1194
+ ##### Class template `ctype_byname` <a id="locale.ctype.byname">[[locale.ctype.byname]]</a>
1195
+
1196
+ ``` cpp
1197
+ namespace std {
1198
+ template<class charT>
1199
+ class ctype_byname : public ctype<charT> {
1200
+ public:
1201
+ using mask = ctype<charT>::mask;
1202
+ explicit ctype_byname(const char*, size_t refs = 0);
1203
+ explicit ctype_byname(const string&, size_t refs = 0);
1204
+
1205
+ protected:
1206
+ ~ctype_byname();
1207
+ };
1208
+ }
1209
+ ```
1210
+
1211
+ ##### `ctype<char>` specialization <a id="facet.ctype.special">[[facet.ctype.special]]</a>
1212
+
1213
+ ###### General <a id="facet.ctype.special.general">[[facet.ctype.special.general]]</a>
1214
+
1215
+ ``` cpp
1216
+ namespace std {
1217
+ template<>
1218
+ class ctype<char> : public locale::facet, public ctype_base {
1219
+ public:
1220
+ using char_type = char;
1221
+
1222
+ explicit ctype(const mask* tab = nullptr, bool del = false, size_t refs = 0);
1223
+
1224
+ bool is(mask m, char c) const;
1225
+ const char* is(const char* low, const char* high, mask* vec) const;
1226
+ const char* scan_is (mask m, const char* low, const char* high) const;
1227
+ const char* scan_not(mask m, const char* low, const char* high) const;
1228
+
1229
+ char toupper(char c) const;
1230
+ const char* toupper(char* low, const char* high) const;
1231
+ char tolower(char c) const;
1232
+ const char* tolower(char* low, const char* high) const;
1233
+
1234
+ char widen(char c) const;
1235
+ const char* widen(const char* low, const char* high, char* to) const;
1236
+ char narrow(char c, char dfault) const;
1237
+ const char* narrow(const char* low, const char* high, char dfault, char* to) const;
1238
+
1239
+ static locale::id id;
1240
+ static const size_t table_size = implementation-defined;
1241
+
1242
+ const mask* table() const noexcept;
1243
+ static const mask* classic_table() noexcept;
1244
+
1245
+ protected:
1246
+ ~ctype();
1247
+ virtual char do_toupper(char c) const;
1248
+ virtual const char* do_toupper(char* low, const char* high) const;
1249
+ virtual char do_tolower(char c) const;
1250
+ virtual const char* do_tolower(char* low, const char* high) const;
1251
+
1252
+ virtual char do_widen(char c) const;
1253
+ virtual const char* do_widen(const char* low, const char* high, char* to) const;
1254
+ virtual char do_narrow(char c, char dfault) const;
1255
+ virtual const char* do_narrow(const char* low, const char* high,
1256
+ char dfault, char* to) const;
1257
+ };
1258
+ }
1259
+ ```
1260
+
1261
+ A specialization `ctype<char>` is provided so that the member functions
1262
+ on type `char` can be implemented inline.[^7]
1263
+
1264
+ The *implementation-defined* value of member `table_size` is at least
1265
+ 256.
1266
+
1267
+ ###### Destructor <a id="facet.ctype.char.dtor">[[facet.ctype.char.dtor]]</a>
1268
+
1269
+ ``` cpp
1270
+ ~ctype();
1271
+ ```
1272
+
1273
+ *Effects:* If the constructor’s first argument was nonzero, and its
1274
+ second argument was `true`, does `delete [] table()`.
1275
+
1276
+ ###### Members <a id="facet.ctype.char.members">[[facet.ctype.char.members]]</a>
1277
+
1278
+ In the following member descriptions, for `unsigned char` values `v`
1279
+ where `v >= table_size`, `table()[v]` is assumed to have an
1280
+ implementation-specific value (possibly different for each such value
1281
+ `v`) without performing the array lookup.
1282
+
1283
+ ``` cpp
1284
+ explicit ctype(const mask* tbl = nullptr, bool del = false, size_t refs = 0);
1285
+ ```
1286
+
1287
+ *Preconditions:* Either `tbl == nullptr` is `true` or \[`tbl`,
1288
+ `tbl + table_size`) is a valid range.
1289
+
1290
+ *Effects:* Passes its `refs` argument to its base class constructor.
1291
+
1292
+ ``` cpp
1293
+ bool is(mask m, char c) const;
1294
+ const char* is(const char* low, const char* high, mask* vec) const;
1295
+ ```
1296
+
1297
+ *Effects:* The second form, for all `*p` in the range \[`low`, `high`),
1298
+ assigns into `vec[p - low]` the value `table()[(unsigned char)*p]`.
1299
+
1300
+ *Returns:* The first form returns `table()[(unsigned char)c] & m`; the
1301
+ second form returns `high`.
1302
+
1303
+ ``` cpp
1304
+ const char* scan_is(mask m, const char* low, const char* high) const;
1305
+ ```
1306
+
1307
+ *Returns:* The smallest `p` in the range \[`low`, `high`) such that
1308
+
1309
+ ``` cpp
1310
+ table()[(unsigned char) *p] & m
1311
+ ```
1312
+
1313
+ is `true`.
1314
+
1315
+ ``` cpp
1316
+ const char* scan_not(mask m, const char* low, const char* high) const;
1317
+ ```
1318
+
1319
+ *Returns:* The smallest `p` in the range \[`low`, `high`) such that
1320
+
1321
+ ``` cpp
1322
+ table()[(unsigned char) *p] & m
1323
+ ```
1324
+
1325
+ is `false`.
1326
+
1327
+ ``` cpp
1328
+ char toupper(char c) const;
1329
+ const char* toupper(char* low, const char* high) const;
1330
+ ```
1331
+
1332
+ *Returns:* `do_toupper(c)` or `do_toupper(low, high)`, respectively.
1333
+
1334
+ ``` cpp
1335
+ char tolower(char c) const;
1336
+ const char* tolower(char* low, const char* high) const;
1337
+ ```
1338
+
1339
+ *Returns:* `do_tolower(c)` or `do_tolower(low, high)`, respectively.
1340
+
1341
+ ``` cpp
1342
+ char widen(char c) const;
1343
+ const char* widen(const char* low, const char* high, char* to) const;
1344
+ ```
1345
+
1346
+ *Returns:* `do_widen(c)` or `do_widen(low, high, to)`, respectively.
1347
+
1348
+ ``` cpp
1349
+ char narrow(char c, char dfault) const;
1350
+ const char* narrow(const char* low, const char* high, char dfault, char* to) const;
1351
+ ```
1352
+
1353
+ *Returns:* `do_narrow(c, dfault)` or `do_narrow(low, high, dfault, to)`,
1354
+ respectively.
1355
+
1356
+ ``` cpp
1357
+ const mask* table() const noexcept;
1358
+ ```
1359
+
1360
+ *Returns:* The first constructor argument, if it was nonzero, otherwise
1361
+ `classic_table()`.
1362
+
1363
+ ###### Static members <a id="facet.ctype.char.statics">[[facet.ctype.char.statics]]</a>
1364
+
1365
+ ``` cpp
1366
+ static const mask* classic_table() noexcept;
1367
+ ```
1368
+
1369
+ *Returns:* A pointer to the initial element of an array of size
1370
+ `table_size` which represents the classifications of characters in the
1371
+ `"C"` locale.
1372
+
1373
+ ###### Virtual functions <a id="facet.ctype.char.virtuals">[[facet.ctype.char.virtuals]]</a>
1374
+
1375
+ ``` cpp
1376
+ char do_toupper(char) const;
1377
+ const char* do_toupper(char* low, const char* high) const;
1378
+ char do_tolower(char) const;
1379
+ const char* do_tolower(char* low, const char* high) const;
1380
+
1381
+ virtual char do_widen(char c) const;
1382
+ virtual const char* do_widen(const char* low, const char* high, char* to) const;
1383
+ virtual char do_narrow(char c, char dfault) const;
1384
+ virtual const char* do_narrow(const char* low, const char* high,
1385
+ char dfault, char* to) const;
1386
+ ```
1387
+
1388
+ These functions are described identically as those members of the same
1389
+ name in the `ctype` class template [[locale.ctype.members]].
1390
+
1391
+ ##### Class template `codecvt` <a id="locale.codecvt">[[locale.codecvt]]</a>
1392
+
1393
+ ###### General <a id="locale.codecvt.general">[[locale.codecvt.general]]</a>
1394
+
1395
+ ``` cpp
1396
+ namespace std {
1397
+ class codecvt_base {
1398
+ public:
1399
+ enum result { ok, partial, error, noconv };
1400
+ };
1401
+
1402
+ template<class internT, class externT, class stateT>
1403
+ class codecvt : public locale::facet, public codecvt_base {
1404
+ public:
1405
+ using intern_type = internT;
1406
+ using extern_type = externT;
1407
+ using state_type = stateT;
1408
+
1409
+ explicit codecvt(size_t refs = 0);
1410
+
1411
+ result out(
1412
+ stateT& state,
1413
+ const internT* from, const internT* from_end, const internT*& from_next,
1414
+ externT* to, externT* to_end, externT*& to_next) const;
1415
+
1416
+ result unshift(
1417
+ stateT& state,
1418
+ externT* to, externT* to_end, externT*& to_next) const;
1419
+
1420
+ result in(
1421
+ stateT& state,
1422
+ const externT* from, const externT* from_end, const externT*& from_next,
1423
+ internT* to, internT* to_end, internT*& to_next) const;
1424
+
1425
+ int encoding() const noexcept;
1426
+ bool always_noconv() const noexcept;
1427
+ int length(stateT&, const externT* from, const externT* end, size_t max) const;
1428
+ int max_length() const noexcept;
1429
+
1430
+ static locale::id id;
1431
+
1432
+ protected:
1433
+ ~codecvt();
1434
+ virtual result do_out(
1435
+ stateT& state,
1436
+ const internT* from, const internT* from_end, const internT*& from_next,
1437
+ externT* to, externT* to_end, externT*& to_next) const;
1438
+ virtual result do_in(
1439
+ stateT& state,
1440
+ const externT* from, const externT* from_end, const externT*& from_next,
1441
+ internT* to, internT* to_end, internT*& to_next) const;
1442
+ virtual result do_unshift(
1443
+ stateT& state,
1444
+ externT* to, externT* to_end, externT*& to_next) const;
1445
+
1446
+ virtual int do_encoding() const noexcept;
1447
+ virtual bool do_always_noconv() const noexcept;
1448
+ virtual int do_length(stateT&, const externT* from, const externT* end, size_t max) const;
1449
+ virtual int do_max_length() const noexcept;
1450
+ };
1451
+ }
1452
+ ```
1453
+
1454
+ The class `codecvt<internT, externT, stateT>` is for use when converting
1455
+ from one character encoding to another, such as from wide characters to
1456
+ multibyte characters or between wide character encodings such as UTF-32
1457
+ and EUC.
1458
+
1459
+ The `stateT` argument selects the pair of character encodings being
1460
+ mapped between.
1461
+
1462
+ The specializations required in [[locale.category.facets]]
1463
+ [[locale.category]] convert the implementation-defined native character
1464
+ set. `codecvt<char, char, mbstate_t>` implements a degenerate
1465
+ conversion; it does not convert at all.
1466
+ `codecvt<wchar_t, char, mbstate_t>` converts between the native
1467
+ character sets for ordinary and wide characters. Specializations on
1468
+ `mbstate_t` perform conversion between encodings known to the library
1469
+ implementer. Other encodings can be converted by specializing on a
1470
+ program-defined `stateT` type. Objects of type `stateT` can contain any
1471
+ state that is useful to communicate to or from the specialized `do_in`
1472
+ or `do_out` members.
1473
+
1474
+ ###### Members <a id="locale.codecvt.members">[[locale.codecvt.members]]</a>
1475
+
1476
+ ``` cpp
1477
+ result out(
1478
+ stateT& state,
1479
+ const internT* from, const internT* from_end, const internT*& from_next,
1480
+ externT* to, externT* to_end, externT*& to_next) const;
1481
+ ```
1482
+
1483
+ *Returns:*
1484
+ `do_out(state, from, from_end, from_next, to, to_end, to_next)`.
1485
+
1486
+ ``` cpp
1487
+ result unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
1488
+ ```
1489
+
1490
+ *Returns:* `do_unshift(state, to, to_end, to_next)`.
1491
+
1492
+ ``` cpp
1493
+ result in(
1494
+ stateT& state,
1495
+ const externT* from, const externT* from_end, const externT*& from_next,
1496
+ internT* to, internT* to_end, internT*& to_next) const;
1497
+ ```
1498
+
1499
+ *Returns:*
1500
+ `do_in(state, from, from_end, from_next, to, to_end, to_next)`.
1501
+
1502
+ ``` cpp
1503
+ int encoding() const noexcept;
1504
+ ```
1505
+
1506
+ *Returns:* `do_encoding()`.
1507
+
1508
+ ``` cpp
1509
+ bool always_noconv() const noexcept;
1510
+ ```
1511
+
1512
+ *Returns:* `do_always_noconv()`.
1513
+
1514
+ ``` cpp
1515
+ int length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
1516
+ ```
1517
+
1518
+ *Returns:* `do_length(state, from, from_end, max)`.
1519
+
1520
+ ``` cpp
1521
+ int max_length() const noexcept;
1522
+ ```
1523
+
1524
+ *Returns:* `do_max_length()`.
1525
+
1526
+ ###### Virtual functions <a id="locale.codecvt.virtuals">[[locale.codecvt.virtuals]]</a>
1527
+
1528
+ ``` cpp
1529
+ result do_out(
1530
+ stateT& state,
1531
+ const internT* from, const internT* from_end, const internT*& from_next,
1532
+ externT* to, externT* to_end, externT*& to_next) const;
1533
+
1534
+ result do_in(
1535
+ stateT& state,
1536
+ const externT* from, const externT* from_end, const externT*& from_next,
1537
+ internT* to, internT* to_end, internT*& to_next) const;
1538
+ ```
1539
+
1540
+ *Preconditions:* `(from <= from_end && to <= to_end)` is well-defined
1541
+ and `true`; `state` is initialized, if at the beginning of a sequence,
1542
+ or else is equal to the result of converting the preceding characters in
1543
+ the sequence.
1544
+
1545
+ *Effects:* Translates characters in the source range \[`from`,
1546
+ `from_end`), placing the results in sequential positions starting at
1547
+ destination `to`. Converts no more than `(from_end - from)` source
1548
+ elements, and stores no more than `(to_end - to)` destination elements.
1549
+
1550
+ Stops if it encounters a character it cannot convert. It always leaves
1551
+ the `from_next` and `to_next` pointers pointing one beyond the last
1552
+ element successfully converted. If it returns `noconv`, `internT` and
1553
+ `externT` are the same type, and the converted sequence is identical to
1554
+ the input sequence \[`from`, `from``next`), `to_next` is set equal to
1555
+ `to`, the value of `state` is unchanged, and there are no changes to the
1556
+ values in \[`to`, `to_end`).
1557
+
1558
+ A `codecvt` facet that is used by `basic_filebuf` [[file.streams]] shall
1559
+ have the property that if
1560
+
1561
+ ``` cpp
1562
+ do_out(state, from, from_end, from_next, to, to_end, to_next)
1563
+ ```
1564
+
1565
+ would return `ok`, where `from != from_end`, then
1566
+
1567
+ ``` cpp
1568
+ do_out(state, from, from + 1, from_next, to, to_end, to_next)
1569
+ ```
1570
+
1571
+ shall also return `ok`, and that if
1572
+
1573
+ ``` cpp
1574
+ do_in(state, from, from_end, from_next, to, to_end, to_next)
1575
+ ```
1576
+
1577
+ would return `ok`, where `to != to_end`, then
1578
+
1579
+ ``` cpp
1580
+ do_in(state, from, from_end, from_next, to, to + 1, to_next)
1581
+ ```
1582
+
1583
+ shall also return `ok`.[^8]
1584
+
1585
+ [*Note 1*: As a result of operations on `state`, it can return `ok` or
1586
+ `partial` and set `from_next == from` and
1587
+ `to_next != to`. — *end note*]
1588
+
1589
+ *Returns:* An enumeration value, as summarized in
1590
+ [[locale.codecvt.inout]].
1591
+
1592
+ **Table: `do_in/do_out` result values** <a id="locale.codecvt.inout">[locale.codecvt.inout]</a>
1593
+
1594
+ | Value | Meaning |
1595
+ | --------- | ------------------------------------------------------------------------------------------------ |
1596
+ | `ok` | completed the conversion |
1597
+ | `partial` | not all source characters converted |
1598
+ | `error` | encountered a character in {[}`from`, `from_end`{)} that cannot be converted |
1599
+ | `noconv` | `internT` and `externT` are the same type, and input sequence is identical to converted sequence |
1600
+
1601
+
1602
+ A return value of `partial`, if `(from_next == from_end)`, indicates
1603
+ that either the destination sequence has not absorbed all the available
1604
+ destination elements, or that additional source elements are needed
1605
+ before another destination element can be produced.
1606
+
1607
+ *Remarks:* Its operations on `state` are unspecified.
1608
+
1609
+ [*Note 2*: This argument can be used, for example, to maintain shift
1610
+ state, to specify conversion options (such as count only), or to
1611
+ identify a cache of seek offsets. — *end note*]
1612
+
1613
+ ``` cpp
1614
+ result do_unshift(stateT& state, externT* to, externT* to_end, externT*& to_next) const;
1615
+ ```
1616
+
1617
+ *Preconditions:* `(to <= to_end)` is well-defined and `true`; `state` is
1618
+ initialized, if at the beginning of a sequence, or else is equal to the
1619
+ result of converting the preceding characters in the sequence.
1620
+
1621
+ *Effects:* Places characters starting at `to` that should be appended to
1622
+ terminate a sequence when the current `stateT` is given by `state`.[^9]
1623
+
1624
+ Stores no more than `(to_end - to)` destination elements, and leaves the
1625
+ `to_next` pointer pointing one beyond the last element successfully
1626
+ stored.
1627
+
1628
+ *Returns:* An enumeration value, as summarized in
1629
+ [[locale.codecvt.unshift]].
1630
+
1631
+ **Table: `do_unshift` result values** <a id="locale.codecvt.unshift">[locale.codecvt.unshift]</a>
1632
+
1633
+ | Value | Meaning |
1634
+ | --------- | -------------------------------------------------------------------------------------------------------------------- |
1635
+ | `ok` | completed the sequence |
1636
+ | `partial` | space for more than `to_end - to` destination elements was needed to terminate a sequence given the value of `state` |
1637
+ | `error` | an unspecified error has occurred |
1638
+ | `noconv` | no termination is needed for this `state_type` |
1639
+
1640
+ ``` cpp
1641
+ int do_encoding() const noexcept;
1642
+ ```
1643
+
1644
+ *Returns:* `-1` if the encoding of the `externT` sequence is
1645
+ state-dependent; else the constant number of `externT` characters needed
1646
+ to produce an internal character; or `0` if this number is not a
1647
+ constant.[^10]
1648
+
1649
+ ``` cpp
1650
+ bool do_always_noconv() const noexcept;
1651
+ ```
1652
+
1653
+ *Returns:* `true` if `do_in()` and `do_out()` return `noconv` for all
1654
+ valid argument values. `codecvt<char, char, mbstate_t>` returns `true`.
1655
+
1656
+ ``` cpp
1657
+ int do_length(stateT& state, const externT* from, const externT* from_end, size_t max) const;
1658
+ ```
1659
+
1660
+ *Preconditions:* `(from <= from_end)` is well-defined and `true`;
1661
+ `state` is initialized, if at the beginning of a sequence, or else is
1662
+ equal to the result of converting the preceding characters in the
1663
+ sequence.
1664
+
1665
+ *Effects:* The effect on the `state` argument is as if it called
1666
+ `do_in(state, from, from_end, from, to, to + max, to)` for `to` pointing
1667
+ to a buffer of at least `max` elements.
1668
+
1669
+ *Returns:* `(from_next - from)` where `from_next` is the largest value
1670
+ in the range \[`from`, `from_end`\] such that the sequence of values in
1671
+ the range \[`from`, `from_next`) represents `max` or fewer valid
1672
+ complete characters of type `internT`. The specialization
1673
+ `codecvt<char, char, mbstate_t>`, returns the lesser of `max` and
1674
+ `(from_end - from)`.
1675
+
1676
+ ``` cpp
1677
+ int do_max_length() const noexcept;
1678
+ ```
1679
+
1680
+ *Returns:* The maximum value that `do_length(state, from, from_end, 1)`
1681
+ can return for any valid range \[`from`, `from_end`) and `stateT` value
1682
+ `state`. The specialization
1683
+ `codecvt<char, char, mbstate_t>::do_max_length()` returns 1.
1684
+
1685
+ ##### Class template `codecvt_byname` <a id="locale.codecvt.byname">[[locale.codecvt.byname]]</a>
1686
+
1687
+ ``` cpp
1688
+ namespace std {
1689
+ template<class internT, class externT, class stateT>
1690
+ class codecvt_byname : public codecvt<internT, externT, stateT> {
1691
+ public:
1692
+ explicit codecvt_byname(const char*, size_t refs = 0);
1693
+ explicit codecvt_byname(const string&, size_t refs = 0);
1694
+
1695
+ protected:
1696
+ ~codecvt_byname();
1697
+ };
1698
+ }
1699
+ ```
1700
+
1701
+ #### The numeric category <a id="category.numeric">[[category.numeric]]</a>
1702
+
1703
+ ##### General <a id="category.numeric.general">[[category.numeric.general]]</a>
1704
+
1705
+ The classes `num_get<>` and `num_put<>` handle numeric formatting and
1706
+ parsing. Virtual functions are provided for several numeric types.
1707
+ Implementations may (but are not required to) delegate extraction of
1708
+ smaller types to extractors for larger types.[^11]
1709
+
1710
+ All specifications of member functions for `num_put` and `num_get` in
1711
+ the subclauses of  [[category.numeric]] only apply to the
1712
+ specializations required in Tables  [[tab:locale.category.facets]] and 
1713
+ [[tab:locale.spec]] [[locale.category]], namely `num_get<char>`,
1714
+ `num_get<wchar_t>`, `num_get<C, InputIterator>`, `num_put<char>`,
1715
+ `num_put<wchar_t>`, and `num_put<C, OutputIterator>`. These
1716
+ specializations refer to the `ios_base&` argument for formatting
1717
+ specifications [[locale.categories]], and to its imbued locale for the
1718
+ `numpunct<>` facet to identify all numeric punctuation preferences, and
1719
+ also for the `ctype<>` facet to perform character classification.
1720
+
1721
+ Extractor and inserter members of the standard iostreams use `num_get<>`
1722
+ and `num_put<>` member functions for formatting and parsing numeric
1723
+ values [[istream.formatted.reqmts]], [[ostream.formatted.reqmts]].
1724
+
1725
+ ##### Class template `num_get` <a id="locale.num.get">[[locale.num.get]]</a>
1726
+
1727
+ ###### General <a id="locale.num.get.general">[[locale.num.get.general]]</a>
1728
+
1729
+ ``` cpp
1730
+ namespace std {
1731
+ template<class charT, class InputIterator = istreambuf_iterator<charT>>
1732
+ class num_get : public locale::facet {
1733
+ public:
1734
+ using char_type = charT;
1735
+ using iter_type = InputIterator;
1736
+
1737
+ explicit num_get(size_t refs = 0);
1738
+
1739
+ iter_type get(iter_type in, iter_type end, ios_base&,
1740
+ ios_base::iostate& err, bool& v) const;
1741
+ iter_type get(iter_type in, iter_type end, ios_base&,
1742
+ ios_base::iostate& err, long& v) const;
1743
+ iter_type get(iter_type in, iter_type end, ios_base&,
1744
+ ios_base::iostate& err, long long& v) const;
1745
+ iter_type get(iter_type in, iter_type end, ios_base&,
1746
+ ios_base::iostate& err, unsigned short& v) const;
1747
+ iter_type get(iter_type in, iter_type end, ios_base&,
1748
+ ios_base::iostate& err, unsigned int& v) const;
1749
+ iter_type get(iter_type in, iter_type end, ios_base&,
1750
+ ios_base::iostate& err, unsigned long& v) const;
1751
+ iter_type get(iter_type in, iter_type end, ios_base&,
1752
+ ios_base::iostate& err, unsigned long long& v) const;
1753
+ iter_type get(iter_type in, iter_type end, ios_base&,
1754
+ ios_base::iostate& err, float& v) const;
1755
+ iter_type get(iter_type in, iter_type end, ios_base&,
1756
+ ios_base::iostate& err, double& v) const;
1757
+ iter_type get(iter_type in, iter_type end, ios_base&,
1758
+ ios_base::iostate& err, long double& v) const;
1759
+ iter_type get(iter_type in, iter_type end, ios_base&,
1760
+ ios_base::iostate& err, void*& v) const;
1761
+
1762
+ static locale::id id;
1763
+
1764
+ protected:
1765
+ ~num_get();
1766
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1767
+ ios_base::iostate& err, bool& v) const;
1768
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1769
+ ios_base::iostate& err, long& v) const;
1770
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1771
+ ios_base::iostate& err, long long& v) const;
1772
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1773
+ ios_base::iostate& err, unsigned short& v) const;
1774
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1775
+ ios_base::iostate& err, unsigned int& v) const;
1776
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1777
+ ios_base::iostate& err, unsigned long& v) const;
1778
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1779
+ ios_base::iostate& err, unsigned long long& v) const;
1780
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1781
+ ios_base::iostate& err, float& v) const;
1782
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1783
+ ios_base::iostate& err, double& v) const;
1784
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1785
+ ios_base::iostate& err, long double& v) const;
1786
+ virtual iter_type do_get(iter_type, iter_type, ios_base&,
1787
+ ios_base::iostate& err, void*& v) const;
1788
+ };
1789
+ }
1790
+ ```
1791
+
1792
+ The facet `num_get` is used to parse numeric values from an input
1793
+ sequence such as an istream.
1794
+
1795
+ ###### Members <a id="facet.num.get.members">[[facet.num.get.members]]</a>
1796
+
1797
+ ``` cpp
1798
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1799
+ ios_base::iostate& err, bool& val) const;
1800
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1801
+ ios_base::iostate& err, long& val) const;
1802
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1803
+ ios_base::iostate& err, long long& val) const;
1804
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1805
+ ios_base::iostate& err, unsigned short& val) const;
1806
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1807
+ ios_base::iostate& err, unsigned int& val) const;
1808
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1809
+ ios_base::iostate& err, unsigned long& val) const;
1810
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1811
+ ios_base::iostate& err, unsigned long long& val) const;
1812
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1813
+ ios_base::iostate& err, float& val) const;
1814
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1815
+ ios_base::iostate& err, double& val) const;
1816
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1817
+ ios_base::iostate& err, long double& val) const;
1818
+ iter_type get(iter_type in, iter_type end, ios_base& str,
1819
+ ios_base::iostate& err, void*& val) const;
1820
+ ```
1821
+
1822
+ *Returns:* `do_get(in, end, str, err, val)`.
1823
+
1824
+ ###### Virtual functions <a id="facet.num.get.virtuals">[[facet.num.get.virtuals]]</a>
1825
+
1826
+ ``` cpp
1827
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1828
+ ios_base::iostate& err, long& val) const;
1829
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1830
+ ios_base::iostate& err, long long& val) const;
1831
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1832
+ ios_base::iostate& err, unsigned short& val) const;
1833
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1834
+ ios_base::iostate& err, unsigned int& val) const;
1835
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1836
+ ios_base::iostate& err, unsigned long& val) const;
1837
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1838
+ ios_base::iostate& err, unsigned long long& val) const;
1839
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1840
+ ios_base::iostate& err, float& val) const;
1841
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1842
+ ios_base::iostate& err, double& val) const;
1843
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1844
+ ios_base::iostate& err, long double& val) const;
1845
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1846
+ ios_base::iostate& err, void*& val) const;
1847
+ ```
1848
+
1849
+ *Effects:* Reads characters from `in`, interpreting them according to
1850
+ `str.flags()`, `use_facet<ctype<charT>>(loc)`, and
1851
+ `use_facet<numpunct<charT>>(loc)`, where `loc` is `str.getloc()`.
1852
+
1853
+ The details of this operation occur in three stages:
1854
+
1855
+ - Stage 1: Determine a conversion specifier.
1856
+ - Stage 2: Extract characters from `in` and determine a corresponding
1857
+ `char` value for the format expected by the conversion specification
1858
+ determined in stage 1.
1859
+ - Stage 3: Store results.
1860
+
1861
+ The details of the stages are presented below.
1862
+
1863
+ [*Example 1*:
1864
+
1865
+ Given an input sequence of `"0x1a.bp+07p"`,
1866
+
1867
+ - if the conversion specifier returned by Stage 1 is `%d`, `"0"` is
1868
+ accumulated;
1869
+ - if the conversion specifier returned by Stage 1 is `%i`, `"0x1a"` are
1870
+ accumulated;
1871
+ - if the conversion specifier returned by Stage 1 is `%g`,
1872
+ `"0x1a.bp+07"` are accumulated.
1873
+
1874
+ In all cases, the remainder is left in the input.
1875
+
1876
+ — *end example*]
1877
+
1878
+ Digit grouping is checked. That is, the positions of discarded
1879
+ separators are examined for consistency with
1880
+ `use_facet<numpunct<charT>>(loc).grouping()`. If they are not consistent
1881
+ then `ios_base::failbit` is assigned to `err`.
1882
+
1883
+ In any case, if stage 2 processing was terminated by the test for
1884
+ `in == end` then `err |= ios_base::eofbit` is performed.
1885
+
1886
+ ``` cpp
1887
+ iter_type do_get(iter_type in, iter_type end, ios_base& str,
1888
+ ios_base::iostate& err, bool& val) const;
1889
+ ```
1890
+
1891
+ *Effects:* If `(str.flags() & ios_base::boolalpha) == 0` then input
1892
+ proceeds as it would for a `long` except that if a value is being stored
1893
+ into `val`, the value is determined according to the following: If the
1894
+ value to be stored is 0 then `false` is stored. If the value is `1` then
1895
+ `true` is stored. Otherwise `true` is stored and `ios_base::failbit` is
1896
+ assigned to `err`.
1897
+
1898
+ Otherwise target sequences are determined “as if” by calling the members
1899
+ `falsename()` and `truename()` of the facet obtained by
1900
+ `use_facet<numpunct<charT>>(str.getloc())`. Successive characters in the
1901
+ range \[`in`, `end`) (see  [[sequence.reqmts]]) are obtained and matched
1902
+ against corresponding positions in the target sequences only as
1903
+ necessary to identify a unique match. The input iterator `in` is
1904
+ compared to `end` only when necessary to obtain a character. If a target
1905
+ sequence is uniquely matched, `val` is set to the corresponding value.
1906
+ Otherwise `false` is stored and `ios_base::failbit` is assigned to
1907
+ `err`.
1908
+
1909
+ The `in` iterator is always left pointing one position beyond the last
1910
+ character successfully matched. If `val` is set, then `err` is set to
1911
+ `str.goodbit`; or to `str.eofbit` if, when seeking another character to
1912
+ match, it is found that `(in == end)`. If `val` is not set, then `err`
1913
+ is set to `str.failbit`; or to `(str.failbit | str.eofbit)` if the
1914
+ reason for the failure was that `(in == end)`.
1915
+
1916
+ [*Example 2*: For targets `true`: `"a"` and `false`: `"abb"`, the input
1917
+ sequence `"a"` yields `val == true` and `err == str.eofbit`; the input
1918
+ sequence `"abc"` yields `err = str.failbit`, with `in` ending at the
1919
+ `’c’` element. For targets `true`: `"1"` and `false`: `"0"`, the input
1920
+ sequence `"1"` yields `val == true` and `err == str.goodbit`. For empty
1921
+ targets `("")`, any input sequence yields
1922
+ `err == str.failbit`. — *end example*]
1923
+
1924
+ *Returns:* `in`.
1925
+
1926
+ ##### Class template `num_put` <a id="locale.nm.put">[[locale.nm.put]]</a>
1927
+
1928
+ ###### General <a id="locale.nm.put.general">[[locale.nm.put.general]]</a>
1929
+
1930
+ ``` cpp
1931
+ namespace std {
1932
+ template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
1933
+ class num_put : public locale::facet {
1934
+ public:
1935
+ using char_type = charT;
1936
+ using iter_type = OutputIterator;
1937
+
1938
+ explicit num_put(size_t refs = 0);
1939
+
1940
+ iter_type put(iter_type s, ios_base& f, char_type fill, bool v) const;
1941
+ iter_type put(iter_type s, ios_base& f, char_type fill, long v) const;
1942
+ iter_type put(iter_type s, ios_base& f, char_type fill, long long v) const;
1943
+ iter_type put(iter_type s, ios_base& f, char_type fill, unsigned long v) const;
1944
+ iter_type put(iter_type s, ios_base& f, char_type fill, unsigned long long v) const;
1945
+ iter_type put(iter_type s, ios_base& f, char_type fill, double v) const;
1946
+ iter_type put(iter_type s, ios_base& f, char_type fill, long double v) const;
1947
+ iter_type put(iter_type s, ios_base& f, char_type fill, const void* v) const;
1948
+
1949
+ static locale::id id;
1950
+
1951
+ protected:
1952
+ ~num_put();
1953
+ virtual iter_type do_put(iter_type, ios_base&, char_type fill, bool v) const;
1954
+ virtual iter_type do_put(iter_type, ios_base&, char_type fill, long v) const;
1955
+ virtual iter_type do_put(iter_type, ios_base&, char_type fill, long long v) const;
1956
+ virtual iter_type do_put(iter_type, ios_base&, char_type fill, unsigned long) const;
1957
+ virtual iter_type do_put(iter_type, ios_base&, char_type fill, unsigned long long) const;
1958
+ virtual iter_type do_put(iter_type, ios_base&, char_type fill, double v) const;
1959
+ virtual iter_type do_put(iter_type, ios_base&, char_type fill, long double v) const;
1960
+ virtual iter_type do_put(iter_type, ios_base&, char_type fill, const void* v) const;
1961
+ };
1962
+ }
1963
+ ```
1964
+
1965
+ The facet `num_put` is used to format numeric values to a character
1966
+ sequence such as an ostream.
1967
+
1968
+ ###### Members <a id="facet.num.put.members">[[facet.num.put.members]]</a>
1969
+
1970
+ ``` cpp
1971
+ iter_type put(iter_type out, ios_base& str, char_type fill, bool val) const;
1972
+ iter_type put(iter_type out, ios_base& str, char_type fill, long val) const;
1973
+ iter_type put(iter_type out, ios_base& str, char_type fill, long long val) const;
1974
+ iter_type put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;
1975
+ iter_type put(iter_type out, ios_base& str, char_type fill, unsigned long long val) const;
1976
+ iter_type put(iter_type out, ios_base& str, char_type fill, double val) const;
1977
+ iter_type put(iter_type out, ios_base& str, char_type fill, long double val) const;
1978
+ iter_type put(iter_type out, ios_base& str, char_type fill, const void* val) const;
1979
+ ```
1980
+
1981
+ *Returns:* `do_put(out, str, fill, val)`.
1982
+
1983
+ ###### Virtual functions <a id="facet.num.put.virtuals">[[facet.num.put.virtuals]]</a>
1984
+
1985
+ ``` cpp
1986
+ iter_type do_put(iter_type out, ios_base& str, char_type fill, long val) const;
1987
+ iter_type do_put(iter_type out, ios_base& str, char_type fill, long long val) const;
1988
+ iter_type do_put(iter_type out, ios_base& str, char_type fill, unsigned long val) const;
1989
+ iter_type do_put(iter_type out, ios_base& str, char_type fill, unsigned long long val) const;
1990
+ iter_type do_put(iter_type out, ios_base& str, char_type fill, double val) const;
1991
+ iter_type do_put(iter_type out, ios_base& str, char_type fill, long double val) const;
1992
+ iter_type do_put(iter_type out, ios_base& str, char_type fill, const void* val) const;
1993
+ ```
1994
+
1995
+ *Effects:* Writes characters to the sequence `out`, formatting `val` as
1996
+ desired. In the following description, `loc` names a local variable
1997
+ initialized as
1998
+
1999
+ ``` cpp
2000
+ locale loc = str.getloc();
2001
+ ```
2002
+
2003
+ The details of this operation occur in several stages:
2004
+
2005
+ - Stage 1: Determine a printf conversion specifier `spec` and determine
2006
+ the characters that would be printed by `printf` [[c.files]] given
2007
+ this conversion specifier for
2008
+ ``` cpp
2009
+ printf(spec, val)
2010
+ ```
2011
+
2012
+ assuming that the current locale is the `"C"` locale.
2013
+ - Stage 2: Adjust the representation by converting each `char`
2014
+ determined by stage 1 to a `charT` using a conversion and values
2015
+ returned by members of `use_facet<numpunct<charT>>(loc)`.
2016
+ - Stage 3: Determine where padding is required.
2017
+ - Stage 4: Insert the sequence into the `out`.
2018
+
2019
+ Detailed descriptions of each stage follow.
2020
+
2021
+ *Returns:* `out`.
2022
+
2023
+ - **Stage 1:**
2024
+
2025
+ The first action of stage 1 is to determine a conversion specifier. The
2026
+ tables that describe this determination use the following local
2027
+ variables
2028
+
2029
+ ``` cpp
2030
+ fmtflags flags = str.flags();
2031
+ fmtflags basefield = (flags & (ios_base::basefield));
2032
+ fmtflags uppercase = (flags & (ios_base::uppercase));
2033
+ fmtflags floatfield = (flags & (ios_base::floatfield));
2034
+ fmtflags showpos = (flags & (ios_base::showpos));
2035
+ fmtflags showbase = (flags & (ios_base::showbase));
2036
+ fmtflags showpoint = (flags & (ios_base::showpoint));
2037
+ ```
2038
+
2039
+ All tables used in describing stage 1 are ordered. That is, the first
2040
+ line whose condition is true applies. A line without a condition is the
2041
+ default behavior when none of the earlier lines apply.
2042
+
2043
+ For conversion from an integral type other than a character type, the
2044
+ function determines the integral conversion specifier as indicated in
2045
+ [[facet.num.put.int]].
2046
+
2047
+ **Table: Integer conversions** <a id="facet.num.put.int">[facet.num.put.int]</a>
2048
+
2049
+ | State | `stdio` equivalent |
2050
+ | -------------------------------------------- | ------------------ |
2051
+ | `basefield == ios_base::oct` | `%o` |
2052
+ | `(basefield == ios_base::hex) && !uppercase` | `%x` |
2053
+ | `(basefield == ios_base::hex)` | `%X` |
2054
+ | for a `signed` integral type | `%d` |
2055
+ | for an `unsigned` integral type | `%u` |
2056
+
2057
+
2058
+ For conversion from a floating-point type, the function determines the
2059
+ floating-point conversion specifier as indicated in
2060
+ [[facet.num.put.fp]].
2061
+
2062
+ **Table: Floating-point conversions** <a id="facet.num.put.fp">[facet.num.put.fp]</a>
2063
+
2064
+ | State | `stdio` equivalent |
2065
+ | ---------------------------------------------------------------------- | ------------------ |
2066
+ | `floatfield == ios_base::fixed && !uppercase` | `%f` |
2067
+ | `floatfield == ios_base::fixed` | `%F` |
2068
+ | `floatfield == ios_base::scientific && !uppercase` | `%e` |
2069
+ | `floatfield == ios_base::scientific` | `%E` |
2070
+ | `floatfield == (ios_base::fixed | ios_base::scientific) && !uppercase` | `%a` |
2071
+ | `floatfield == (ios_base::fixed | ios_base::scientific)` | `%A` |
2072
+ | `!uppercase` | `%g` |
2073
+ | otherwise | `%G` |
2074
+
2075
+
2076
+ For conversions from an integral or floating-point type a length
2077
+ modifier is added to the conversion specifier as indicated in
2078
+ [[facet.num.put.length]].
2079
+
2080
+ **Table: Length modifier** <a id="facet.num.put.length">[facet.num.put.length]</a>
2081
+
2082
+ | Type | Length modifier |
2083
+ | -------------------- | --------------- |
2084
+ | `long` | `l` |
2085
+ | `long long` | `ll` |
2086
+ | `unsigned long` | `l` |
2087
+ | `unsigned long long` | `ll` |
2088
+ | `long double` | `L` |
2089
+ | otherwise | none |
2090
+
2091
+
2092
+ The conversion specifier has the following optional additional
2093
+ qualifiers prepended as indicated in [[facet.num.put.conv]].
2094
+
2095
+ **Table: Numeric conversions** <a id="facet.num.put.conv">[facet.num.put.conv]</a>
2096
+
2097
+ | Type(s) | State | `stdio` equivalent |
2098
+ | --------------------- | ----------- | ------------------ |
2099
+ | an integral type | `showpos` | `+` |
2100
+ | | `showbase` | `#` |
2101
+ | a floating-point type | `showpos` | `+` |
2102
+ | | `showpoint` | `#` |
2103
+
2104
+
2105
+ For conversion from a floating-point type, if
2106
+ `floatfield != (ios_base::fixed | ios_base::scientific)`,
2107
+ `str.precision()` is specified as precision in the conversion
2108
+ specification. Otherwise, no precision is specified.
2109
+
2110
+ For conversion from `void*` the specifier is `%p`.
2111
+
2112
+ The representations at the end of stage 1 consists of the `char`’s that
2113
+ would be printed by a call of `printf(s, val)` where `s` is the
2114
+ conversion specifier determined above.
2115
+
2116
+ - **Stage 2:**
2117
+
2118
+ Any character `c` other than a decimal point(.) is converted to a
2119
+ `charT` via
2120
+
2121
+ ``` cpp
2122
+ use_facet<ctype<charT>>(loc).widen(c)
2123
+ ```
2124
+
2125
+ A local variable `punct` is initialized via
2126
+
2127
+ ``` cpp
2128
+ const numpunct<charT>& punct = use_facet<numpunct<charT>>(loc);
2129
+ ```
2130
+
2131
+ For arithmetic types, `punct.thousands_sep()` characters are inserted
2132
+ into the sequence as determined by the value returned by
2133
+ `punct.do_grouping()` using the method described
2134
+ in [[facet.numpunct.virtuals]].
2135
+
2136
+ Decimal point characters(.) are replaced by `punct.decimal_point()`.
2137
+
2138
+ - **Stage 3:**
2139
+
2140
+ A local variable is initialized as
2141
+
2142
+ ``` cpp
2143
+ fmtflags adjustfield = (flags & (ios_base::adjustfield));
2144
+ ```
2145
+
2146
+ The location of any padding[^12]
2147
+
2148
+ is determined according to [[facet.num.put.fill]].
2149
+
2150
+ **Table: Fill padding** <a id="facet.num.put.fill">[facet.num.put.fill]</a>
2151
+
2152
+ | State | Location |
2153
+ | ------------------------------------------------------------------------------ | ------------------ |
2154
+ | `adjustfield == ios_base::left` | pad after |
2155
+ | `adjustfield == ios_base::right` | pad before |
2156
+ | `adjustfield == internal` and a sign occurs in the representation | pad after the sign |
2157
+ | `adjustfield == internal` and representation after stage 1 began with 0x or 0X | pad after x or X |
2158
+ | otherwise | pad before |
2159
+
2160
+
2161
+ If `str.width()` is nonzero and the number of `charT`’s in the sequence
2162
+ after stage 2 is less than `str.width()`, then enough `fill` characters
2163
+ are added to the sequence at the position indicated for padding to bring
2164
+ the length of the sequence to `str.width()`.
2165
+
2166
+ `str.width(0)` is called.
2167
+
2168
+ - **Stage 4:**
2169
+
2170
+ The sequence of `charT`’s at the end of stage 3 are output via
2171
+
2172
+ ``` cpp
2173
+ *out++ = c
2174
+ ```
2175
+
2176
+ ``` cpp
2177
+ iter_type do_put(iter_type out, ios_base& str, char_type fill, bool val) const;
2178
+ ```
2179
+
2180
+ *Returns:* If `(str.flags() & ios_base::boolalpha) == 0` returns
2181
+ `do_put(out, str, fill,`
2182
+ `(int)val)`, otherwise obtains a string `s` as if by
2183
+
2184
+ ``` cpp
2185
+ string_type s =
2186
+ val ? use_facet<numpunct<charT>>(loc).truename()
2187
+ : use_facet<numpunct<charT>>(loc).falsename();
2188
+ ```
2189
+
2190
+ and then inserts each character `c` of `s` into `out` via `*out++ = c`
2191
+ and returns `out`.
2192
+
2193
+ #### The numeric punctuation facet <a id="facet.numpunct">[[facet.numpunct]]</a>
2194
+
2195
+ ##### Class template `numpunct` <a id="locale.numpunct">[[locale.numpunct]]</a>
2196
+
2197
+ ###### General <a id="locale.numpunct.general">[[locale.numpunct.general]]</a>
2198
+
2199
+ ``` cpp
2200
+ namespace std {
2201
+ template<class charT>
2202
+ class numpunct : public locale::facet {
2203
+ public:
2204
+ using char_type = charT;
2205
+ using string_type = basic_string<charT>;
2206
+
2207
+ explicit numpunct(size_t refs = 0);
2208
+
2209
+ char_type decimal_point() const;
2210
+ char_type thousands_sep() const;
2211
+ string grouping() const;
2212
+ string_type truename() const;
2213
+ string_type falsename() const;
2214
+
2215
+ static locale::id id;
2216
+
2217
+ protected:
2218
+ ~numpunct(); // virtual
2219
+ virtual char_type do_decimal_point() const;
2220
+ virtual char_type do_thousands_sep() const;
2221
+ virtual string do_grouping() const;
2222
+ virtual string_type do_truename() const; // for bool
2223
+ virtual string_type do_falsename() const; // for bool
2224
+ };
2225
+ }
2226
+ ```
2227
+
2228
+ `numpunct<>` specifies numeric punctuation. The specializations required
2229
+ in [[locale.category.facets]] [[locale.category]], namely
2230
+ `numpunct<{}wchar_t>` and `numpunct<char>`, provide classic `"C"`
2231
+ numeric formats, i.e., they contain information equivalent to that
2232
+ contained in the `"C"` locale or their wide character counterparts as if
2233
+ obtained by a call to `widen`.
2234
+
2235
+ The syntax for number formats is as follows, where represents the radix
2236
+ set specified by the `fmtflags` argument value, and and are the results
2237
+ of corresponding `numpunct<charT>` members. Integer values have the
2238
+ format:
2239
+
2240
+ ``` bnf
2241
+ intval:
2242
+ signₒₚₜ units
2243
+ ```
2244
+
2245
+ ``` bnf
2246
+ sign:
2247
+ '+'
2248
+ '-'
2249
+ ```
2250
+
2251
+ ``` bnf
2252
+ units:
2253
+ digits
2254
+ digits thousands-sep units
2255
+ ```
2256
+
2257
+ ``` bnf
2258
+ digits:
2259
+ digit digitsₒₚₜ
2260
+ ```
2261
+
2262
+ and floating-point values have:
2263
+
2264
+ ``` bnf
2265
+ floatval:
2266
+ signₒₚₜ units fractionalₒₚₜ exponentₒₚₜ
2267
+ signₒₚₜ decimal-point digits exponentₒₚₜ
2268
+ ```
2269
+
2270
+ ``` bnf
2271
+ fractional:
2272
+ decimal-point digitsₒₚₜ
2273
+ ```
2274
+
2275
+ ``` bnf
2276
+ exponent:
2277
+ e signₒₚₜ digits
2278
+ ```
2279
+
2280
+ ``` bnf
2281
+ e:
2282
+ 'e'
2283
+ 'E'
2284
+ ```
2285
+
2286
+ where the number of digits between is as specified by `do_grouping()`.
2287
+ For parsing, if the portion contains no thousands-separators, no
2288
+ grouping constraint is applied.
2289
+
2290
+ ###### Members <a id="facet.numpunct.members">[[facet.numpunct.members]]</a>
2291
+
2292
+ ``` cpp
2293
+ char_type decimal_point() const;
2294
+ ```
2295
+
2296
+ *Returns:* `do_decimal_point()`.
2297
+
2298
+ ``` cpp
2299
+ char_type thousands_sep() const;
2300
+ ```
2301
+
2302
+ *Returns:* `do_thousands_sep()`.
2303
+
2304
+ ``` cpp
2305
+ string grouping() const;
2306
+ ```
2307
+
2308
+ *Returns:* `do_grouping()`.
2309
+
2310
+ ``` cpp
2311
+ string_type truename() const;
2312
+ string_type falsename() const;
2313
+ ```
2314
+
2315
+ *Returns:* `do_truename()` or `do_falsename()`, respectively.
2316
+
2317
+ ###### Virtual functions <a id="facet.numpunct.virtuals">[[facet.numpunct.virtuals]]</a>
2318
+
2319
+ ``` cpp
2320
+ char_type do_decimal_point() const;
2321
+ ```
2322
+
2323
+ *Returns:* A character for use as the decimal radix separator. The
2324
+ required specializations return `’.’` or `L’.’`.
2325
+
2326
+ ``` cpp
2327
+ char_type do_thousands_sep() const;
2328
+ ```
2329
+
2330
+ *Returns:* A character for use as the digit group separator. The
2331
+ required specializations return `’,’` or `L’,’`.
2332
+
2333
+ ``` cpp
2334
+ string do_grouping() const;
2335
+ ```
2336
+
2337
+ *Returns:* A `string` `vec` used as a vector of integer values, in which
2338
+ each element `vec[i]` represents the number of digits[^13]
2339
+
2340
+ in the group at position `i`, starting with position 0 as the rightmost
2341
+ group. If `vec.size() <= i`, the number is the same as group `(i - 1)`;
2342
+ if `(i < 0 || vec[i] <= 0 || vec[i] == CHAR_MAX)`, the size of the digit
2343
+ group is unlimited.
2344
+
2345
+ The required specializations return the empty string, indicating no
2346
+ grouping.
2347
+
2348
+ ``` cpp
2349
+ string_type do_truename() const;
2350
+ string_type do_falsename() const;
2351
+ ```
2352
+
2353
+ *Returns:* A string representing the name of the boolean value `true` or
2354
+ `false`, respectively.
2355
+
2356
+ In the base class implementation these names are `"true"` and `"false"`,
2357
+ or `L"true"` and `L"false"`.
2358
+
2359
+ ##### Class template `numpunct_byname` <a id="locale.numpunct.byname">[[locale.numpunct.byname]]</a>
2360
+
2361
+ ``` cpp
2362
+ namespace std {
2363
+ template<class charT>
2364
+ class numpunct_byname : public numpunct<charT> {
2365
+ // this class is specialized for char and wchar_t.
2366
+ public:
2367
+ using char_type = charT;
2368
+ using string_type = basic_string<charT>;
2369
+
2370
+ explicit numpunct_byname(const char*, size_t refs = 0);
2371
+ explicit numpunct_byname(const string&, size_t refs = 0);
2372
+
2373
+ protected:
2374
+ ~numpunct_byname();
2375
+ };
2376
+ }
2377
+ ```
2378
+
2379
+ #### The collate category <a id="category.collate">[[category.collate]]</a>
2380
+
2381
+ ##### Class template `collate` <a id="locale.collate">[[locale.collate]]</a>
2382
+
2383
+ ###### General <a id="locale.collate.general">[[locale.collate.general]]</a>
2384
+
2385
+ ``` cpp
2386
+ namespace std {
2387
+ template<class charT>
2388
+ class collate : public locale::facet {
2389
+ public:
2390
+ using char_type = charT;
2391
+ using string_type = basic_string<charT>;
2392
+
2393
+ explicit collate(size_t refs = 0);
2394
+
2395
+ int compare(const charT* low1, const charT* high1,
2396
+ const charT* low2, const charT* high2) const;
2397
+ string_type transform(const charT* low, const charT* high) const;
2398
+ long hash(const charT* low, const charT* high) const;
2399
+
2400
+ static locale::id id;
2401
+
2402
+ protected:
2403
+ ~collate();
2404
+ virtual int do_compare(const charT* low1, const charT* high1,
2405
+ const charT* low2, const charT* high2) const;
2406
+ virtual string_type do_transform(const charT* low, const charT* high) const;
2407
+ virtual long do_hash (const charT* low, const charT* high) const;
2408
+ };
2409
+ }
2410
+ ```
2411
+
2412
+ The class `collate<charT>` provides features for use in the collation
2413
+ (comparison) and hashing of strings. A locale member function template,
2414
+ `operator()`, uses the collate facet to allow a locale to act directly
2415
+ as the predicate argument for standard algorithms [[algorithms]] and
2416
+ containers operating on strings. The specializations required in
2417
+ [[locale.category.facets]] [[locale.category]], namely `collate<char>`
2418
+ and `collate<wchar_t>`, apply lexicographical ordering
2419
+ [[alg.lex.comparison]].
2420
+
2421
+ Each function compares a string of characters `*p` in the range \[`low`,
2422
+ `high`).
2423
+
2424
+ ###### Members <a id="locale.collate.members">[[locale.collate.members]]</a>
2425
+
2426
+ ``` cpp
2427
+ int compare(const charT* low1, const charT* high1,
2428
+ const charT* low2, const charT* high2) const;
2429
+ ```
2430
+
2431
+ *Returns:* `do_compare(low1, high1, low2, high2)`.
2432
+
2433
+ ``` cpp
2434
+ string_type transform(const charT* low, const charT* high) const;
2435
+ ```
2436
+
2437
+ *Returns:* `do_transform(low, high)`.
2438
+
2439
+ ``` cpp
2440
+ long hash(const charT* low, const charT* high) const;
2441
+ ```
2442
+
2443
+ *Returns:* `do_hash(low, high)`.
2444
+
2445
+ ###### Virtual functions <a id="locale.collate.virtuals">[[locale.collate.virtuals]]</a>
2446
+
2447
+ ``` cpp
2448
+ int do_compare(const charT* low1, const charT* high1,
2449
+ const charT* low2, const charT* high2) const;
2450
+ ```
2451
+
2452
+ *Returns:* `1` if the first string is greater than the second, `-1` if
2453
+ less, zero otherwise. The specializations required in
2454
+ [[locale.category.facets]][[locale.category]], namely `collate<char>`
2455
+ and `collate<wchar_t>`, implement a lexicographical
2456
+ comparison [[alg.lex.comparison]].
2457
+
2458
+ ``` cpp
2459
+ string_type do_transform(const charT* low, const charT* high) const;
2460
+ ```
2461
+
2462
+ *Returns:* A `basic_string<charT>` value that, compared
2463
+ lexicographically with the result of calling `transform()` on another
2464
+ string, yields the same result as calling `do_compare()` on the same two
2465
+ strings.[^14]
2466
+
2467
+ ``` cpp
2468
+ long do_hash(const charT* low, const charT* high) const;
2469
+ ```
2470
+
2471
+ *Returns:* An integer value equal to the result of calling `hash()` on
2472
+ any other string for which `do_compare()` returns 0 (equal) when passed
2473
+ the two strings.
2474
+
2475
+ *Recommended practice:* The probability that the result equals that for
2476
+ another string which does not compare equal should be very small,
2477
+ approaching `(1.0/numeric_limits<unsigned long>::max())`.
2478
+
2479
+ ##### Class template `collate_byname` <a id="locale.collate.byname">[[locale.collate.byname]]</a>
2480
+
2481
+ ``` cpp
2482
+ namespace std {
2483
+ template<class charT>
2484
+ class collate_byname : public collate<charT> {
2485
+ public:
2486
+ using string_type = basic_string<charT>;
2487
+
2488
+ explicit collate_byname(const char*, size_t refs = 0);
2489
+ explicit collate_byname(const string&, size_t refs = 0);
2490
+
2491
+ protected:
2492
+ ~collate_byname();
2493
+ };
2494
+ }
2495
+ ```
2496
+
2497
+ #### The time category <a id="category.time">[[category.time]]</a>
2498
+
2499
+ ##### General <a id="category.time.general">[[category.time.general]]</a>
2500
+
2501
+ Templates `time_get<charT, InputIterator>` and
2502
+ `time_put<charT, OutputIterator>` provide date and time formatting and
2503
+ parsing. All specifications of member functions for `time_put` and
2504
+ `time_get` in the subclauses of  [[category.time]] only apply to the
2505
+ specializations required in Tables  [[tab:locale.category.facets]] and 
2506
+ [[tab:locale.spec]] [[locale.category]]. Their members use their
2507
+ `ios_base&`, `ios_base::iostate&`, and `fill` arguments as described in 
2508
+ [[locale.categories]], and the `ctype<>` facet, to determine formatting
2509
+ details.
2510
+
2511
+ ##### Class template `time_get` <a id="locale.time.get">[[locale.time.get]]</a>
2512
+
2513
+ ###### General <a id="locale.time.get.general">[[locale.time.get.general]]</a>
2514
+
2515
+ ``` cpp
2516
+ namespace std {
2517
+ class time_base {
2518
+ public:
2519
+ enum dateorder { no_order, dmy, mdy, ymd, ydm };
2520
+ };
2521
+
2522
+ template<class charT, class InputIterator = istreambuf_iterator<charT>>
2523
+ class time_get : public locale::facet, public time_base {
2524
+ public:
2525
+ using char_type = charT;
2526
+ using iter_type = InputIterator;
2527
+
2528
+ explicit time_get(size_t refs = 0);
2529
+
2530
+ dateorder date_order() const { return do_date_order(); }
2531
+ iter_type get_time(iter_type s, iter_type end, ios_base& f,
2532
+ ios_base::iostate& err, tm* t) const;
2533
+ iter_type get_date(iter_type s, iter_type end, ios_base& f,
2534
+ ios_base::iostate& err, tm* t) const;
2535
+ iter_type get_weekday(iter_type s, iter_type end, ios_base& f,
2536
+ ios_base::iostate& err, tm* t) const;
2537
+ iter_type get_monthname(iter_type s, iter_type end, ios_base& f,
2538
+ ios_base::iostate& err, tm* t) const;
2539
+ iter_type get_year(iter_type s, iter_type end, ios_base& f,
2540
+ ios_base::iostate& err, tm* t) const;
2541
+ iter_type get(iter_type s, iter_type end, ios_base& f,
2542
+ ios_base::iostate& err, tm* t, char format, char modifier = 0) const;
2543
+ iter_type get(iter_type s, iter_type end, ios_base& f,
2544
+ ios_base::iostate& err, tm* t, const char_type* fmt,
2545
+ const char_type* fmtend) const;
2546
+
2547
+ static locale::id id;
2548
+
2549
+ protected:
2550
+ ~time_get();
2551
+ virtual dateorder do_date_order() const;
2552
+ virtual iter_type do_get_time(iter_type s, iter_type end, ios_base&,
2553
+ ios_base::iostate& err, tm* t) const;
2554
+ virtual iter_type do_get_date(iter_type s, iter_type end, ios_base&,
2555
+ ios_base::iostate& err, tm* t) const;
2556
+ virtual iter_type do_get_weekday(iter_type s, iter_type end, ios_base&,
2557
+ ios_base::iostate& err, tm* t) const;
2558
+ virtual iter_type do_get_monthname(iter_type s, iter_type end, ios_base&,
2559
+ ios_base::iostate& err, tm* t) const;
2560
+ virtual iter_type do_get_year(iter_type s, iter_type end, ios_base&,
2561
+ ios_base::iostate& err, tm* t) const;
2562
+ virtual iter_type do_get(iter_type s, iter_type end, ios_base& f,
2563
+ ios_base::iostate& err, tm* t, char format, char modifier) const;
2564
+ };
2565
+ }
2566
+ ```
2567
+
2568
+ `time_get` is used to parse a character sequence, extracting components
2569
+ of a time or date into a `tm` object. Each `get` member parses a format
2570
+ as produced by a corresponding format specifier to `time_put<>::put`. If
2571
+ the sequence being parsed matches the correct format, the corresponding
2572
+ members of the `tm` argument are set to the values used to produce the
2573
+ sequence; otherwise either an error is reported or unspecified values
2574
+ are assigned.[^15]
2575
+
2576
+ If the end iterator is reached during parsing by any of the `get()`
2577
+ member functions, the member sets `ios_base::eofbit` in `err`.
2578
+
2579
+ ###### Members <a id="locale.time.get.members">[[locale.time.get.members]]</a>
2580
+
2581
+ ``` cpp
2582
+ dateorder date_order() const;
2583
+ ```
2584
+
2585
+ *Returns:* `do_date_order()`.
2586
+
2587
+ ``` cpp
2588
+ iter_type get_time(iter_type s, iter_type end, ios_base& str,
2589
+ ios_base::iostate& err, tm* t) const;
2590
+ ```
2591
+
2592
+ *Returns:* `do_get_time(s, end, str, err, t)`.
2593
+
2594
+ ``` cpp
2595
+ iter_type get_date(iter_type s, iter_type end, ios_base& str,
2596
+ ios_base::iostate& err, tm* t) const;
2597
+ ```
2598
+
2599
+ *Returns:* `do_get_date(s, end, str, err, t)`.
2600
+
2601
+ ``` cpp
2602
+ iter_type get_weekday(iter_type s, iter_type end, ios_base& str,
2603
+ ios_base::iostate& err, tm* t) const;
2604
+ iter_type get_monthname(iter_type s, iter_type end, ios_base& str,
2605
+ ios_base::iostate& err, tm* t) const;
2606
+ ```
2607
+
2608
+ *Returns:* `do_get_weekday(s, end, str, err, t)` or
2609
+ `do_get_monthname(s, end, str, err, t)`.
2610
+
2611
+ ``` cpp
2612
+ iter_type get_year(iter_type s, iter_type end, ios_base& str,
2613
+ ios_base::iostate& err, tm* t) const;
2614
+ ```
2615
+
2616
+ *Returns:* `do_get_year(s, end, str, err, t)`.
2617
+
2618
+ ``` cpp
2619
+ iter_type get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err,
2620
+ tm* t, char format, char modifier = 0) const;
2621
+ ```
2622
+
2623
+ *Returns:* `do_get(s, end, f, err, t, format, modifier)`.
2624
+
2625
+ ``` cpp
2626
+ iter_type get(iter_type s, iter_type end, ios_base& f, ios_base::iostate& err,
2627
+ tm* t, const char_type* fmt, const char_type* fmtend) const;
2628
+ ```
2629
+
2630
+ *Preconditions:* \[`fmt`, `fmtend`) is a valid range.
2631
+
2632
+ *Effects:* The function starts by evaluating `err = ios_base::goodbit`.
2633
+ It then enters a loop, reading zero or more characters from `s` at each
2634
+ iteration. Unless otherwise specified below, the loop terminates when
2635
+ the first of the following conditions holds:
2636
+
2637
+ - The expression `fmt == fmtend` evaluates to `true`.
2638
+ - The expression `err == ios_base::goodbit` evaluates to `false`.
2639
+ - The expression `s == end` evaluates to `true`, in which case the
2640
+ function evaluates `err = ios_base::eofbit | ios_base::failbit`.
2641
+ - The next element of `fmt` is equal to `’%’`, optionally followed by a
2642
+ modifier character, followed by a conversion specifier character,
2643
+ `format`, together forming a conversion specification valid for the
2644
+ POSIX function `strptime`. If the number of elements in the range
2645
+ \[`fmt`, `fmtend`) is not sufficient to unambiguously determine
2646
+ whether the conversion specification is complete and valid, the
2647
+ function evaluates `err = ios_base::failbit`. Otherwise, the function
2648
+ evaluates `s = do_get(s, end, f, err, t, format, modifier)`, where the
2649
+ value of `modifier` is `’\0’` when the optional modifier is absent
2650
+ from the conversion specification. If `err == ios_base::goodbit` holds
2651
+ after the evaluation of the expression, the function increments `fmt`
2652
+ to point just past the end of the conversion specification and
2653
+ continues looping.
2654
+ - The expression `isspace(*fmt, f.getloc())` evaluates to `true`, in
2655
+ which case the function first increments `fmt` until
2656
+ `fmt == fmtend || !isspace(*fmt, f.getloc())` evaluates to `true`,
2657
+ then advances `s` until `s == end || !isspace(*s, f.getloc())` is
2658
+ `true`, and finally resumes looping.
2659
+ - The next character read from `s` matches the element pointed to by
2660
+ `fmt` in a case-insensitive comparison, in which case the function
2661
+ evaluates `++fmt, ++s` and continues looping. Otherwise, the function
2662
+ evaluates `err = ios_base::failbit`.
2663
+
2664
+ [*Note 1*: The function uses the `ctype<charT>` facet installed in
2665
+ `f`’s locale to determine valid whitespace characters. It is unspecified
2666
+ by what means the function performs case-insensitive comparison or
2667
+ whether multi-character sequences are considered while doing
2668
+ so. — *end note*]
2669
+
2670
+ *Returns:* `s`.
2671
+
2672
+ ###### Virtual functions <a id="locale.time.get.virtuals">[[locale.time.get.virtuals]]</a>
2673
+
2674
+ ``` cpp
2675
+ dateorder do_date_order() const;
2676
+ ```
2677
+
2678
+ *Returns:* An enumeration value indicating the preferred order of
2679
+ components for those date formats that are composed of day, month, and
2680
+ year.[^16]
2681
+
2682
+ Returns `no_order` if the date format specified by `’x’` contains other
2683
+ variable components (e.g., Julian day, week number, week day).
2684
+
2685
+ ``` cpp
2686
+ iter_type do_get_time(iter_type s, iter_type end, ios_base& str,
2687
+ ios_base::iostate& err, tm* t) const;
2688
+ ```
2689
+
2690
+ *Effects:* Reads characters starting at `s` until it has extracted those
2691
+ `tm` members, and remaining format characters, used by `time_put<>::put`
2692
+ to produce the format specified by `"%H:%M:%S"`, or until it encounters
2693
+ an error or end of sequence.
2694
+
2695
+ *Returns:* An iterator pointing immediately beyond the last character
2696
+ recognized as possibly part of a valid time.
2697
+
2698
+ ``` cpp
2699
+ iter_type do_get_date(iter_type s, iter_type end, ios_base& str,
2700
+ ios_base::iostate& err, tm* t) const;
2701
+ ```
2702
+
2703
+ *Effects:* Reads characters starting at `s` until it has extracted those
2704
+ `tm` members and remaining format characters used by `time_put<>::put`
2705
+ to produce one of the following formats, or until it encounters an
2706
+ error. The format depends on the value returned by `date_order()` as
2707
+ shown in [[locale.time.get.dogetdate]].
2708
+
2709
+ **Table: `do_get_date` effects** <a id="locale.time.get.dogetdate">[locale.time.get.dogetdate]</a>
2710
+
2711
+ | `date_order()` | Format |
2712
+ | -------------- | ---------- |
2713
+ | `no_order` | `"%m%d%y"` |
2714
+ | `dmy` | `"%d%m%y"` |
2715
+ | `mdy` | `"%m%d%y"` |
2716
+ | `ymd` | `"%y%m%d"` |
2717
+ | `ydm` | `"%y%d%m"` |
2718
+
2719
+
2720
+ An implementation may also accept additional *implementation-defined*
2721
+ formats.
2722
+
2723
+ *Returns:* An iterator pointing immediately beyond the last character
2724
+ recognized as possibly part of a valid date.
2725
+
2726
+ ``` cpp
2727
+ iter_type do_get_weekday(iter_type s, iter_type end, ios_base& str,
2728
+ ios_base::iostate& err, tm* t) const;
2729
+ iter_type do_get_monthname(iter_type s, iter_type end, ios_base& str,
2730
+ ios_base::iostate& err, tm* t) const;
2731
+ ```
2732
+
2733
+ *Effects:* Reads characters starting at `s` until it has extracted the
2734
+ (perhaps abbreviated) name of a weekday or month. If it finds an
2735
+ abbreviation that is followed by characters that can match a full name,
2736
+ it continues reading until it matches the full name or fails. It sets
2737
+ the appropriate `tm` member accordingly.
2738
+
2739
+ *Returns:* An iterator pointing immediately beyond the last character
2740
+ recognized as part of a valid name.
2741
+
2742
+ ``` cpp
2743
+ iter_type do_get_year(iter_type s, iter_type end, ios_base& str,
2744
+ ios_base::iostate& err, tm* t) const;
2745
+ ```
2746
+
2747
+ *Effects:* Reads characters starting at `s` until it has extracted an
2748
+ unambiguous year identifier. It is *implementation-defined* whether
2749
+ two-digit year numbers are accepted, and (if so) what century they are
2750
+ assumed to lie in. Sets the `t->tm_year` member accordingly.
2751
+
2752
+ *Returns:* An iterator pointing immediately beyond the last character
2753
+ recognized as part of a valid year identifier.
2754
+
2755
+ ``` cpp
2756
+ iter_type do_get(iter_type s, iter_type end, ios_base& f,
2757
+ ios_base::iostate& err, tm* t, char format, char modifier) const;
2758
+ ```
2759
+
2760
+ *Preconditions:* `t` points to an object.
2761
+
2762
+ *Effects:* The function starts by evaluating `err = ios_base::goodbit`.
2763
+ It then reads characters starting at `s` until it encounters an error,
2764
+ or until it has extracted and assigned those `tm` members, and any
2765
+ remaining format characters, corresponding to a conversion specification
2766
+ appropriate for the POSIX function `strptime`, formed by concatenating
2767
+ `’%’`, the `modifier` character, when non-NUL, and the `format`
2768
+ character. When the concatenation fails to yield a complete valid
2769
+ directive the function leaves the object pointed to by `t` unchanged and
2770
+ evaluates `err |= ios_base::failbit`. When `s == end` evaluates to
2771
+ `true` after reading a character the function evaluates
2772
+ `err |= ios_base::eofbit`.
2773
+
2774
+ For complex conversion specifications such as `%c`, `%x`, or `%X`, or
2775
+ conversion specifications that involve the optional modifiers `E` or
2776
+ `O`, when the function is unable to unambiguously determine some or all
2777
+ `tm` members from the input sequence \[`s`, `end`), it evaluates
2778
+ `err |= ios_base::eofbit`. In such cases the values of those `tm`
2779
+ members are unspecified and may be outside their valid range.
2780
+
2781
+ *Returns:* An iterator pointing immediately beyond the last character
2782
+ recognized as possibly part of a valid input sequence for the given
2783
+ `format` and `modifier`.
2784
+
2785
+ *Remarks:* It is unspecified whether multiple calls to `do_get()` with
2786
+ the address of the same `tm` object will update the current contents of
2787
+ the object or simply overwrite its members. Portable programs should
2788
+ zero out the object before invoking the function.
2789
+
2790
+ ##### Class template `time_get_byname` <a id="locale.time.get.byname">[[locale.time.get.byname]]</a>
2791
+
2792
+ ``` cpp
2793
+ namespace std {
2794
+ template<class charT, class InputIterator = istreambuf_iterator<charT>>
2795
+ class time_get_byname : public time_get<charT, InputIterator> {
2796
+ public:
2797
+ using dateorder = time_base::dateorder;
2798
+ using iter_type = InputIterator;
2799
+
2800
+ explicit time_get_byname(const char*, size_t refs = 0);
2801
+ explicit time_get_byname(const string&, size_t refs = 0);
2802
+
2803
+ protected:
2804
+ ~time_get_byname();
2805
+ };
2806
+ }
2807
+ ```
2808
+
2809
+ ##### Class template `time_put` <a id="locale.time.put">[[locale.time.put]]</a>
2810
+
2811
+ ###### General <a id="locale.time.put.general">[[locale.time.put.general]]</a>
2812
+
2813
+ ``` cpp
2814
+ namespace std {
2815
+ template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
2816
+ class time_put : public locale::facet {
2817
+ public:
2818
+ using char_type = charT;
2819
+ using iter_type = OutputIterator;
2820
+
2821
+ explicit time_put(size_t refs = 0);
2822
+
2823
+ // the following is implemented in terms of other member functions.
2824
+ iter_type put(iter_type s, ios_base& f, char_type fill, const tm* tmb,
2825
+ const charT* pattern, const charT* pat_end) const;
2826
+ iter_type put(iter_type s, ios_base& f, char_type fill,
2827
+ const tm* tmb, char format, char modifier = 0) const;
2828
+
2829
+ static locale::id id;
2830
+
2831
+ protected:
2832
+ ~time_put();
2833
+ virtual iter_type do_put(iter_type s, ios_base&, char_type, const tm* t,
2834
+ char format, char modifier) const;
2835
+ };
2836
+ }
2837
+ ```
2838
+
2839
+ ###### Members <a id="locale.time.put.members">[[locale.time.put.members]]</a>
2840
+
2841
+ ``` cpp
2842
+ iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
2843
+ const charT* pattern, const charT* pat_end) const;
2844
+ iter_type put(iter_type s, ios_base& str, char_type fill, const tm* t,
2845
+ char format, char modifier = 0) const;
2846
+ ```
2847
+
2848
+ *Effects:* The first form steps through the sequence from `pattern` to
2849
+ `pat_end`, identifying characters that are part of a format sequence.
2850
+ Each character that is not part of a format sequence is written to `s`
2851
+ immediately, and each format sequence, as it is identified, results in a
2852
+ call to `do_put`; thus, format elements and other characters are
2853
+ interleaved in the output in the order in which they appear in the
2854
+ pattern. Format sequences are identified by converting each character
2855
+ `c` to a `char` value as if by `ct.narrow(c, 0)`, where `ct` is a
2856
+ reference to `ctype<charT>` obtained from `str.getloc()`. The first
2857
+ character of each sequence is equal to `’%’`, followed by an optional
2858
+ modifier character `mod` and a format specifier character `spec` as
2859
+ defined for the function `strftime`. If no modifier character is
2860
+ present, `mod` is zero. For each valid format sequence identified, calls
2861
+ `do_put(s, str, fill, t, spec, mod)`.
2862
+
2863
+ The second form calls `do_put(s, str, fill, t, format, modifier)`.
2864
+
2865
+ [*Note 2*: The `fill` argument can be used in the
2866
+ implementation-defined formats or by derivations. A space character is a
2867
+ reasonable default for this argument. — *end note*]
2868
+
2869
+ *Returns:* An iterator pointing immediately after the last character
2870
+ produced.
2871
+
2872
+ ###### Virtual functions <a id="locale.time.put.virtuals">[[locale.time.put.virtuals]]</a>
2873
+
2874
+ ``` cpp
2875
+ iter_type do_put(iter_type s, ios_base&, char_type fill, const tm* t,
2876
+ char format, char modifier) const;
2877
+ ```
2878
+
2879
+ *Effects:* Formats the contents of the parameter `t` into characters
2880
+ placed on the output sequence `s`. Formatting is controlled by the
2881
+ parameters `format` and `modifier`, interpreted identically as the
2882
+ format specifiers in the string argument to the standard library
2883
+ function `strftime()`, except that the sequence of characters produced
2884
+ for those specifiers that are described as depending on the C locale are
2885
+ instead *implementation-defined*.
2886
+
2887
+ [*Note 3*: Interpretation of the `modifier` argument is
2888
+ implementation-defined. — *end note*]
2889
+
2890
+ *Returns:* An iterator pointing immediately after the last character
2891
+ produced.
2892
+
2893
+ [*Note 4*: The `fill` argument can be used in the
2894
+ implementation-defined formats or by derivations. A space character is a
2895
+ reasonable default for this argument. — *end note*]
2896
+
2897
+ *Recommended practice:* Interpretation of the `modifier` should follow
2898
+ POSIX conventions. Implementations should refer to other standards such
2899
+ as POSIX for a specification of the character sequences produced for
2900
+ those specifiers described as depending on the C locale.
2901
+
2902
+ ##### Class template `time_put_byname` <a id="locale.time.put.byname">[[locale.time.put.byname]]</a>
2903
+
2904
+ ``` cpp
2905
+ namespace std {
2906
+ template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
2907
+ class time_put_byname : public time_put<charT, OutputIterator> {
2908
+ public:
2909
+ using char_type = charT;
2910
+ using iter_type = OutputIterator;
2911
+
2912
+ explicit time_put_byname(const char*, size_t refs = 0);
2913
+ explicit time_put_byname(const string&, size_t refs = 0);
2914
+
2915
+ protected:
2916
+ ~time_put_byname();
2917
+ };
2918
+ }
2919
+ ```
2920
+
2921
+ #### The monetary category <a id="category.monetary">[[category.monetary]]</a>
2922
+
2923
+ ##### General <a id="category.monetary.general">[[category.monetary.general]]</a>
2924
+
2925
+ These templates handle monetary formats. A template parameter indicates
2926
+ whether local or international monetary formats are to be used.
2927
+
2928
+ All specifications of member functions for `money_put` and `money_get`
2929
+ in the subclauses of  [[category.monetary]] only apply to the
2930
+ specializations required in Tables  [[tab:locale.category.facets]] and 
2931
+ [[tab:locale.spec]] [[locale.category]]. Their members use their
2932
+ `ios_base&`, `ios_base::iostate&`, and `fill` arguments as described in 
2933
+ [[locale.categories]], and the `moneypunct<>` and `ctype<>` facets, to
2934
+ determine formatting details.
2935
+
2936
+ ##### Class template `money_get` <a id="locale.money.get">[[locale.money.get]]</a>
2937
+
2938
+ ###### General <a id="locale.money.get.general">[[locale.money.get.general]]</a>
2939
+
2940
+ ``` cpp
2941
+ namespace std {
2942
+ template<class charT, class InputIterator = istreambuf_iterator<charT>>
2943
+ class money_get : public locale::facet {
2944
+ public:
2945
+ using char_type = charT;
2946
+ using iter_type = InputIterator;
2947
+ using string_type = basic_string<charT>;
2948
+
2949
+ explicit money_get(size_t refs = 0);
2950
+
2951
+ iter_type get(iter_type s, iter_type end, bool intl,
2952
+ ios_base& f, ios_base::iostate& err,
2953
+ long double& units) const;
2954
+ iter_type get(iter_type s, iter_type end, bool intl,
2955
+ ios_base& f, ios_base::iostate& err,
2956
+ string_type& digits) const;
2957
+
2958
+ static locale::id id;
2959
+
2960
+ protected:
2961
+ ~money_get();
2962
+ virtual iter_type do_get(iter_type, iter_type, bool, ios_base&,
2963
+ ios_base::iostate& err, long double& units) const;
2964
+ virtual iter_type do_get(iter_type, iter_type, bool, ios_base&,
2965
+ ios_base::iostate& err, string_type& digits) const;
2966
+ };
2967
+ }
2968
+ ```
2969
+
2970
+ ###### Members <a id="locale.money.get.members">[[locale.money.get.members]]</a>
2971
+
2972
+ ``` cpp
2973
+ iter_type get(iter_type s, iter_type end, bool intl, ios_base& f,
2974
+ ios_base::iostate& err, long double& quant) const;
2975
+ iter_type get(iter_type s, iter_type end, bool intl, ios_base& f,
2976
+ ios_base::iostate& err, string_type& quant) const;
2977
+ ```
2978
+
2979
+ *Returns:* `do_get(s, end, intl, f, err, quant)`.
2980
+
2981
+ ###### Virtual functions <a id="locale.money.get.virtuals">[[locale.money.get.virtuals]]</a>
2982
+
2983
+ ``` cpp
2984
+ iter_type do_get(iter_type s, iter_type end, bool intl, ios_base& str,
2985
+ ios_base::iostate& err, long double& units) const;
2986
+ iter_type do_get(iter_type s, iter_type end, bool intl, ios_base& str,
2987
+ ios_base::iostate& err, string_type& digits) const;
2988
+ ```
2989
+
2990
+ *Effects:* Reads characters from `s` to parse and construct a monetary
2991
+ value according to the format specified by a `moneypunct<charT, Intl>`
2992
+ facet reference `mp` and the character mapping specified by a
2993
+ `ctype<charT>` facet reference `ct` obtained from the locale returned by
2994
+ `str.getloc()`, and `str.flags()`. If a valid sequence is recognized,
2995
+ does not change `err`; otherwise, sets `err` to `(err | str.failbit)`,
2996
+ or `(err | str.failbit | str.eofbit)` if no more characters are
2997
+ available, and does not change `units` or `digits`. Uses the pattern
2998
+ returned by `mp.neg_format()` to parse all values. The result is
2999
+ returned as an integral value stored in `units` or as a sequence of
3000
+ digits possibly preceded by a minus sign (as produced by `ct.widen(c)`
3001
+ where `c` is `’-’` or in the range from `’0’` through `’9’` (inclusive))
3002
+ stored in `digits`.
3003
+
3004
+ [*Example 1*: The sequence `$1,056.23` in a common United States locale
3005
+ would yield, for `units`, `105623`, or, for `digits`,
3006
+ `"105623"`. — *end example*]
3007
+
3008
+ If `mp.grouping()` indicates that no thousands separators are permitted,
3009
+ any such characters are not read, and parsing is terminated at the point
3010
+ where they first appear. Otherwise, thousands separators are optional;
3011
+ if present, they are checked for correct placement only after all format
3012
+ components have been read.
3013
+
3014
+ Where `money_base::space` or `money_base::none` appears as the last
3015
+ element in the format pattern, no whitespace is consumed. Otherwise,
3016
+ where `money_base::space` appears in any of the initial elements of the
3017
+ format pattern, at least one whitespace character is required. Where
3018
+ `money_base::none` appears in any of the initial elements of the format
3019
+ pattern, whitespace is allowed but not required. If
3020
+ `(str.flags() & str.showbase)` is `false`, the currency symbol is
3021
+ optional and is consumed only if other characters are needed to complete
3022
+ the format; otherwise, the currency symbol is required.
3023
+
3024
+ If the first character (if any) in the string `pos` returned by
3025
+ `mp.positive_sign()` or the string `neg` returned by
3026
+ `mp.negative_sign()` is recognized in the position indicated by `sign`
3027
+ in the format pattern, it is consumed and any remaining characters in
3028
+ the string are required after all the other format components.
3029
+
3030
+ [*Example 2*: If `showbase` is off, then for a `neg` value of `"()"`
3031
+ and a currency symbol of `"L"`, in `"(100 L)"` the `"L"` is consumed;
3032
+ but if `neg` is `"-"`, the `"L"` in `"-100 L"` is not
3033
+ consumed. — *end example*]
3034
+
3035
+ If `pos` or `neg` is empty, the sign component is optional, and if no
3036
+ sign is detected, the result is given the sign that corresponds to the
3037
+ source of the empty string. Otherwise, the character in the indicated
3038
+ position must match the first character of `pos` or `neg`, and the
3039
+ result is given the corresponding sign. If the first character of `pos`
3040
+ is equal to the first character of `neg`, or if both strings are empty,
3041
+ the result is given a positive sign.
3042
+
3043
+ Digits in the numeric monetary component are extracted and placed in
3044
+ `digits`, or into a character buffer `buf1` for conversion to produce a
3045
+ value for `units`, in the order in which they appear, preceded by a
3046
+ minus sign if and only if the result is negative. The value `units` is
3047
+ produced as if by[^17]
3048
+
3049
+ ``` cpp
3050
+ for (int i = 0; i < n; ++i)
3051
+ buf2[i] = src[find(atoms, atoms + sizeof(src), buf1[i]) - atoms];
3052
+ buf2[n] = 0;
3053
+ sscanf(buf2, "%Lf", &units);
3054
+ ```
3055
+
3056
+ where `n` is the number of characters placed in `buf1`, `buf2` is a
3057
+ character buffer, and the values `src` and `atoms` are defined as if by
3058
+
3059
+ ``` cpp
3060
+ static const char src[] = "0123456789-";
3061
+ charT atoms[sizeof(src)];
3062
+ ct.widen(src, src + sizeof(src) - 1, atoms);
3063
+ ```
3064
+
3065
+ *Returns:* An iterator pointing immediately beyond the last character
3066
+ recognized as part of a valid monetary quantity.
3067
+
3068
+ ##### Class template `money_put` <a id="locale.money.put">[[locale.money.put]]</a>
3069
+
3070
+ ###### General <a id="locale.money.put.general">[[locale.money.put.general]]</a>
3071
+
3072
+ ``` cpp
3073
+ namespace std {
3074
+ template<class charT, class OutputIterator = ostreambuf_iterator<charT>>
3075
+ class money_put : public locale::facet {
3076
+ public:
3077
+ using char_type = charT;
3078
+ using iter_type = OutputIterator;
3079
+ using string_type = basic_string<charT>;
3080
+
3081
+ explicit money_put(size_t refs = 0);
3082
+
3083
+ iter_type put(iter_type s, bool intl, ios_base& f,
3084
+ char_type fill, long double units) const;
3085
+ iter_type put(iter_type s, bool intl, ios_base& f,
3086
+ char_type fill, const string_type& digits) const;
3087
+
3088
+ static locale::id id;
3089
+
3090
+ protected:
3091
+ ~money_put();
3092
+ virtual iter_type do_put(iter_type, bool, ios_base&, char_type fill,
3093
+ long double units) const;
3094
+ virtual iter_type do_put(iter_type, bool, ios_base&, char_type fill,
3095
+ const string_type& digits) const;
3096
+ };
3097
+ }
3098
+ ```
3099
+
3100
+ ###### Members <a id="locale.money.put.members">[[locale.money.put.members]]</a>
3101
+
3102
+ ``` cpp
3103
+ iter_type put(iter_type s, bool intl, ios_base& f, char_type fill, long double quant) const;
3104
+ iter_type put(iter_type s, bool intl, ios_base& f, char_type fill, const string_type& quant) const;
3105
+ ```
3106
+
3107
+ *Returns:* `do_put(s, intl, f, fill, quant)`.
3108
+
3109
+ ###### Virtual functions <a id="locale.money.put.virtuals">[[locale.money.put.virtuals]]</a>
3110
+
3111
+ ``` cpp
3112
+ iter_type do_put(iter_type s, bool intl, ios_base& str,
3113
+ char_type fill, long double units) const;
3114
+ iter_type do_put(iter_type s, bool intl, ios_base& str,
3115
+ char_type fill, const string_type& digits) const;
3116
+ ```
3117
+
3118
+ *Effects:* Writes characters to `s` according to the format specified by
3119
+ a `moneypunct<charT, Intl>` facet reference `mp` and the character
3120
+ mapping specified by a `ctype<charT>` facet reference `ct` obtained from
3121
+ the locale returned by `str.getloc()`, and `str.flags()`. The argument
3122
+ `units` is transformed into a sequence of wide characters as if by
3123
+
3124
+ ``` cpp
3125
+ ct.widen(buf1, buf1 + sprintf(buf1, "%.0Lf", units), buf2)
3126
+ ```
3127
+
3128
+ for character buffers `buf1` and `buf2`. If the first character in
3129
+ `digits` or `buf2` is equal to `ct.widen(’-’)`, then the pattern used
3130
+ for formatting is the result of `mp.neg_format()`; otherwise the pattern
3131
+ is the result of `mp.pos_format()`. Digit characters are written,
3132
+ interspersed with any thousands separators and decimal point specified
3133
+ by the format, in the order they appear (after the optional leading
3134
+ minus sign) in `digits` or `buf2`. In `digits`, only the optional
3135
+ leading minus sign and the immediately subsequent digit characters (as
3136
+ classified according to `ct`) are used; any trailing characters
3137
+ (including digits appearing after a non-digit character) are ignored.
3138
+ Calls `str.width(0)`.
3139
+
3140
+ *Returns:* An iterator pointing immediately after the last character
3141
+ produced.
3142
+
3143
+ *Remarks:* The currency symbol is generated if and only if
3144
+ `(str.flags() & str.showbase)` is nonzero. If the number of characters
3145
+ generated for the specified format is less than the value returned by
3146
+ `str.width()` on entry to the function, then copies of `fill` are
3147
+ inserted as necessary to pad to the specified width. For the value `af`
3148
+ equal to `(str.flags() & str.adjustfield)`, if `(af == str.internal)` is
3149
+ `true`, the fill characters are placed where `none` or `space` appears
3150
+ in the formatting pattern; otherwise if `(af == str.left)` is `true`,
3151
+ they are placed after the other characters; otherwise, they are placed
3152
+ before the other characters.
3153
+
3154
+ [*Note 1*: It is possible, with some combinations of format patterns
3155
+ and flag values, to produce output that cannot be parsed using
3156
+ `num_get<>::get`. — *end note*]
3157
+
3158
+ ##### Class template `moneypunct` <a id="locale.moneypunct">[[locale.moneypunct]]</a>
3159
+
3160
+ ###### General <a id="locale.moneypunct.general">[[locale.moneypunct.general]]</a>
3161
+
3162
+ ``` cpp
3163
+ namespace std {
3164
+ class money_base {
3165
+ public:
3166
+ enum part { none, space, symbol, sign, value };
3167
+ struct pattern { char field[4]; };
3168
+ };
3169
+
3170
+ template<class charT, bool International = false>
3171
+ class moneypunct : public locale::facet, public money_base {
3172
+ public:
3173
+ using char_type = charT;
3174
+ using string_type = basic_string<charT>;
3175
+
3176
+ explicit moneypunct(size_t refs = 0);
3177
+
3178
+ charT decimal_point() const;
3179
+ charT thousands_sep() const;
3180
+ string grouping() const;
3181
+ string_type curr_symbol() const;
3182
+ string_type positive_sign() const;
3183
+ string_type negative_sign() const;
3184
+ int frac_digits() const;
3185
+ pattern pos_format() const;
3186
+ pattern neg_format() const;
3187
+
3188
+ static locale::id id;
3189
+ static const bool intl = International;
3190
+
3191
+ protected:
3192
+ ~moneypunct();
3193
+ virtual charT do_decimal_point() const;
3194
+ virtual charT do_thousands_sep() const;
3195
+ virtual string do_grouping() const;
3196
+ virtual string_type do_curr_symbol() const;
3197
+ virtual string_type do_positive_sign() const;
3198
+ virtual string_type do_negative_sign() const;
3199
+ virtual int do_frac_digits() const;
3200
+ virtual pattern do_pos_format() const;
3201
+ virtual pattern do_neg_format() const;
3202
+ };
3203
+ }
3204
+ ```
3205
+
3206
+ The `moneypunct<>` facet defines monetary formatting parameters used by
3207
+ `money_get<>` and `money_put<>`. A monetary format is a sequence of four
3208
+ components, specified by a `pattern` value `p`, such that the `part`
3209
+ value `static_cast<part>(p.field[i])` determines the `i`ᵗʰ component of
3210
+ the format.[^18]
3211
+
3212
+ In the `field` member of a `pattern` object, each value `symbol`,
3213
+ `sign`, `value`, and either `space` or `none` appears exactly once. The
3214
+ value `none`, if present, is not first; the value `space`, if present,
3215
+ is neither first nor last.
3216
+
3217
+ Where `none` or `space` appears, whitespace is permitted in the format,
3218
+ except where `none` appears at the end, in which case no whitespace is
3219
+ permitted. The value `space` indicates that at least one space is
3220
+ required at that position. Where `symbol` appears, the sequence of
3221
+ characters returned by `curr_symbol()` is permitted, and can be
3222
+ required. Where `sign` appears, the first (if any) of the sequence of
3223
+ characters returned by `positive_sign()` or `negative_sign()`
3224
+ (respectively as the monetary value is non-negative or negative) is
3225
+ required. Any remaining characters of the sign sequence are required
3226
+ after all other format components. Where `value` appears, the absolute
3227
+ numeric monetary value is required.
3228
+
3229
+ The format of the numeric monetary value is a decimal number:
3230
+
3231
+ ``` bnf
3232
+ value:
3233
+ units fractionalₒₚₜ
3234
+ decimal-point digits
3235
+ ```
3236
+
3237
+ ``` bnf
3238
+ fractional:
3239
+ decimal-point digitsₒₚₜ
3240
+ ```
3241
+
3242
+ if `frac_digits()` returns a positive value, or
3243
+
3244
+ ``` bnf
3245
+ value:
3246
+ units
3247
+ ```
3248
+
3249
+ otherwise. The symbol indicates the character returned by
3250
+ `decimal_point()`. The other symbols are defined as follows:
3251
+
3252
+ ``` bnf
3253
+ units:
3254
+ digits
3255
+ digits thousands-sep units
3256
+ ```
3257
+
3258
+ ``` bnf
3259
+ digits:
3260
+ adigit digitsₒₚₜ
3261
+ ```
3262
+
3263
+ In the syntax specification, the symbol is any of the values
3264
+ `ct.widen(c)` for `c` in the range `'0'` through `'9'` (inclusive) and
3265
+ `ct` is a reference of type `const ctype<charT>&` obtained as described
3266
+ in the definitions of `money_get<>` and `money_put<>`. The symbol is the
3267
+ character returned by `thousands_sep()`. The space character used is the
3268
+ value `ct.widen(' ')`. Whitespace characters are those characters `c`
3269
+ for which `ci.is(space, c)` returns `true`. The number of digits
3270
+ required after the decimal point (if any) is exactly the value returned
3271
+ by `frac_digits()`.
3272
+
3273
+ The placement of thousands-separator characters (if any) is determined
3274
+ by the value returned by `grouping()`, defined identically as the member
3275
+ `numpunct<>::do_grouping()`.
3276
+
3277
+ ###### Members <a id="locale.moneypunct.members">[[locale.moneypunct.members]]</a>
3278
+
3279
+ ``` cpp
3280
+ charT decimal_point() const;
3281
+ charT thousands_sep() const;
3282
+ string grouping() const;
3283
+ string_type curr_symbol() const;
3284
+ string_type positive_sign() const;
3285
+ string_type negative_sign() const;
3286
+ int frac_digits() const;
3287
+ pattern pos_format() const;
3288
+ pattern neg_format() const;
3289
+ ```
3290
+
3291
+ Each of these functions `F` returns the result of calling the
3292
+ corresponding virtual member function `do_F()`.
3293
+
3294
+ ###### Virtual functions <a id="locale.moneypunct.virtuals">[[locale.moneypunct.virtuals]]</a>
3295
+
3296
+ ``` cpp
3297
+ charT do_decimal_point() const;
3298
+ ```
3299
+
3300
+ *Returns:* The radix separator to use in case `do_frac_digits()` is
3301
+ greater than zero.[^19]
3302
+
3303
+ ``` cpp
3304
+ charT do_thousands_sep() const;
3305
+ ```
3306
+
3307
+ *Returns:* The digit group separator to use in case `do_grouping()`
3308
+ specifies a digit grouping pattern.[^20]
3309
+
3310
+ ``` cpp
3311
+ string do_grouping() const;
3312
+ ```
3313
+
3314
+ *Returns:* A pattern defined identically as, but not necessarily equal
3315
+ to, the result of `numpunct<charT>::do_grouping()`.[^21]
3316
+
3317
+ ``` cpp
3318
+ string_type do_curr_symbol() const;
3319
+ ```
3320
+
3321
+ *Returns:* A string to use as the currency identifier symbol.
3322
+
3323
+ [*Note 2*: For specializations where the second template parameter is
3324
+ `true`, this is typically four characters long: a three-letter code as
3325
+ specified by ISO 4217 followed by a space. — *end note*]
3326
+
3327
+ ``` cpp
3328
+ string_type do_positive_sign() const;
3329
+ string_type do_negative_sign() const;
3330
+ ```
3331
+
3332
+ *Returns:* `do_positive_sign()` returns the string to use to indicate a
3333
+ positive monetary value;[^22]
3334
+
3335
+ `do_negative_sign()` returns the string to use to indicate a negative
3336
+ value.
3337
+
3338
+ ``` cpp
3339
+ int do_frac_digits() const;
3340
+ ```
3341
+
3342
+ *Returns:* The number of digits after the decimal radix separator, if
3343
+ any.[^23]
3344
+
3345
+ ``` cpp
3346
+ pattern do_pos_format() const;
3347
+ pattern do_neg_format() const;
3348
+ ```
3349
+
3350
+ *Returns:* The specializations required in
3351
+ [[locale.spec]][[locale.category]], namely
3352
+
3353
+ - `moneypunct<char>`,
3354
+ - `moneypunct<wchar_t>`,
3355
+ - `moneypunct<char, true>`, and
3356
+ - `moneypunct<wchar_t, true>`,
3357
+
3358
+ return an object of type `pattern` initialized to
3359
+ `{ symbol, sign, none, value }`.[^24]
3360
+
3361
+ ##### Class template `moneypunct_byname` <a id="locale.moneypunct.byname">[[locale.moneypunct.byname]]</a>
3362
+
3363
+ ``` cpp
3364
+ namespace std {
3365
+ template<class charT, bool Intl = false>
3366
+ class moneypunct_byname : public moneypunct<charT, Intl> {
3367
+ public:
3368
+ using pattern = money_base::pattern;
3369
+ using string_type = basic_string<charT>;
3370
+
3371
+ explicit moneypunct_byname(const char*, size_t refs = 0);
3372
+ explicit moneypunct_byname(const string&, size_t refs = 0);
3373
+
3374
+ protected:
3375
+ ~moneypunct_byname();
3376
+ };
3377
+ }
3378
+ ```
3379
+
3380
+ #### The message retrieval category <a id="category.messages">[[category.messages]]</a>
3381
+
3382
+ ##### General <a id="category.messages.general">[[category.messages.general]]</a>
3383
+
3384
+ Class `messages<charT>` implements retrieval of strings from message
3385
+ catalogs.
3386
+
3387
+ ##### Class template `messages` <a id="locale.messages">[[locale.messages]]</a>
3388
+
3389
+ ###### General <a id="locale.messages.general">[[locale.messages.general]]</a>
3390
+
3391
+ ``` cpp
3392
+ namespace std {
3393
+ class messages_base {
3394
+ public:
3395
+ using catalog = unspecified signed integer type;
3396
+ };
3397
+
3398
+ template<class charT>
3399
+ class messages : public locale::facet, public messages_base {
3400
+ public:
3401
+ using char_type = charT;
3402
+ using string_type = basic_string<charT>;
3403
+
3404
+ explicit messages(size_t refs = 0);
3405
+
3406
+ catalog open(const string& fn, const locale&) const;
3407
+ string_type get(catalog c, int set, int msgid,
3408
+ const string_type& dfault) const;
3409
+ void close(catalog c) const;
3410
+
3411
+ static locale::id id;
3412
+
3413
+ protected:
3414
+ ~messages();
3415
+ virtual catalog do_open(const string&, const locale&) const;
3416
+ virtual string_type do_get(catalog, int set, int msgid,
3417
+ const string_type& dfault) const;
3418
+ virtual void do_close(catalog) const;
3419
+ };
3420
+ }
3421
+ ```
3422
+
3423
+ Values of type `messages_base::catalog` usable as arguments to members
3424
+ `get` and `close` can be obtained only by calling member `open`.
3425
+
3426
+ ###### Members <a id="locale.messages.members">[[locale.messages.members]]</a>
3427
+
3428
+ ``` cpp
3429
+ catalog open(const string& name, const locale& loc) const;
3430
+ ```
3431
+
3432
+ *Returns:* `do_open(name, loc)`.
3433
+
3434
+ ``` cpp
3435
+ string_type get(catalog cat, int set, int msgid, const string_type& dfault) const;
3436
+ ```
3437
+
3438
+ *Returns:* `do_get(cat, set, msgid, dfault)`.
3439
+
3440
+ ``` cpp
3441
+ void close(catalog cat) const;
3442
+ ```
3443
+
3444
+ *Effects:* Calls `do_close(cat)`.
3445
+
3446
+ ###### Virtual functions <a id="locale.messages.virtuals">[[locale.messages.virtuals]]</a>
3447
+
3448
+ ``` cpp
3449
+ catalog do_open(const string& name, const locale& loc) const;
3450
+ ```
3451
+
3452
+ *Returns:* A value that may be passed to `get()` to retrieve a message
3453
+ from the message catalog identified by the string `name` according to an
3454
+ *implementation-defined* mapping. The result can be used until it is
3455
+ passed to `close()`.
3456
+
3457
+ Returns a value less than 0 if no such catalog can be opened.
3458
+
3459
+ *Remarks:* The locale argument `loc` is used for character set code
3460
+ conversion when retrieving messages, if needed.
3461
+
3462
+ ``` cpp
3463
+ string_type do_get(catalog cat, int set, int msgid, const string_type& dfault) const;
3464
+ ```
3465
+
3466
+ *Preconditions:* `cat` is a catalog obtained from `open()` and not yet
3467
+ closed.
3468
+
3469
+ *Returns:* A message identified by arguments `set`, `msgid`, and
3470
+ `dfault`, according to an *implementation-defined* mapping. If no such
3471
+ message can be found, returns `dfault`.
3472
+
3473
+ ``` cpp
3474
+ void do_close(catalog cat) const;
3475
+ ```
3476
+
3477
+ *Preconditions:* `cat` is a catalog obtained from `open()` and not yet
3478
+ closed.
3479
+
3480
+ *Effects:* Releases unspecified resources associated with `cat`.
3481
+
3482
+ *Remarks:* The limit on such resources, if any, is
3483
+ *implementation-defined*.
3484
+
3485
+ ##### Class template `messages_byname` <a id="locale.messages.byname">[[locale.messages.byname]]</a>
3486
+
3487
+ ``` cpp
3488
+ namespace std {
3489
+ template<class charT>
3490
+ class messages_byname : public messages<charT> {
3491
+ public:
3492
+ using catalog = messages_base::catalog;
3493
+ using string_type = basic_string<charT>;
3494
+
3495
+ explicit messages_byname(const char*, size_t refs = 0);
3496
+ explicit messages_byname(const string&, size_t refs = 0);
3497
+
3498
+ protected:
3499
+ ~messages_byname();
3500
+ };
3501
+ }
3502
+ ```
3503
+
3504
+ ### C library locales <a id="c.locales">[[c.locales]]</a>
3505
+
3506
+ #### Header `<clocale>` synopsis <a id="clocale.syn">[[clocale.syn]]</a>
3507
+
3508
+ ``` cpp
3509
+ namespace std {
3510
+ struct lconv;
3511
+
3512
+ char* setlocale(int category, const char* locale);
3513
+ lconv* localeconv();
3514
+ }
3515
+
3516
+ #define NULL see [support.types.nullptr]
3517
+ #define LC_ALL see below
3518
+ #define LC_COLLATE see below
3519
+ #define LC_CTYPE see below
3520
+ #define LC_MONETARY see below
3521
+ #define LC_NUMERIC see below
3522
+ #define LC_TIME see below
3523
+ ```
3524
+
3525
+ The contents and meaning of the header `<clocale>` are the same as the C
3526
+ standard library header `<locale.h>`.
3527
+
3528
+ #### Data races <a id="clocale.data.races">[[clocale.data.races]]</a>
3529
+
3530
+ Calls to the function `setlocale` may introduce a data race
3531
+ [[res.on.data.races]] with other calls to `setlocale` or with calls to
3532
+ the functions listed in [[setlocale.data.races]].
3533
+
3534
+ See also: ISO C 7.11
3535
+
3536
+ **Table: Potential `setlocale` data races** <a id="setlocale.data.races">[setlocale.data.races]</a>
3537
+
3538
+ | | | | | |
3539
+ | --------- | ---------- | ----------- | ------------ | ---------- |
3540
+ | `fprintf` | `isprint` | `iswdigit` | `localeconv` | `tolower` |
3541
+ | `fscanf` | `ispunct` | `iswgraph` | `mblen` | `toupper` |
3542
+ | `isalnum` | `isspace` | `iswlower` | `mbstowcs` | `towlower` |
3543
+ | `isalpha` | `isupper` | `iswprint` | `mbtowc` | `towupper` |
3544
+ | `isblank` | `iswalnum` | `iswpunct` | `setlocale` | `wcscoll` |
3545
+ | `iscntrl` | `iswalpha` | `iswspace` | `strcoll` | `wcstod` |
3546
+ | `isdigit` | `iswblank` | `iswupper` | `strerror` | `wcstombs` |
3547
+ | `isgraph` | `iswcntrl` | `iswxdigit` | `strtod` | `wcsxfrm` |
3548
+ | `islower` | `iswctype` | `isxdigit` | `strxfrm` | `wctomb` |
3549
+
3550
+
3551
+ ## Text encodings identification <a id="text.encoding">[[text.encoding]]</a>
3552
+
3553
+ ### Header `<text_encoding>` synopsis <a id="text.encoding.syn">[[text.encoding.syn]]</a>
3554
+
3555
+ ``` cpp
3556
+ namespace std {
3557
+ struct text_encoding;
3558
+
3559
+ // [text.encoding.hash], hash support
3560
+ template<class T> struct hash;
3561
+ template<> struct hash<text_encoding>;
3562
+ }
3563
+ ```
3564
+
3565
+ ### Class `text_encoding` <a id="text.encoding.class">[[text.encoding.class]]</a>
3566
+
3567
+ #### Overview <a id="text.encoding.overview">[[text.encoding.overview]]</a>
3568
+
3569
+ The class `text_encoding` describes an interface for accessing the IANA
3570
+ Character Sets registry.
3571
+
3572
+ ``` cpp
3573
+ namespace std {
3574
+ struct text_encoding {
3575
+ static constexpr size_t max_name_length = 63;
3576
+
3577
+ // [text.encoding.id], enumeration text_encoding::id
3578
+ enum class id : int_least32_t {
3579
+ see below
3580
+ };
3581
+ using enum id;
3582
+
3583
+ constexpr text_encoding() = default;
3584
+ constexpr explicit text_encoding(string_view enc) noexcept;
3585
+ constexpr text_encoding(id i) noexcept;
3586
+
3587
+ constexpr id mib() const noexcept;
3588
+ constexpr const char* name() const noexcept;
3589
+
3590
+ // [text.encoding.aliases], class text_encoding::aliases_view
3591
+ struct aliases_view;
3592
+ constexpr aliases_view aliases() const noexcept;
3593
+
3594
+ friend constexpr bool operator==(const text_encoding& a,
3595
+ const text_encoding& b) noexcept;
3596
+ friend constexpr bool operator==(const text_encoding& encoding, id i) noexcept;
3597
+
3598
+ static consteval text_encoding literal() noexcept;
3599
+ static text_encoding environment();
3600
+ template<id i> static bool environment_is();
3601
+
3602
+ private:
3603
+ id mib_ = id::unknown; // exposition only
3604
+ char name_[max_name_length + 1] = {0}; // exposition only
3605
+ static constexpr bool comp-name(string_view a, string_view b); // exposition only
3606
+ };
3607
+ }
3608
+ ```
3609
+
3610
+ Class `text_encoding` is a trivially copyable type
3611
+ [[term.trivially.copyable.type]].
3612
+
3613
+ #### General <a id="text.encoding.general">[[text.encoding.general]]</a>
3614
+
3615
+ A *registered character encoding* is a character encoding scheme in the
3616
+ IANA Character Sets registry.
3617
+
3618
+ [*Note 1*: The IANA Character Sets registry uses the term “character
3619
+ sets” to refer to character encodings. — *end note*]
3620
+
3621
+ The primary name of a registered character encoding is the name of that
3622
+ encoding specified in the IANA Character Sets registry.
3623
+
3624
+ The set of known registered character encodings contains every
3625
+ registered character encoding specified in the IANA Character Sets
3626
+ registry except for the following:
3627
+
3628
+ - NATS-DANO (33)
3629
+ - NATS-DANO-ADD (34)
3630
+
3631
+ Each known registered character encoding is identified by an enumerator
3632
+ in `text_encoding::id`, and has a set of zero or more *aliases*.
3633
+
3634
+ The set of aliases of a known registered character encoding is an
3635
+ *implementation-defined* superset of the aliases specified in the IANA
3636
+ Character Sets registry. The set of aliases for US-ASCII includes
3637
+ “ASCII”. No two aliases or primary names of distinct registered
3638
+ character encodings are equivalent when compared by
3639
+ `text_encoding::comp-name`.
3640
+
3641
+ How a `text_encoding` object is determined to be representative of a
3642
+ character encoding scheme implemented in the translation or execution
3643
+ environment is *implementation-defined*.
3644
+
3645
+ An object `e` of type `text_encoding` such that
3646
+ `e.mib() == text_encoding::id::unknown` is `false` and
3647
+ `e.mib() == text_encoding::id::other` is `false` maintains the following
3648
+ invariants:
3649
+
3650
+ - `*e.name() == '\0'` is `false`, and
3651
+ - `e.mib() == text_encoding(e.name()).mib()` is `true`.
3652
+
3653
+ *Recommended practice:*
3654
+
3655
+ - Implementations should not consider registered encodings to be
3656
+ interchangeable. \[*Example 1*: Shift_JIS and Windows-31J denote
3657
+ different encodings. — *end example*]
3658
+ - Implementations should not use the name of a registered encoding to
3659
+ describe another similar yet different non-registered encoding unless
3660
+ there is a precedent on that implementation.
3661
+ \[*Example 2*: Big5 — *end example*]
3662
+
3663
+ #### Members <a id="text.encoding.members">[[text.encoding.members]]</a>
3664
+
3665
+ ``` cpp
3666
+ constexpr explicit text_encoding(string_view enc) noexcept;
3667
+ ```
3668
+
3669
+ *Preconditions:*
3670
+
3671
+ - `enc` represents a string in the ordinary literal encoding consisting
3672
+ only of elements of the basic character set [[lex.charset]].
3673
+ - `enc.size() <= max_name_length` is `true`.
3674
+ - `enc.contains(’\0’)` is `false`.
3675
+
3676
+ *Ensures:*
3677
+
3678
+ - If there exists a primary name or alias `a` of a known registered
3679
+ character encoding such that *`comp-name`*`(a, enc)` is `true`,
3680
+ *mib\_* has the value of the enumerator of `id` associated with that
3681
+ registered character encoding. Otherwise, *`mib_`*` == id::other` is
3682
+ `true`.
3683
+ - `enc.compare(`*`name_`*`) == 0` is `true`.
3684
+
3685
+ ``` cpp
3686
+ constexpr text_encoding(id i) noexcept;
3687
+ ```
3688
+
3689
+ *Preconditions:* `i` has the value of one of the enumerators of `id`.
3690
+
3691
+ *Ensures:*
3692
+
3693
+ - *`mib_`*` == i` is `true`.
3694
+ - If `(`*`mib_`*` == id::unknown || `*`mib_`*` == id::other)` is `true`,
3695
+ `strlen(`*`name_`*`) == 0` is `true`. Otherwise,
3696
+ `ranges::contains(aliases(), string_view(`*`name_`*`))` is `true`.
3697
+
3698
+ ``` cpp
3699
+ constexpr id mib() const noexcept;
3700
+ ```
3701
+
3702
+ *Returns:* *mib\_*.
3703
+
3704
+ ``` cpp
3705
+ constexpr const char* name() const noexcept;
3706
+ ```
3707
+
3708
+ *Returns:* *name\_*.
3709
+
3710
+ *Remarks:* `name()` is an NTBS and accessing elements of *name\_*
3711
+ outside of the range `name()`+\[0, `strlen(name()) + 1`) is undefined
3712
+ behavior.
3713
+
3714
+ ``` cpp
3715
+ constexpr aliases_view aliases() const noexcept;
3716
+ ```
3717
+
3718
+ Let `r` denote an instance of `aliases_view`. If `*this` represents a
3719
+ known registered character encoding, then:
3720
+
3721
+ - `r.front()` is the primary name of the registered character encoding,
3722
+ - `r` contains the aliases of the registered character encoding, and
3723
+ - `r` does not contain duplicate values when compared with `strcmp`.
3724
+
3725
+ Otherwise, `r` is an empty range.
3726
+
3727
+ Each element in `r` is a non-null, non-empty NTBS encoded in the literal
3728
+ character encoding and comprising only characters from the basic
3729
+ character set.
3730
+
3731
+ *Returns:* `r`.
3732
+
3733
+ [*Note 1*: The order of aliases in `r` is unspecified. — *end note*]
3734
+
3735
+ ``` cpp
3736
+ static consteval text_encoding literal() noexcept;
3737
+ ```
3738
+
3739
+ *Mandates:* `CHAR_BIT == 8` is `true`.
3740
+
3741
+ *Returns:* A `text_encoding` object representing the ordinary character
3742
+ literal encoding [[lex.charset]].
3743
+
3744
+ ``` cpp
3745
+ static text_encoding environment();
3746
+ ```
3747
+
3748
+ *Mandates:* `CHAR_BIT == 8` is `true`.
3749
+
3750
+ *Returns:* A `text_encoding` object representing the
3751
+ *implementation-defined* character encoding scheme of the environment.
3752
+ On a POSIX implementation, this is the encoding scheme associated with
3753
+ the POSIX locale denoted by the empty string `""`.
3754
+
3755
+ [*Note 2*: This function is not affected by calls to
3756
+ `setlocale`. — *end note*]
3757
+
3758
+ *Recommended practice:* Implementations should return a value that is
3759
+ not affected by calls to the POSIX function `setenv` and other functions
3760
+ which can modify the environment [[support.runtime]].
3761
+
3762
+ ``` cpp
3763
+ template<id i>
3764
+ static bool environment_is();
3765
+ ```
3766
+
3767
+ *Mandates:* `CHAR_BIT == 8` is `true`.
3768
+
3769
+ *Returns:* `environment() == i`.
3770
+
3771
+ ``` cpp
3772
+ static constexpr bool comp-name(string_view a, string_view b);
3773
+ ```
3774
+
3775
+ *Returns:* `true` if the two strings `a` and `b` encoded in the ordinary
3776
+ literal encoding are equal, ignoring, from left-to-right,
3777
+
3778
+ - all elements that are not digits or letters [[character.seq.general]],
3779
+ - character case, and
3780
+ - any sequence of one or more `0` characters not immediately preceded by
3781
+ a numeric prefix, where a numeric prefix is a sequence consisting of a
3782
+ digit in the range \[`1`, `9`\] optionally followed by one or more
3783
+ elements which are not digits or letters,
3784
+
3785
+ and `false` otherwise.
3786
+
3787
+ [*Note 3*: This comparison is identical to the “Charset Alias Matching”
3788
+ algorithm described in the Unicode Technical Standard 22. — *end note*]
3789
+
3790
+ [*Example 1*:
3791
+
3792
+ ``` cpp
3793
+ static_assert(comp-name("UTF-8", "utf8") == true);
3794
+ static_assert(comp-name("u.t.f-008", "utf8") == true);
3795
+ static_assert(comp-name("ut8", "utf8") == false);
3796
+ static_assert(comp-name("utf-80", "utf8") == false);
3797
+ ```
3798
+
3799
+ — *end example*]
3800
+
3801
+ #### Comparison functions <a id="text.encoding.cmp">[[text.encoding.cmp]]</a>
3802
+
3803
+ ``` cpp
3804
+ friend constexpr bool operator==(const text_encoding& a, const text_encoding& b) noexcept;
3805
+ ```
3806
+
3807
+ *Returns:* If `a.`*`mib_`*` == id::other && b.`*`mib_`*` == id::other`
3808
+ is `true`, then *`comp-name`*`(a.`*`name_`*`,b.`*`name_`*`)`. Otherwise,
3809
+ `a.`*`mib_`*` == b.`*`mib_`*.
3810
+
3811
+ ``` cpp
3812
+ friend constexpr bool operator==(const text_encoding& encoding, id i) noexcept;
3813
+ ```
3814
+
3815
+ *Returns:* `encoding.`*`mib_`*` == i`.
3816
+
3817
+ *Remarks:* This operator induces an equivalence relation on its
3818
+ arguments if and only if `i != id::other` is `true`.
3819
+
3820
+ #### Class `text_encoding::aliases_view` <a id="text.encoding.aliases">[[text.encoding.aliases]]</a>
3821
+
3822
+ ``` cpp
3823
+ struct text_encoding::aliases_view : ranges::view_interface<text_encoding::aliases_view> {
3824
+ constexpr implementation-defined // type of text_encoding::aliases_view::begin() begin() const;
3825
+ constexpr implementation-defined // type of text_encoding::aliases_view::end() end() const;
3826
+ };
3827
+ ```
3828
+
3829
+ `text_encoding::aliases_view` models `copyable`, `ranges::view`,
3830
+ `ranges::random_access_range`, and `ranges::borrowed_range`.
3831
+
3832
+ [*Note 1*: `text_encoding::aliases_view` is not required to satisfy
3833
+ `ranges::``common_range`, nor `default_initializable`. — *end note*]
3834
+
3835
+ Both `ranges::range_value_t<text_encoding::aliases_view>` and
3836
+ `ranges::range_reference_t<text_encoding::aliases_view>` denote
3837
+ `const char*`.
3838
+
3839
+ `ranges::iterator_t<text_encoding::aliases_view>` is a constexpr
3840
+ iterator [[iterator.requirements.general]].
3841
+
3842
+ #### Enumeration `text_encoding::id` <a id="text.encoding.id">[[text.encoding.id]]</a>
3843
+
3844
+ ``` cpp
3845
+ namespace std {
3846
+ enum class text_encoding::id : int_least32_t {
3847
+ other = 1,
3848
+ unknown = 2,
3849
+ ASCII = 3,
3850
+ ISOLatin1 = 4,
3851
+ ISOLatin2 = 5,
3852
+ ISOLatin3 = 6,
3853
+ ISOLatin4 = 7,
3854
+ ISOLatinCyrillic = 8,
3855
+ ISOLatinArabic = 9,
3856
+ ISOLatinGreek = 10,
3857
+ ISOLatinHebrew = 11,
3858
+ ISOLatin5 = 12,
3859
+ ISOLatin6 = 13,
3860
+ ISOTextComm = 14,
3861
+ HalfWidthKatakana = 15,
3862
+ JISEncoding = 16,
3863
+ ShiftJIS = 17,
3864
+ EUCPkdFmtJapanese = 18,
3865
+ EUCFixWidJapanese = 19,
3866
+ ISO4UnitedKingdom = 20,
3867
+ ISO11SwedishForNames = 21,
3868
+ ISO15Italian = 22,
3869
+ ISO17Spanish = 23,
3870
+ ISO21German = 24,
3871
+ ISO60DanishNorwegian = 25,
3872
+ ISO69French = 26,
3873
+ ISO10646UTF1 = 27,
3874
+ ISO646basic1983 = 28,
3875
+ INVARIANT = 29,
3876
+ ISO2IntlRefVersion = 30,
3877
+ NATSSEFI = 31,
3878
+ NATSSEFIADD = 32,
3879
+ ISO10Swedish = 35,
3880
+ KSC56011987 = 36,
3881
+ ISO2022KR = 37,
3882
+ EUCKR = 38,
3883
+ ISO2022JP = 39,
3884
+ ISO2022JP2 = 40,
3885
+ ISO13JISC6220jp = 41,
3886
+ ISO14JISC6220ro = 42,
3887
+ ISO16Portuguese = 43,
3888
+ ISO18Greek7Old = 44,
3889
+ ISO19LatinGreek = 45,
3890
+ ISO25French = 46,
3891
+ ISO27LatinGreek1 = 47,
3892
+ ISO5427Cyrillic = 48,
3893
+ ISO42JISC62261978 = 49,
3894
+ ISO47BSViewdata = 50,
3895
+ ISO49INIS = 51,
3896
+ ISO50INIS8 = 52,
3897
+ ISO51INISCyrillic = 53,
3898
+ ISO54271981 = 54,
3899
+ ISO5428Greek = 55,
3900
+ ISO57GB1988 = 56,
3901
+ ISO58GB231280 = 57,
3902
+ ISO61Norwegian2 = 58,
3903
+ ISO70VideotexSupp1 = 59,
3904
+ ISO84Portuguese2 = 60,
3905
+ ISO85Spanish2 = 61,
3906
+ ISO86Hungarian = 62,
3907
+ ISO87JISX0208 = 63,
3908
+ ISO88Greek7 = 64,
3909
+ ISO89ASMO449 = 65,
3910
+ ISO90 = 66,
3911
+ ISO91JISC62291984a = 67,
3912
+ ISO92JISC62991984b = 68,
3913
+ ISO93JIS62291984badd = 69,
3914
+ ISO94JIS62291984hand = 70,
3915
+ ISO95JIS62291984handadd = 71,
3916
+ ISO96JISC62291984kana = 72,
3917
+ ISO2033 = 73,
3918
+ ISO99NAPLPS = 74,
3919
+ ISO102T617bit = 75,
3920
+ ISO103T618bit = 76,
3921
+ ISO111ECMACyrillic = 77,
3922
+ ISO121Canadian1 = 78,
3923
+ ISO122Canadian2 = 79,
3924
+ ISO123CSAZ24341985gr = 80,
3925
+ ISO88596E = 81,
3926
+ ISO88596I = 82,
3927
+ ISO128T101G2 = 83,
3928
+ ISO88598E = 84,
3929
+ ISO88598I = 85,
3930
+ ISO139CSN369103 = 86,
3931
+ ISO141JUSIB1002 = 87,
3932
+ ISO143IECP271 = 88,
3933
+ ISO146Serbian = 89,
3934
+ ISO147Macedonian = 90,
3935
+ ISO150 = 91,
3936
+ ISO151Cuba = 92,
3937
+ ISO6937Add = 93,
3938
+ ISO153GOST1976874 = 94,
3939
+ ISO8859Supp = 95,
3940
+ ISO10367Box = 96,
3941
+ ISO158Lap = 97,
3942
+ ISO159JISX02121990 = 98,
3943
+ ISO646Danish = 99,
3944
+ USDK = 100,
3945
+ DKUS = 101,
3946
+ KSC5636 = 102,
3947
+ Unicode11UTF7 = 103,
3948
+ ISO2022CN = 104,
3949
+ ISO2022CNEXT = 105,
3950
+ UTF8 = 106,
3951
+ ISO885913 = 109,
3952
+ ISO885914 = 110,
3953
+ ISO885915 = 111,
3954
+ ISO885916 = 112,
3955
+ GBK = 113,
3956
+ GB18030 = 114,
3957
+ OSDEBCDICDF0415 = 115,
3958
+ OSDEBCDICDF03IRV = 116,
3959
+ OSDEBCDICDF041 = 117,
3960
+ ISO115481 = 118,
3961
+ KZ1048 = 119,
3962
+ UCS2 = 1000,
3963
+ UCS4 = 1001,
3964
+ UnicodeASCII = 1002,
3965
+ UnicodeLatin1 = 1003,
3966
+ UnicodeJapanese = 1004,
3967
+ UnicodeIBM1261 = 1005,
3968
+ UnicodeIBM1268 = 1006,
3969
+ UnicodeIBM1276 = 1007,
3970
+ UnicodeIBM1264 = 1008,
3971
+ UnicodeIBM1265 = 1009,
3972
+ Unicode11 = 1010,
3973
+ SCSU = 1011,
3974
+ UTF7 = 1012,
3975
+ UTF16BE = 1013,
3976
+ UTF16LE = 1014,
3977
+ UTF16 = 1015,
3978
+ CESU8 = 1016,
3979
+ UTF32 = 1017,
3980
+ UTF32BE = 1018,
3981
+ UTF32LE = 1019,
3982
+ BOCU1 = 1020,
3983
+ UTF7IMAP = 1021,
3984
+ Windows30Latin1 = 2000,
3985
+ Windows31Latin1 = 2001,
3986
+ Windows31Latin2 = 2002,
3987
+ Windows31Latin5 = 2003,
3988
+ HPRoman8 = 2004,
3989
+ AdobeStandardEncoding = 2005,
3990
+ VenturaUS = 2006,
3991
+ VenturaInternational = 2007,
3992
+ DECMCS = 2008,
3993
+ PC850Multilingual = 2009,
3994
+ PCp852 = 2010,
3995
+ PC8CodePage437 = 2011,
3996
+ PC8DanishNorwegian = 2012,
3997
+ PC862LatinHebrew = 2013,
3998
+ PC8Turkish = 2014,
3999
+ IBMSymbols = 2015,
4000
+ IBMThai = 2016,
4001
+ HPLegal = 2017,
4002
+ HPPiFont = 2018,
4003
+ HPMath8 = 2019,
4004
+ HPPSMath = 2020,
4005
+ HPDesktop = 2021,
4006
+ VenturaMath = 2022,
4007
+ MicrosoftPublishing = 2023,
4008
+ Windows31J = 2024,
4009
+ GB2312 = 2025,
4010
+ Big5 = 2026,
4011
+ Macintosh = 2027,
4012
+ IBM037 = 2028,
4013
+ IBM038 = 2029,
4014
+ IBM273 = 2030,
4015
+ IBM274 = 2031,
4016
+ IBM275 = 2032,
4017
+ IBM277 = 2033,
4018
+ IBM278 = 2034,
4019
+ IBM280 = 2035,
4020
+ IBM281 = 2036,
4021
+ IBM284 = 2037,
4022
+ IBM285 = 2038,
4023
+ IBM290 = 2039,
4024
+ IBM297 = 2040,
4025
+ IBM420 = 2041,
4026
+ IBM423 = 2042,
4027
+ IBM424 = 2043,
4028
+ IBM500 = 2044,
4029
+ IBM851 = 2045,
4030
+ IBM855 = 2046,
4031
+ IBM857 = 2047,
4032
+ IBM860 = 2048,
4033
+ IBM861 = 2049,
4034
+ IBM863 = 2050,
4035
+ IBM864 = 2051,
4036
+ IBM865 = 2052,
4037
+ IBM868 = 2053,
4038
+ IBM869 = 2054,
4039
+ IBM870 = 2055,
4040
+ IBM871 = 2056,
4041
+ IBM880 = 2057,
4042
+ IBM891 = 2058,
4043
+ IBM903 = 2059,
4044
+ IBM904 = 2060,
4045
+ IBM905 = 2061,
4046
+ IBM918 = 2062,
4047
+ IBM1026 = 2063,
4048
+ IBMEBCDICATDE = 2064,
4049
+ EBCDICATDEA = 2065,
4050
+ EBCDICCAFR = 2066,
4051
+ EBCDICDKNO = 2067,
4052
+ EBCDICDKNOA = 2068,
4053
+ EBCDICFISE = 2069,
4054
+ EBCDICFISEA = 2070,
4055
+ EBCDICFR = 2071,
4056
+ EBCDICIT = 2072,
4057
+ EBCDICPT = 2073,
4058
+ EBCDICES = 2074,
4059
+ EBCDICESA = 2075,
4060
+ EBCDICESS = 2076,
4061
+ EBCDICUK = 2077,
4062
+ EBCDICUS = 2078,
4063
+ Unknown8BiT = 2079,
4064
+ Mnemonic = 2080,
4065
+ Mnem = 2081,
4066
+ VISCII = 2082,
4067
+ VIQR = 2083,
4068
+ KOI8R = 2084,
4069
+ HZGB2312 = 2085,
4070
+ IBM866 = 2086,
4071
+ PC775Baltic = 2087,
4072
+ KOI8U = 2088,
4073
+ IBM00858 = 2089,
4074
+ IBM00924 = 2090,
4075
+ IBM01140 = 2091,
4076
+ IBM01141 = 2092,
4077
+ IBM01142 = 2093,
4078
+ IBM01143 = 2094,
4079
+ IBM01144 = 2095,
4080
+ IBM01145 = 2096,
4081
+ IBM01146 = 2097,
4082
+ IBM01147 = 2098,
4083
+ IBM01148 = 2099,
4084
+ IBM01149 = 2100,
4085
+ Big5HKSCS = 2101,
4086
+ IBM1047 = 2102,
4087
+ PTCP154 = 2103,
4088
+ Amiga1251 = 2104,
4089
+ KOI7switched = 2105,
4090
+ BRF = 2106,
4091
+ TSCII = 2107,
4092
+ CP51932 = 2108,
4093
+ windows874 = 2109,
4094
+ windows1250 = 2250,
4095
+ windows1251 = 2251,
4096
+ windows1252 = 2252,
4097
+ windows1253 = 2253,
4098
+ windows1254 = 2254,
4099
+ windows1255 = 2255,
4100
+ windows1256 = 2256,
4101
+ windows1257 = 2257,
4102
+ windows1258 = 2258,
4103
+ TIS620 = 2259,
4104
+ CP50220 = 2260
4105
+ };
4106
+ }
4107
+ ```
4108
+
4109
+ [*Note 1*:
4110
+
4111
+ The `text_encoding::id` enumeration contains an enumerator for each
4112
+ known registered character encoding. For each encoding, the
4113
+ corresponding enumerator is derived from the alias beginning with
4114
+ “`cs`”, as follows
4115
+
4116
+ - `csUnicode` is mapped to `text_encoding::id::UCS2`,
4117
+ - `csIBBM904` is mapped to `text_encoding::id::IBM904`, and
4118
+ - the “`cs`” prefix is removed from other names.
4119
+
4120
+ — *end note*]
4121
+
4122
+ #### Hash support <a id="text.encoding.hash">[[text.encoding.hash]]</a>
4123
+
4124
+ ``` cpp
4125
+ template<> struct hash<text_encoding>;
4126
+ ```
4127
+
4128
+ The specialization is enabled [[unord.hash]].
4129
+
4130
+ ## Formatting <a id="format">[[format]]</a>
4131
+
4132
+ ### Header `<format>` synopsis <a id="format.syn">[[format.syn]]</a>
4133
+
4134
+ ``` cpp
4135
+ namespace std {
4136
+ // [format.context], class template basic_format_context
4137
+ template<class Out, class charT> class basic_format_context;
4138
+ using format_context = basic_format_context<unspecified, char>;
4139
+ using wformat_context = basic_format_context<unspecified, wchar_t>;
4140
+
4141
+ // [format.args], class template basic_format_args
4142
+ template<class Context> class basic_format_args;
4143
+ using format_args = basic_format_args<format_context>;
4144
+ using wformat_args = basic_format_args<wformat_context>;
4145
+
4146
+ // [format.fmt.string], class template basic_format_string
4147
+ template<class charT, class... Args>
4148
+ struct basic_format_string;
4149
+
4150
+ template<class charT> struct runtime-format-string { // exposition only
4151
+ private:
4152
+ basic_string_view<charT> str; // exposition only
4153
+ public:
4154
+ runtime-format-string(basic_string_view<charT> s) noexcept : str(s) {}
4155
+ runtime-format-string(const runtime-format-string&) = delete;
4156
+ runtime-format-string& operator=(const runtime-format-string&) = delete;
4157
+ };
4158
+ runtime-format-string<char> runtime_format(string_view fmt) noexcept { return fmt; }
4159
+ runtime-format-string<wchar_t> runtime_format(wstring_view fmt) noexcept { return fmt; }
4160
+
4161
+ template<class... Args>
4162
+ using format_string = basic_format_string<char, type_identity_t<Args>...>;
4163
+ template<class... Args>
4164
+ using wformat_string = basic_format_string<wchar_t, type_identity_t<Args>...>;
4165
+
4166
+ // [format.functions], formatting functions
4167
+ template<class... Args>
4168
+ string format(format_string<Args...> fmt, Args&&... args);
4169
+ template<class... Args>
4170
+ wstring format(wformat_string<Args...> fmt, Args&&... args);
4171
+ template<class... Args>
4172
+ string format(const locale& loc, format_string<Args...> fmt, Args&&... args);
4173
+ template<class... Args>
4174
+ wstring format(const locale& loc, wformat_string<Args...> fmt, Args&&... args);
4175
+
4176
+ string vformat(string_view fmt, format_args args);
4177
+ wstring vformat(wstring_view fmt, wformat_args args);
4178
+ string vformat(const locale& loc, string_view fmt, format_args args);
4179
+ wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
4180
+
4181
+ template<class Out, class... Args>
4182
+ Out format_to(Out out, format_string<Args...> fmt, Args&&... args);
4183
+ template<class Out, class... Args>
4184
+ Out format_to(Out out, wformat_string<Args...> fmt, Args&&... args);
4185
+ template<class Out, class... Args>
4186
+ Out format_to(Out out, const locale& loc, format_string<Args...> fmt, Args&&... args);
4187
+ template<class Out, class... Args>
4188
+ Out format_to(Out out, const locale& loc, wformat_string<Args...> fmt, Args&&... args);
4189
+
4190
+ template<class Out>
4191
+ Out vformat_to(Out out, string_view fmt, format_args args);
4192
+ template<class Out>
4193
+ Out vformat_to(Out out, wstring_view fmt, wformat_args args);
4194
+ template<class Out>
4195
+ Out vformat_to(Out out, const locale& loc, string_view fmt, format_args args);
4196
+ template<class Out>
4197
+ Out vformat_to(Out out, const locale& loc, wstring_view fmt, wformat_args args);
4198
+
4199
+ template<class Out> struct format_to_n_result {
4200
+ Out out;
4201
+ iter_difference_t<Out> size;
4202
+ };
4203
+ template<class Out, class... Args>
4204
+ format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
4205
+ format_string<Args...> fmt, Args&&... args);
4206
+ template<class Out, class... Args>
4207
+ format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
4208
+ wformat_string<Args...> fmt, Args&&... args);
4209
+ template<class Out, class... Args>
4210
+ format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
4211
+ const locale& loc, format_string<Args...> fmt,
4212
+ Args&&... args);
4213
+ template<class Out, class... Args>
4214
+ format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
4215
+ const locale& loc, wformat_string<Args...> fmt,
4216
+ Args&&... args);
4217
+
4218
+ template<class... Args>
4219
+ size_t formatted_size(format_string<Args...> fmt, Args&&... args);
4220
+ template<class... Args>
4221
+ size_t formatted_size(wformat_string<Args...> fmt, Args&&... args);
4222
+ template<class... Args>
4223
+ size_t formatted_size(const locale& loc, format_string<Args...> fmt, Args&&... args);
4224
+ template<class... Args>
4225
+ size_t formatted_size(const locale& loc, wformat_string<Args...> fmt, Args&&... args);
4226
+
4227
+ // [format.formatter], formatter
4228
+ template<class T, class charT = char> struct formatter;
4229
+
4230
+ // [format.formatter.locking], formatter locking
4231
+ template<class T>
4232
+ constexpr bool enable_nonlocking_formatter_optimization = false;
4233
+
4234
+ // [format.formattable], concept formattable
4235
+ template<class T, class charT>
4236
+ concept formattable = see below;
4237
+
4238
+ template<class R, class charT>
4239
+ concept const-formattable-range = // exposition only
4240
+ ranges::input_range<const R> &&
4241
+ formattable<ranges::range_reference_t<const R>, charT>;
4242
+
4243
+ template<class R, class charT>
4244
+ using fmt-maybe-const = // exposition only
4245
+ conditional_t<const-formattable-range<R, charT>, const R, R>;
4246
+
4247
+ // [format.parse.ctx], class template basic_format_parse_context
4248
+ template<class charT> class basic_format_parse_context;
4249
+ using format_parse_context = basic_format_parse_context<char>;
4250
+ using wformat_parse_context = basic_format_parse_context<wchar_t>;
4251
+
4252
+ // [format.range], formatting of ranges
4253
+ // [format.range.fmtkind], variable template format_kind
4254
+ enum class range_format {
4255
+ disabled,
4256
+ map,
4257
+ set,
4258
+ sequence,
4259
+ string,
4260
+ debug_string
4261
+ };
4262
+
4263
+ template<class R>
4264
+ constexpr unspecified format_kind = unspecified;
4265
+
4266
+ template<ranges::input_range R>
4267
+ requires same_as<R, remove_cvref_t<R>>
4268
+ constexpr range_format format_kind<R> = see below;
4269
+
4270
+ // [format.range.formatter], class template range_formatter
4271
+ template<class T, class charT = char>
4272
+ requires same_as<remove_cvref_t<T>, T> && formattable<T, charT>
4273
+ class range_formatter;
4274
+
4275
+ // [format.range.fmtdef], class template range-default-formatter
4276
+ template<range_format K, ranges::input_range R, class charT>
4277
+ struct range-default-formatter; // exposition only
4278
+
4279
+ // [format.range.fmtmap], [format.range.fmtset], [format.range.fmtstr], specializations for maps, sets, and strings
4280
+ template<ranges::input_range R, class charT>
4281
+ requires (format_kind<R> != range_format::disabled) &&
4282
+ formattable<ranges::range_reference_t<R>, charT>
4283
+ struct formatter<R, charT> : range-default-formatter<format_kind<R>, R, charT> { };
4284
+
4285
+ template<ranges::input_range R>
4286
+ requires (format_kind<R> != range_format::disabled)
4287
+ constexpr bool enable_nonlocking_formatter_optimization<R> = false;
4288
+
4289
+ // [format.arguments], arguments
4290
+ // [format.arg], class template basic_format_arg
4291
+ template<class Context> class basic_format_arg;
4292
+
4293
+ // [format.arg.store], class template format-arg-store
4294
+ template<class Context, class... Args> class format-arg-store; // exposition only
4295
+
4296
+ template<class Context = format_context, class... Args>
4297
+ format-arg-store<Context, Args...>
4298
+ make_format_args(Args&... fmt_args);
4299
+ template<class... Args>
4300
+ format-arg-store<wformat_context, Args...>
4301
+ make_wformat_args(Args&... args);
4302
+
4303
+ // [format.error], class format_error
4304
+ class format_error;
4305
+ }
4306
+ ```
4307
+
4308
+ The class template `format_to_n_result` has the template parameters,
4309
+ data members, and special members specified above. It has no base
4310
+ classes or members other than those specified.
4311
+
4312
+ ### Format string <a id="format.string">[[format.string]]</a>
4313
+
4314
+ #### General <a id="format.string.general">[[format.string.general]]</a>
4315
+
4316
+ A *format string* for arguments `args` is a (possibly empty) sequence of
4317
+ *replacement fields*, *escape sequences*, and characters other than `{`
4318
+ and `}`. Let `charT` be the character type of the format string. Each
4319
+ character that is not part of a replacement field or an escape sequence
4320
+ is copied unchanged to the output. An escape sequence is one of `{{` or
4321
+ `}}`. It is replaced with `{` or `}`, respectively, in the output. The
4322
+ syntax of replacement fields is as follows:
4323
+
4324
+ ``` bnf
4325
+ replacement-field
4326
+ '{' arg-idₒₚₜ format-specifierₒₚₜ '}'
4327
+ ```
4328
+
4329
+ ``` bnf
4330
+ arg-id
4331
+ '0'
4332
+ positive-integer
4333
+ ```
4334
+
4335
+ ``` bnf
4336
+ positive-integer
4337
+ nonzero-digit
4338
+ positive-integer digit
4339
+ ```
4340
+
4341
+ ``` bnf
4342
+ nonnegative-integer
4343
+ digit
4344
+ nonnegative-integer digit
4345
+ ```
4346
+
4347
+ ``` bnf
4348
+ nonzero-digit one of
4349
+ '1 2 3 4 5 6 7 8 9'
4350
+ ```
4351
+
4352
+ ``` bnf
4353
+ digit one of
4354
+ '0 1 2 3 4 5 6 7 8 9'
4355
+ ```
4356
+
4357
+ ``` bnf
4358
+ format-specifier
4359
+ ':' format-spec
4360
+ ```
4361
+
4362
+ ``` bnf
4363
+ format-spec
4364
+ as specified by the formatter specialization for the argument type; cannot start with '}'
4365
+ ```
4366
+
4367
+ The *arg-id* field specifies the index of the argument in `args` whose
4368
+ value is to be formatted and inserted into the output instead of the
4369
+ replacement field. If there is no argument with the index *arg-id* in
4370
+ `args`, the string is not a format string for `args`. The optional
4371
+ *format-specifier* field explicitly specifies a format for the
4372
+ replacement value.
4373
+
4374
+ [*Example 1*:
4375
+
4376
+ ``` cpp
4377
+ string s = format("{0}-{{", 8); // value of s is "8-{"
4378
+ ```
4379
+
4380
+ — *end example*]
4381
+
4382
+ If all *arg-id*s in a format string are omitted (including those in the
4383
+ *format-spec*, as interpreted by the corresponding `formatter`
4384
+ specialization), argument indices 0, 1, 2, … will automatically be used
4385
+ in that order. If some *arg-id*s are omitted and some are present, the
4386
+ string is not a format string.
4387
+
4388
+ [*Note 1*: A format string cannot contain a mixture of automatic and
4389
+ manual indexing. — *end note*]
4390
+
4391
+ [*Example 2*:
4392
+
4393
+ ``` cpp
4394
+ string s0 = format("{} to {}", "a", "b"); // OK, automatic indexing
4395
+ string s1 = format("{1} to {0}", "a", "b"); // OK, manual indexing
4396
+ string s2 = format("{0} to {}", "a", "b"); // not a format string (mixing automatic and manual indexing),
4397
+ // ill-formed
4398
+ string s3 = format("{} to {1}", "a", "b"); // not a format string (mixing automatic and manual indexing),
4399
+ // ill-formed
4400
+ ```
4401
+
4402
+ — *end example*]
4403
+
4404
+ The *format-spec* field contains *format specifications* that define how
4405
+ the value should be presented. Each type can define its own
4406
+ interpretation of the *format-spec* field. If *format-spec* does not
4407
+ conform to the format specifications for the argument type referred to
4408
+ by *arg-id*, the string is not a format string for `args`.
4409
+
4410
+ [*Example 3*:
4411
+
4412
+ - For arithmetic, pointer, and string types the *format-spec* is
4413
+ interpreted as a *std-format-spec* as described in 
4414
+ [[format.string.std]].
4415
+ - For chrono types the *format-spec* is interpreted as a
4416
+ *chrono-format-spec* as described in  [[time.format]].
4417
+ - For user-defined `formatter` specializations, the behavior of the
4418
+ `parse` member function determines how the *format-spec* is
4419
+ interpreted.
4420
+
4421
+ — *end example*]
4422
+
4423
+ #### Standard format specifiers <a id="format.string.std">[[format.string.std]]</a>
4424
+
4425
+ Each `formatter` specialization described in [[format.formatter.spec]]
4426
+ for fundamental and string types interprets *format-spec* as a
4427
+ *std-format-spec*.
4428
+
4429
+ [*Note 1*: The format specification can be used to specify such details
4430
+ as minimum field width, alignment, padding, and decimal precision. Some
4431
+ of the formatting options are only supported for arithmetic
4432
+ types. — *end note*]
4433
+
4434
+ The syntax of format specifications is as follows:
4435
+
4436
+ ``` bnf
4437
+ std-format-spec
4438
+ fill-and-alignₒₚₜ signₒₚₜ '#'ₒₚₜ '0'ₒₚₜ widthₒₚₜ precisionₒₚₜ 'L'ₒₚₜ typeₒₚₜ
4439
+ ```
4440
+
4441
+ ``` bnf
4442
+ fill-and-align
4443
+ fillₒₚₜ align
4444
+ ```
4445
+
4446
+ ``` bnf
4447
+ fill
4448
+ any character other than \{ or \}
4449
+ ```
4450
+
4451
+ ``` bnf
4452
+ align one of
4453
+ '< > ^'
4454
+ ```
4455
+
4456
+ ``` bnf
4457
+ sign one of
4458
+ '+ -' space
4459
+ ```
4460
+
4461
+ ``` bnf
4462
+ width
4463
+ positive-integer
4464
+ '{' arg-idₒₚₜ '}'
4465
+ ```
4466
+
4467
+ ``` bnf
4468
+ precision
4469
+ '.' nonnegative-integer
4470
+ '.' '{' arg-idₒₚₜ '}'
4471
+ ```
4472
+
4473
+ ``` bnf
4474
+ type one of
4475
+ 'a A b B c d e E f F g G o p P s x X ?'
4476
+ ```
4477
+
4478
+ Field widths are specified in *field width units*; the number of column
4479
+ positions required to display a sequence of characters in a terminal.
4480
+ The *minimum field width* is the number of field width units a
4481
+ replacement field minimally requires of the formatted sequence of
4482
+ characters produced for a format argument. The *estimated field width*
4483
+ is the number of field width units that are required for the formatted
4484
+ sequence of characters produced for a format argument independent of the
4485
+ effects of the *width* option. The *padding width* is the greater of `0`
4486
+ and the difference of the minimum field width and the estimated field
4487
+ width.
4488
+
4489
+ [*Note 2*: The POSIX `wcswidth` function is an example of a function
4490
+ that, given a string, returns the number of column positions required by
4491
+ a terminal to display the string. — *end note*]
4492
+
4493
+ The *fill character* is the character denoted by the *fill* option or,
4494
+ if the *fill* option is absent, the space character. For a format
4495
+ specification in UTF-8, UTF-16, or UTF-32, the fill character
4496
+ corresponds to a single Unicode scalar value.
4497
+
4498
+ [*Note 3*: The presence of a *fill* option is signaled by the character
4499
+ following it, which must be one of the alignment options. If the second
4500
+ character of *std-format-spec* is not a valid alignment option, then it
4501
+ is assumed that the *fill* and *align* options are both
4502
+ absent. — *end note*]
4503
+
4504
+ The *align* option applies to all argument types. The meaning of the
4505
+ various alignment options is as specified in [[format.align]].
4506
+
4507
+ [*Example 1*:
4508
+
4509
+ ``` cpp
4510
+ char c = 120;
4511
+ string s0 = format("{:6}", 42); // value of s0 is "\ \ \ \ 42"
4512
+ string s1 = format("{:6}", 'x'); // value of s1 is "x\ \ \ \ \ "
4513
+ string s2 = format("{:*<6}", 'x'); // value of s2 is "x*****"
4514
+ string s3 = format("{:*>6}", 'x'); // value of s3 is "*****x"
4515
+ string s4 = format("{:*^6}", 'x'); // value of s4 is "**x***"
4516
+ string s5 = format("{:6d}", c); // value of s5 is "\ \ \ 120"
4517
+ string s6 = format("{:6}", true); // value of s6 is "true\ \ "
4518
+ string s7 = format("{:*<6.3}", "123456"); // value of s7 is "123***"
4519
+ string s8 = format("{:02}", 1234); // value of s8 is "1234"
4520
+ string s9 = format("{:*<}", "12"); // value of s9 is "12"
4521
+ string sA = format("{:*<6}", "12345678"); // value of sA is "12345678"
4522
+ string sB = format("{:\importexample[-2pt]{example_05}\kern0.75pt^6}", "x"); // value of sB is "\importexample[-2pt]{example_05\importexample[-2pt]{example_05}x\importexample[-2pt]{example_05}\importexample[-2pt]{example_05}\importexample[-2pt]{example_05}"}
4523
+ string sC = format("{:*^6}", "\importexample[-2pt]{example_05}\kern0.75pt\importexample[-2pt]{example_05}\kern0.75pt\importexample[-2pt]{example_05}\kern0.75pt"); // value of sC is "\importexample[-2pt]{example_05\importexample[-2pt]{example_05}\importexample[-2pt]{example_05}"}
4524
+ ```
4525
+
4526
+ — *end example*]
4527
+
4528
+ [*Note 4*: The *fill*, *align*, and `0` options have no effect when the
4529
+ minimum field width is not greater than the estimated field width
4530
+ because padding width is `0` in that case. Since fill characters are
4531
+ assumed to have a field width of `1`, use of a character with a
4532
+ different field width can produce misaligned output. The
4533
+ (U+1f921 (clown face)) character has a field width of `2`. The examples
4534
+ above that include that character illustrate the effect of the field
4535
+ width when that character is used as a fill character as opposed to when
4536
+ it is used as a formatting argument. — *end note*]
4537
+
4538
+ **Table: Meaning of align options** <a id="format.align">[format.align]</a>
4539
+
4540
+ | Option | Meaning |
4541
+ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
4542
+ | `<` | Forces the formatted argument to be aligned to the start of the field by inserting $n$ fill characters after the formatted argument where $n$ is the padding width. This is the default for non-arithmetic non-pointer types, `charT`, and `bool`, unless an integer presentation type is specified. |
4543
+ | % `>` | Forces the formatted argument to be aligned to the end of the field by inserting $n$ fill characters before the formatted argument where $n$ is the padding width. This is the default for arithmetic types other than `charT` and `bool`, pointer types, or when an integer presentation type is specified. |
4544
+ | % `^` | Forces the formatted argument to be centered within the field by inserting $\bigl\lfloor \frac{n}{2} \bigr\rfloor$ fill characters before and $\bigl\lceil \frac{n}{2} \bigr\rceil$ fill characters after the formatted argument, where $n$ is the padding width. |
4545
+
4546
+
4547
+ The *sign* option is only valid for arithmetic types other than `charT`
4548
+ and `bool` or when an integer presentation type is specified. The
4549
+ meaning of the various options is as specified in [[format.sign]].
4550
+
4551
+ **Table: Meaning of sign options** <a id="format.sign">[format.sign]</a>
4552
+
4553
+ | Option | Meaning |
4554
+ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
4555
+ | `+` | Indicates that a sign should be used for both non-negative and negative numbers. The `+` sign is inserted before the output of `to_chars` for non-negative numbers other than negative zero. *For negative numbers and negative zero the output of `to_chars` will already contain the sign so no additional transformation is performed.* |
4556
+ | % `-` | Indicates that a sign should be used for negative numbers and negative zero only (this is the default behavior). |
4557
+ | % space | Indicates that a leading space should be used for non-negative numbers other than negative zero, and a minus sign for negative numbers and negative zero. |
4558
+
4559
+
4560
+ The *sign* option applies to floating-point infinity and NaN.
4561
+
4562
+ [*Example 2*:
4563
+
4564
+ ``` cpp
4565
+ double inf = numeric_limits<double>::infinity();
4566
+ double nan = numeric_limits<double>::quiet_NaN();
4567
+ string s0 = format("{0:},{0:+},{0:-},{0: }", 1); // value of s0 is "1,+1,1, 1"
4568
+ string s1 = format("{0:},{0:+},{0:-},{0: }", -1); // value of s1 is "-1,-1,-1,-1"
4569
+ string s2 = format("{0:},{0:+},{0:-},{0: }", inf); // value of s2 is "inf,+inf,inf, inf"
4570
+ string s3 = format("{0:},{0:+},{0:-},{0: }", nan); // value of s3 is "nan,+nan,nan, nan"
4571
+ ```
4572
+
4573
+ — *end example*]
4574
+
4575
+ The `#` option causes the *alternate form* to be used for the
4576
+ conversion. This option is valid for arithmetic types other than `charT`
4577
+ and `bool` or when an integer presentation type is specified, and not
4578
+ otherwise. For integral types, the alternate form inserts the base
4579
+ prefix (if any) specified in [[format.type.int]] into the output after
4580
+ the sign character (possibly space) if there is one, or before the
4581
+ output of `to_chars` otherwise. For floating-point types, the alternate
4582
+ form causes the result of the conversion of finite values to always
4583
+ contain a decimal-point character, even if no digits follow it.
4584
+ Normally, a decimal-point character appears in the result of these
4585
+ conversions only if a digit follows it. In addition, for `g` and `G`
4586
+ conversions, trailing zeros are not removed from the result.
4587
+
4588
+ The `0` option is valid for arithmetic types other than `charT` and
4589
+ `bool`, pointer types, or when an integer presentation type is
4590
+ specified. For formatting arguments that have a value other than an
4591
+ infinity or a NaN, this option pads the formatted argument by inserting
4592
+ the `0` character n times following the sign or base prefix indicators
4593
+ (if any) where n is `0` if the *align* option is present and is the
4594
+ padding width otherwise.
4595
+
4596
+ [*Example 3*:
4597
+
4598
+ ``` cpp
4599
+ char c = 120;
4600
+ string s1 = format("{:+06d}", c); // value of s1 is "+00120"
4601
+ string s2 = format("{:#06x}", 0xa); // value of s2 is "0x000a"
4602
+ string s3 = format("{:<06}", -42); // value of s3 is "-42\ \ \ " (0 has no effect)
4603
+ string s4 = format("{:06}", inf); // value of s4 is "\ \ \ inf" (0 has no effect)
4604
+ ```
4605
+
4606
+ — *end example*]
4607
+
4608
+ The *width* option specifies the minimum field width. If the *width*
4609
+ option is absent, the minimum field width is `0`.
4610
+
4611
+ If `{ \opt{arg-id} }` is used in a *width* or *precision* option, the
4612
+ value of the corresponding formatting argument is used as the value of
4613
+ the option. The option is valid only if the corresponding formatting
4614
+ argument is of standard signed or unsigned integer type. If its value is
4615
+ negative, an exception of type `format_error` is thrown.
4616
+
4617
+ If *positive-integer* is used in a *width* option, the value of the
4618
+ *positive-integer* is interpreted as a decimal integer and used as the
4619
+ value of the option.
4620
+
4621
+ For the purposes of width computation, a string is assumed to be in a
4622
+ locale-independent, *implementation-defined* encoding. Implementations
4623
+ should use either UTF-8, UTF-16, or UTF-32, on platforms capable of
4624
+ displaying Unicode text in a terminal.
4625
+
4626
+ [*Note 5*:
4627
+
4628
+ This is the case for Windows®-based[^25]
4629
+
4630
+ and many POSIX-based operating systems.
4631
+
4632
+ — *end note*]
4633
+
4634
+ For a sequence of characters in UTF-8, UTF-16, or UTF-32, an
4635
+ implementation should use as its field width the sum of the field widths
4636
+ of the first code point of each extended grapheme cluster. Extended
4637
+ grapheme clusters are defined by UAX \#29 of the Unicode Standard. The
4638
+ following code points have a field width of 2:
4639
+
4640
+ - any code point with the `East_Asian_Width="W"` or
4641
+ `East_Asian_Width="F"` property as described by UAX \#44 of the
4642
+ Unicode Standard
4643
+ - `U+4dc0` – `U+4dff` (Yijing Hexagram Symbols)
4644
+ - `U+1f300` – `U+1f5ff` (Miscellaneous Symbols and Pictographs)
4645
+ - `U+1f900` – `U+1f9ff` (Supplemental Symbols and Pictographs)
4646
+
4647
+ The field width of all other code points is 1.
4648
+
4649
+ For a sequence of characters in neither UTF-8, UTF-16, nor UTF-32, the
4650
+ field width is unspecified.
4651
+
4652
+ The *precision* option is valid for floating-point and string types. For
4653
+ floating-point types, the value of this option specifies the precision
4654
+ to be used for the floating-point presentation type. For string types,
4655
+ this option specifies the longest prefix of the formatted argument to be
4656
+ included in the replacement field such that the field width of the
4657
+ prefix is no greater than the value of this option.
4658
+
4659
+ If *nonnegative-integer* is used in a *precision* option, the value of
4660
+ the decimal integer is used as the value of the option.
4661
+
4662
+ When the `L` option is used, the form used for the conversion is called
4663
+ the *locale-specific form*. The `L` option is only valid for arithmetic
4664
+ types, and its effect depends upon the type.
4665
+
4666
+ - For integral types, the locale-specific form causes the context’s
4667
+ locale to be used to insert the appropriate digit group separator
4668
+ characters.
4669
+ - For floating-point types, the locale-specific form causes the
4670
+ context’s locale to be used to insert the appropriate digit group and
4671
+ radix separator characters.
4672
+ - For the textual representation of `bool`, the locale-specific form
4673
+ causes the context’s locale to be used to insert the appropriate
4674
+ string as if obtained with `numpunct::truename` or
4675
+ `numpunct::falsename`.
4676
+
4677
+ The *type* determines how the data should be presented.
4678
+
4679
+ The available string presentation types are specified in
4680
+ [[format.type.string]].
4681
+
4682
+ **Table: Meaning of type options for strings** <a id="format.type.string">[format.type.string]</a>
4683
+
4684
+ | Type | Meaning |
4685
+ | --------- | ------------------------------------------------------------------ |
4686
+ | none, `s` | Copies the string to the output. |
4687
+ | % `?` | Copies the escaped string [[format.string.escaped]] to the output. |
4688
+
4689
+
4690
+ The meaning of some non-string presentation types is defined in terms of
4691
+ a call to `to_chars`. In such cases, let \[`first`, `last`) be a range
4692
+ large enough to hold the `to_chars` output and `value` be the formatting
4693
+ argument value. Formatting is done as if by calling `to_chars` as
4694
+ specified and copying the output through the output iterator of the
4695
+ format context.
4696
+
4697
+ [*Note 6*: Additional padding and adjustments are performed prior to
4698
+ copying the output through the output iterator as specified by the
4699
+ format specifiers. — *end note*]
4700
+
4701
+ The available integer presentation types for integral types other than
4702
+ `bool` and `charT` are specified in [[format.type.int]].
4703
+
4704
+ [*Example 4*:
4705
+
4706
+ ``` cpp
4707
+ string s0 = format("{}", 42); // value of s0 is "42"
4708
+ string s1 = format("{0:b} {0:d} {0:o} {0:x}", 42); // value of s1 is "101010 42 52 2a"
4709
+ string s2 = format("{0:#x} {0:#X}", 42); // value of s2 is "0x2a 0X2A"
4710
+ string s3 = format("{:L}", 1234); // value of s3 can be "1,234"
4711
+ // (depending on the locale)
4712
+ ```
4713
+
4714
+ — *end example*]
4715
+
4716
+ **Table: Meaning of type options for integer types** <a id="format.type.int">[format.type.int]</a>
4717
+
4718
+ | Type | Meaning |
4719
+ | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
4720
+ | `b` | `to_chars(first, last, value, 2)`; \indextext{base prefix}% the base prefix is `0b`. |
4721
+ | % `B` | The same as `b`, except that \indextext{base prefix}% the base prefix is `0B`. |
4722
+ | % `c` | Copies the character `static_cast<charT>(value)` to the output. Throws `format_error` if `value` is not in the range of representable values for `charT`. |
4723
+ | % `d` | `to_chars(first, last, value)`. |
4724
+ | % `o` | `to_chars(first, last, value, 8)`; \indextext{base prefix}% the base prefix is `0` if `value` is nonzero and is empty otherwise. |
4725
+ | % `x` | `to_chars(first, last, value, 16)`; \indextext{base prefix}% the base prefix is `0x`. |
4726
+ | % `X` | The same as `x`, except that it uses uppercase letters for digits above 9 and \indextext{base prefix}% the base prefix is `0X`. |
4727
+ | % none | The same as `d`. *If the formatting argument type is `charT` or `bool`, the default is instead `c` or `s`, respectively.* |
4728
+
4729
+
4730
+ The available `charT` presentation types are specified in
4731
+ [[format.type.char]].
4732
+
4733
+ **Table: Meaning of type options for `charT`** <a id="format.type.char">[format.type.char]</a>
4734
+
4735
+ | Type | Meaning |
4736
+ | ------------------------------ | ---------------------------------------------------------------------------------------------------------- |
4737
+ | none, `c` | Copies the character to the output. |
4738
+ | % `b`, `B`, `d`, `o`, `x`, `X` | As specified in [[format.type.int]] with `value` converted to the unsigned version of the underlying type. |
4739
+ | % `?` | Copies the escaped character [[format.string.escaped]] to the output. |
4740
+
4741
+
4742
+ The available `bool` presentation types are specified in
4743
+ [[format.type.bool]].
4744
+
4745
+ **Table: Meaning of type options for `bool`** <a id="format.type.bool">[format.type.bool]</a>
4746
+
4747
+ | Type | Meaning |
4748
+ | ------------------------------ | -------------------------------------------------------------------------------------- |
4749
+ | none, `s` | Copies textual representation, either `true` or `false`, to the output. |
4750
+ | % `b`, `B`, `d`, `o`, `x`, `X` | As specified in [[format.type.int]] for the value `static_cast<unsigned char>(value)`. |
4751
+
4752
+
4753
+ The available floating-point presentation types and their meanings for
4754
+ values other than infinity and NaN are specified in
4755
+ [[format.type.float]]. For lower-case presentation types, infinity and
4756
+ NaN are formatted as `inf` and `nan`, respectively. For upper-case
4757
+ presentation types, infinity and NaN are formatted as `INF` and `NAN`,
4758
+ respectively.
4759
+
4760
+ [*Note 7*: In either case, a sign is included if indicated by the
4761
+ *sign* option. — *end note*]
4762
+
4763
+ **Table: Meaning of type options for floating-point types** <a id="format.type.float">[format.type.float]</a>
4764
+
4765
+ | Type | Meaning |
4766
+ | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
4767
+ | `a` | If precision is specified, equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::hex, precision) \end{codeblock} where `precision` is the specified formatting precision; equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::hex) \end{codeblock} otherwise. |
4768
+ | % `A` | The same as `a`, except that it uses uppercase letters for digits above 9 and `P` to indicate the exponent. |
4769
+ | % `e` | Equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::scientific, precision) \end{codeblock} where `precision` is the specified formatting precision, or `6` if precision is not specified. |
4770
+ | % `E` | The same as `e`, except that it uses `E` to indicate exponent. |
4771
+ | % `f`, `F` | Equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::fixed, precision) \end{codeblock} where `precision` is the specified formatting precision, or `6` if precision is not specified. |
4772
+ | % `g` | Equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::general, precision) \end{codeblock} where `precision` is the specified formatting precision, or `6` if precision is not specified. |
4773
+ | % `G` | The same as `g`, except that it uses `E` to indicate exponent. |
4774
+ | % none | If precision is specified, equivalent to \begin{codeblock} to_chars(first, last, value, chars_format::general, precision) \end{codeblock} where `precision` is the specified formatting precision; equivalent to \begin{codeblock} to_chars(first, last, value) \end{codeblock} otherwise. |
4775
+
4776
+
4777
+ The available pointer presentation types and their mapping to `to_chars`
4778
+ are specified in [[format.type.ptr]].
4779
+
4780
+ [*Note 8*: Pointer presentation types also apply to
4781
+ `nullptr_t`. — *end note*]
4782
+
4783
+ **Table: Meaning of type options for pointer types** <a id="format.type.ptr">[format.type.ptr]</a>
4784
+
4785
+ | Type | Meaning |
4786
+ | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
4787
+ | none, `p` | If `uintptr_t` is defined, \begin{codeblock} to_chars(first, last, reinterpret_cast<uintptr_t>(value), 16) \end{codeblock} with the prefix `0x` inserted immediately before the output of `to_chars`; otherwise, implementation-defined. |
4788
+ | `P` | The same as `p`, except that it uses uppercase letters for digits above `9` and the base prefix is `0X`. |
4789
+
4790
+
4791
+ ### Error reporting <a id="format.err.report">[[format.err.report]]</a>
4792
+
4793
+ Formatting functions throw `format_error` if an argument `fmt` is passed
4794
+ that is not a format string for `args`. They propagate exceptions thrown
4795
+ by operations of `formatter` specializations and iterators. Failure to
4796
+ allocate storage is reported by throwing an exception as described in 
4797
+ [[res.on.exception.handling]].
4798
+
4799
+ ### Class template `basic_format_string` <a id="format.fmt.string">[[format.fmt.string]]</a>
4800
+
4801
+ ``` cpp
4802
+ namespace std {
4803
+ template<class charT, class... Args>
4804
+ struct basic_format_string {
4805
+ private:
4806
+ basic_string_view<charT> str; // exposition only
4807
+
4808
+ public:
4809
+ template<class T> consteval basic_format_string(const T& s);
4810
+ basic_format_string(runtime-format-string<charT> s) noexcept : str(s.str) {}
4811
+
4812
+ constexpr basic_string_view<charT> get() const noexcept { return str; }
4813
+ };
4814
+ }
4815
+ ```
4816
+
4817
+ ``` cpp
4818
+ template<class T> consteval basic_format_string(const T& s);
4819
+ ```
4820
+
4821
+ *Constraints:* `const T&` models
4822
+ `convertible_to<basic_string_view<charT>>`.
4823
+
4824
+ *Effects:* Direct-non-list-initializes *str* with `s`.
4825
+
4826
+ *Remarks:* A call to this function is not a core constant
4827
+ expression [[expr.const]] unless there exist `args` of types `Args` such
4828
+ that *str* is a format string for `args`.
4829
+
4830
+ ### Formatting functions <a id="format.functions">[[format.functions]]</a>
4831
+
4832
+ In the description of the functions, operator `+` is used for some of
4833
+ the iterator categories for which it does not have to be defined. In
4834
+ these cases the semantics of `a + n` are the same as in
4835
+ [[algorithms.requirements]].
4836
+
4837
+ ``` cpp
4838
+ template<class... Args>
4839
+ string format(format_string<Args...> fmt, Args&&... args);
4840
+ ```
4841
+
4842
+ *Effects:* Equivalent to:
4843
+
4844
+ ``` cpp
4845
+ return vformat(fmt.str, make_format_args(args...));
4846
+ ```
4847
+
4848
+ ``` cpp
4849
+ template<class... Args>
4850
+ wstring format(wformat_string<Args...> fmt, Args&&... args);
4851
+ ```
4852
+
4853
+ *Effects:* Equivalent to:
4854
+
4855
+ ``` cpp
4856
+ return vformat(fmt.str, make_wformat_args(args...));
4857
+ ```
4858
+
4859
+ ``` cpp
4860
+ template<class... Args>
4861
+ string format(const locale& loc, format_string<Args...> fmt, Args&&... args);
4862
+ ```
4863
+
4864
+ *Effects:* Equivalent to:
4865
+
4866
+ ``` cpp
4867
+ return vformat(loc, fmt.str, make_format_args(args...));
4868
+ ```
4869
+
4870
+ ``` cpp
4871
+ template<class... Args>
4872
+ wstring format(const locale& loc, wformat_string<Args...> fmt, Args&&... args);
4873
+ ```
4874
+
4875
+ *Effects:* Equivalent to:
4876
+
4877
+ ``` cpp
4878
+ return vformat(loc, fmt.str, make_wformat_args(args...));
4879
+ ```
4880
+
4881
+ ``` cpp
4882
+ string vformat(string_view fmt, format_args args);
4883
+ wstring vformat(wstring_view fmt, wformat_args args);
4884
+ string vformat(const locale& loc, string_view fmt, format_args args);
4885
+ wstring vformat(const locale& loc, wstring_view fmt, wformat_args args);
4886
+ ```
4887
+
4888
+ *Returns:* A string object holding the character representation of
4889
+ formatting arguments provided by `args` formatted according to
4890
+ specifications given in `fmt`. If present, `loc` is used for
4891
+ locale-specific formatting.
4892
+
4893
+ *Throws:* As specified in  [[format.err.report]].
4894
+
4895
+ ``` cpp
4896
+ template<class Out, class... Args>
4897
+ Out format_to(Out out, format_string<Args...> fmt, Args&&... args);
4898
+ ```
4899
+
4900
+ *Effects:* Equivalent to:
4901
+
4902
+ ``` cpp
4903
+ return vformat_to(std::move(out), fmt.str, make_format_args(args...));
4904
+ ```
4905
+
4906
+ ``` cpp
4907
+ template<class Out, class... Args>
4908
+ Out format_to(Out out, wformat_string<Args...> fmt, Args&&... args);
4909
+ ```
4910
+
4911
+ *Effects:* Equivalent to:
4912
+
4913
+ ``` cpp
4914
+ return vformat_to(std::move(out), fmt.str, make_wformat_args(args...));
4915
+ ```
4916
+
4917
+ ``` cpp
4918
+ template<class Out, class... Args>
4919
+ Out format_to(Out out, const locale& loc, format_string<Args...> fmt, Args&&... args);
4920
+ ```
4921
+
4922
+ *Effects:* Equivalent to:
4923
+
4924
+ ``` cpp
4925
+ return vformat_to(std::move(out), loc, fmt.str, make_format_args(args...));
4926
+ ```
4927
+
4928
+ ``` cpp
4929
+ template<class Out, class... Args>
4930
+ Out format_to(Out out, const locale& loc, wformat_string<Args...> fmt, Args&&... args);
4931
+ ```
4932
+
4933
+ *Effects:* Equivalent to:
4934
+
4935
+ ``` cpp
4936
+ return vformat_to(std::move(out), loc, fmt.str, make_wformat_args(args...));
4937
+ ```
4938
+
4939
+ ``` cpp
4940
+ template<class Out>
4941
+ Out vformat_to(Out out, string_view fmt, format_args args);
4942
+ template<class Out>
4943
+ Out vformat_to(Out out, wstring_view fmt, wformat_args args);
4944
+ template<class Out>
4945
+ Out vformat_to(Out out, const locale& loc, string_view fmt, format_args args);
4946
+ template<class Out>
4947
+ Out vformat_to(Out out, const locale& loc, wstring_view fmt, wformat_args args);
4948
+ ```
4949
+
4950
+ Let `charT` be `decltype(fmt)::value_type`.
4951
+
4952
+ *Constraints:* `Out` satisfies `output_iterator<const charT&>`.
4953
+
4954
+ *Preconditions:* `Out` models `output_iterator<const charT&>`.
4955
+
4956
+ *Effects:* Places the character representation of formatting the
4957
+ arguments provided by `args`, formatted according to the specifications
4958
+ given in `fmt`, into the range \[`out`, `out + N`), where `N` is the
4959
+ number of characters in that character representation. If present, `loc`
4960
+ is used for locale-specific formatting.
4961
+
4962
+ *Returns:* `out + N`.
4963
+
4964
+ *Throws:* As specified in  [[format.err.report]].
4965
+
4966
+ ``` cpp
4967
+ template<class Out, class... Args>
4968
+ format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
4969
+ format_string<Args...> fmt, Args&&... args);
4970
+ template<class Out, class... Args>
4971
+ format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
4972
+ wformat_string<Args...> fmt, Args&&... args);
4973
+ template<class Out, class... Args>
4974
+ format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
4975
+ const locale& loc, format_string<Args...> fmt,
4976
+ Args&&... args);
4977
+ template<class Out, class... Args>
4978
+ format_to_n_result<Out> format_to_n(Out out, iter_difference_t<Out> n,
4979
+ const locale& loc, wformat_string<Args...> fmt,
4980
+ Args&&... args);
4981
+ ```
4982
+
4983
+ Let
4984
+
4985
+ - `charT` be `decltype(fmt.`*`str`*`)::value_type`,
4986
+ - `N` be `formatted_size(fmt, args...)` for the functions without a
4987
+ `loc` parameter and `formatted_size(loc, fmt, args...)` for the
4988
+ functions with a `loc` parameter, and
4989
+ - `M` be `clamp(n, 0, N)`.
4990
+
4991
+ *Constraints:* `Out` satisfies `output_iterator<const charT&>`.
4992
+
4993
+ *Preconditions:* `Out` models `output_iterator<const charT&>`, and
4994
+ `formatter<``remove_cvref_t<Tᵢ``>, charT>` meets the
4995
+ requirements [[formatter.requirements]] for each `Tᵢ` in `Args`.
4996
+
4997
+ *Effects:* Places the first `M` characters of the character
4998
+ representation of formatting the arguments provided by `args`, formatted
4999
+ according to the specifications given in `fmt`, into the range \[`out`,
5000
+ `out + M`). If present, `loc` is used for locale-specific formatting.
5001
+
5002
+ *Returns:* `{out + M, N}`.
5003
+
5004
+ *Throws:* As specified in  [[format.err.report]].
5005
+
5006
+ ``` cpp
5007
+ template<class... Args>
5008
+ size_t formatted_size(format_string<Args...> fmt, Args&&... args);
5009
+ template<class... Args>
5010
+ size_t formatted_size(wformat_string<Args...> fmt, Args&&... args);
5011
+ template<class... Args>
5012
+ size_t formatted_size(const locale& loc, format_string<Args...> fmt, Args&&... args);
5013
+ template<class... Args>
5014
+ size_t formatted_size(const locale& loc, wformat_string<Args...> fmt, Args&&... args);
5015
+ ```
5016
+
5017
+ Let `charT` be `decltype(fmt.`*`str`*`)::value_type`.
5018
+
5019
+ *Preconditions:* `formatter<``remove_cvref_t<Tᵢ``>, charT>` meets the
5020
+ requirements [[formatter.requirements]] for each `Tᵢ` in `Args`.
5021
+
5022
+ *Returns:* The number of characters in the character representation of
5023
+ formatting arguments `args` formatted according to specifications given
5024
+ in `fmt`. If present, `loc` is used for locale-specific formatting.
5025
+
5026
+ *Throws:* As specified in  [[format.err.report]].
5027
+
5028
+ ### Formatter <a id="format.formatter">[[format.formatter]]</a>
5029
+
5030
+ #### Formatter requirements <a id="formatter.requirements">[[formatter.requirements]]</a>
5031
+
5032
+ A type `F` meets the requirements if it meets the
5033
+
5034
+ - *Cpp17DefaultConstructible* ([[cpp17.defaultconstructible]]),
5035
+ - *Cpp17CopyConstructible* ([[cpp17.copyconstructible]]),
5036
+ - *Cpp17CopyAssignable* ([[cpp17.copyassignable]]),
5037
+ - *Cpp17Swappable* [[swappable.requirements]], and
5038
+ - *Cpp17Destructible* ([[cpp17.destructible]])
5039
+
5040
+ requirements, and the expressions shown in [[formatter.basic]] are valid
5041
+ and have the indicated semantics.
5042
+
5043
+ A type `F` meets the requirements if it meets the requirements and the
5044
+ expressions shown in [[formatter]] are valid and have the indicated
5045
+ semantics.
5046
+
5047
+ Given character type `charT`, output iterator type `Out`, and formatting
5048
+ argument type `T`, in [[formatter.basic]] and [[formatter]]:
5049
+
5050
+ - `f` is a value of type (possibly const) `F`,
5051
+ - `g` is an lvalue of type `F`,
5052
+ - `u` is an lvalue of type `T`,
5053
+ - `t` is a value of a type convertible to (possibly const) `T`,
5054
+ - `PC` is `basic_format_parse_context<charT>`,
5055
+ - `FC` is `basic_format_context<Out, charT>`,
5056
+ - `pc` is an lvalue of type `PC`, and
5057
+ - `fc` is an lvalue of type `FC`.
5058
+
5059
+ `pc.begin()` points to the beginning of the *format-spec*
5060
+ [[format.string]] of the replacement field being formatted in the format
5061
+ string. If *format-spec* is not present or empty then either
5062
+ `pc.begin() == pc.end()` or `*pc.begin() == '}'`.
5063
+
5064
+ [*Note 1*: This allows formatters to emit meaningful error
5065
+ messages. — *end note*]
5066
+
5067
+ **Table: \newoldconcept{Formatter} requirements** <a id="formatter">[formatter]</a>
5068
+
5069
+ | Expression | Return type | Requirement |
5070
+ | ----------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
5071
+ | `f.format(t, fc)` | `FC::iterator` | Formats `t` according to the specifiers stored in `*this`, writes the output to `fc.out()`, and returns an iterator past the end of the output range. The output shall only depend on `t`, `fc.locale()`, `fc.arg(n)` for any value `n` of type `size_t`, and the range {[}`pc.begin()`, `pc.end()`{)} from the last call to `f.parse(pc)`. |
5072
+ | `f.format(u, fc)` | `FC::iterator` | As above, but does not modify `u`. |
5073
+
5074
+
5075
+ #### Formatter locking <a id="format.formatter.locking">[[format.formatter.locking]]</a>
5076
+
5077
+ ``` cpp
5078
+ template<class T>
5079
+ constexpr bool enable_nonlocking_formatter_optimization = false;
5080
+ ```
5081
+
5082
+ *Remarks:* Pursuant to [[namespace.std]], users may specialize
5083
+ `enable_nonlocking_formatter_optimization` for cv-unqualified
5084
+ program-defined types. Such specializations shall be usable in constant
5085
+ expressions [[expr.const]] and have type `const bool`.
5086
+
5087
+ #### Concept <a id="format.formattable">[[format.formattable]]</a>
5088
+
5089
+ Let `fmt-iter-for<charT>` be an unspecified type that models
5090
+ `output_iterator<const charT&>` [[iterator.concept.output]].
5091
+
5092
+ ``` cpp
5093
+ template<class T, class Context,
5094
+ class Formatter = typename Context::template formatter_type<remove_const_t<T>>>
5095
+ concept formattable-with = // exposition only
5096
+ semiregular<Formatter> &&
5097
+ requires(Formatter& f, const Formatter& cf, T&& t, Context fc,
5098
+ basic_format_parse_context<typename Context::char_type> pc)
5099
+ {
5100
+ { f.parse(pc) } -> same_as<typename decltype(pc)::iterator>;
5101
+ { cf.format(t, fc) } -> same_as<typename Context::iterator>;
5102
+ };
5103
+
5104
+ template<class T, class charT>
5105
+ concept formattable =
5106
+ formattable-with<remove_reference_t<T>, basic_format_context<fmt-iter-for<charT>, charT>>;
5107
+ ```
5108
+
5109
+ A type `T` and a character type `charT` model `formattable` if
5110
+ `formatter<remove_cvref_t<T>, charT>` meets the requirements
5111
+ [[formatter.requirements]] and, if `remove_reference_t<T>` is
5112
+ const-qualified, the requirements.
5113
+
5114
+ #### Formatter specializations <a id="format.formatter.spec">[[format.formatter.spec]]</a>
5115
+
5116
+ The functions defined in [[format.functions]] use specializations of the
5117
+ class template `formatter` to format individual arguments.
5118
+
5119
+ Let `charT` be either `char` or `wchar_t`. Each specialization of
5120
+ `formatter` is either enabled or disabled, as described below. A
5121
+ *debug-enabled* specialization of `formatter` additionally provides a
5122
+ public, constexpr, non-static member function `set_debug_format()` which
5123
+ modifies the state of the `formatter` to be as if the type of the
5124
+ *std-format-spec* parsed by the last call to `parse` were `?`. Each
5125
+ header that declares the template `formatter` provides the following
5126
+ enabled specializations:
5127
+
5128
+ - The debug-enabled specializations
5129
+ ``` cpp
5130
+ template<> struct formatter<char, char>;
5131
+ template<> struct formatter<char, wchar_t>;
5132
+ template<> struct formatter<wchar_t, wchar_t>;
5133
+ ```
5134
+ - For each `charT`, the debug-enabled string type specializations
5135
+ ``` cpp
5136
+ template<> struct formatter<charT*, charT>;
5137
+ template<> struct formatter<const charT*, charT>;
5138
+ template<size_t N> struct formatter<charT[N], charT>;
5139
+ template<class traits, class Allocator>
5140
+ struct formatter<basic_string<charT, traits, Allocator>, charT>;
5141
+ template<class traits>
5142
+ struct formatter<basic_string_view<charT, traits>, charT>;
5143
+ ```
5144
+ - For each `charT`, for each cv-unqualified arithmetic type
5145
+ `ArithmeticT` other than `char`, `wchar_t`, `char8_t`, `char16_t`, or
5146
+ `char32_t`, a specialization
5147
+ ``` cpp
5148
+ template<> struct formatter<ArithmeticT, charT>;
5149
+ ```
5150
+ - For each `charT`, the pointer type specializations
5151
+ ``` cpp
5152
+ template<> struct formatter<nullptr_t, charT>;
5153
+ template<> struct formatter<void*, charT>;
5154
+ template<> struct formatter<const void*, charT>;
5155
+ ```
5156
+
5157
+ The `parse` member functions of these formatters interpret the format
5158
+ specification as a *std-format-spec* as described in 
5159
+ [[format.string.std]].
5160
+
5161
+ Unless specified otherwise, for each type `T` for which a `formatter`
5162
+ specialization is provided by the library, each of the headers provides
5163
+ the following specialization:
5164
+
5165
+ ``` cpp
5166
+ template<> inline constexpr bool enable_nonlocking_formatter_optimization<T> = true;
5167
+ ```
5168
+
5169
+ [*Note 1*: Specializations such as `formatter<wchar_t, char>` that
5170
+ would require implicit multibyte / wide string or character conversion
5171
+ are disabled. — *end note*]
5172
+
5173
+ The header `<format>` provides the following disabled specializations:
5174
+
5175
+ - The string type specializations
5176
+ ``` cpp
5177
+ template<> struct formatter<char*, wchar_t>;
5178
+ template<> struct formatter<const char*, wchar_t>;
5179
+ template<size_t N> struct formatter<char[N], wchar_t>;
5180
+ template<class traits, class Allocator>
5181
+ struct formatter<basic_string<char, traits, Allocator>, wchar_t>;
5182
+ template<class traits>
5183
+ struct formatter<basic_string_view<char, traits>, wchar_t>;
5184
+ ```
5185
+
5186
+ For any types `T` and `charT` for which neither the library nor the user
5187
+ provides an explicit or partial specialization of the class template
5188
+ `formatter`, `formatter<T, charT>` is disabled.
5189
+
5190
+ If the library provides an explicit or partial specialization of
5191
+ `formatter<T, charT>`, that specialization is enabled and meets the
5192
+ requirements except as noted otherwise.
5193
+
5194
+ If `F` is a disabled specialization of `formatter`, these values are
5195
+ `false`:
5196
+
5197
+ - `is_default_constructible_v<F>`,
5198
+ - `is_copy_constructible_v<F>`,
5199
+ - `is_move_constructible_v<F>`,
5200
+ - `is_copy_assignable_v<F>`, and
5201
+ - `is_move_assignable_v<F>`.
5202
+
5203
+ An enabled specialization `formatter<T, charT>` meets the requirements
5204
+ [[formatter.requirements]].
5205
+
5206
+ [*Example 1*:
5207
+
5208
+ ``` cpp
5209
+ #include <format>
5210
+ #include <string>
5211
+
5212
+ enum color { red, green, blue };
5213
+ const char* color_names[] = { "red", "green", "blue" };
5214
+
5215
+ template<> struct std::formatter<color> : std::formatter<const char*> {
5216
+ auto format(color c, format_context& ctx) const {
5217
+ return formatter<const char*>::format(color_names[c], ctx);
5218
+ }
5219
+ };
5220
+
5221
+ struct err {};
5222
+
5223
+ std::string s0 = std::format("{}", 42); // OK, library-provided formatter
5224
+ std::string s1 = std::format("{}", L"foo"); // error: disabled formatter
5225
+ std::string s2 = std::format("{}", red); // OK, user-provided formatter
5226
+ std::string s3 = std::format("{}", err{}); // error: disabled formatter
5227
+ ```
5228
+
5229
+ — *end example*]
5230
+
5231
+ #### Formatting escaped characters and strings <a id="format.string.escaped">[[format.string.escaped]]</a>
5232
+
5233
+ A character or string can be formatted as *escaped* to make it more
5234
+ suitable for debugging or for logging.
5235
+
5236
+ The escaped string *E* representation of a string *S* is constructed by
5237
+ encoding a sequence of characters as follows. The associated character
5238
+ encoding *CE* for `charT` ([[lex.string.literal]]) is used to both
5239
+ interpret *S* and construct *E*.
5240
+
5241
+ - U+0022 (quotation mark) (`"`) is appended to *E*.
5242
+ - For each code unit sequence *X* in *S* that either encodes a single
5243
+ character, is a shift sequence, or is a sequence of ill-formed code
5244
+ units, processing is in order as follows:
5245
+ - If *X* encodes a single character *C*, then:
5246
+ - If *C* is one of the characters in [[format.escape.sequences]],
5247
+ then the two characters shown as the corresponding escape sequence
5248
+ are appended to *E*.
5249
+ - Otherwise, if *C* is not U+0020 (space) and
5250
+ - *CE* is UTF-8, UTF-16, or UTF-32 and *C* corresponds to a
5251
+ Unicode scalar value whose Unicode property `General_Category`
5252
+ has a value in the groups `Separator` (`Z`) or `Other` (`C`), as
5253
+ described by UAX \#44 of the Unicode Standard, or
5254
+ - *CE* is UTF-8, UTF-16, or UTF-32 and *C* corresponds to a
5255
+ Unicode scalar value with the Unicode property
5256
+ `Grapheme_Extend=Yes` as described by UAX \#44 of the Unicode
5257
+ Standard and *C* is not immediately preceded in *S* by a
5258
+ character *P* appended to *E* without translation to an escape
5259
+ sequence, or
5260
+ - *CE* is neither UTF-8, UTF-16, nor UTF-32 and *C* is one of an
5261
+ implementation-defined set of separator or non-printable
5262
+ characters
5263
+
5264
+ then the sequence `\u{hex-digit-sequence}` is appended to *E*,
5265
+ where `hex-digit-sequence` is the shortest hexadecimal
5266
+ representation of *C* using lower-case hexadecimal digits.
5267
+ - Otherwise, *C* is appended to *E*.
5268
+ - Otherwise, if *X* is a shift sequence, the effect on *E* and further
5269
+ decoding of *S* is unspecified. *Recommended practice:* A shift
5270
+ sequence should be represented in *E* such that the original code
5271
+ unit sequence of *S* can be reconstructed.
5272
+ - Otherwise (*X* is a sequence of ill-formed code units), each code
5273
+ unit *U* is appended to *E* in order as the sequence
5274
+ `\x{hex-digit-sequence}`, where `hex-digit-sequence` is the shortest
5275
+ hexadecimal representation of *U* using lower-case hexadecimal
5276
+ digits.
5277
+ - Finally, U+0022 (quotation mark) (`"`) is appended to *E*.
5278
+
5279
+ **Table: Mapping of characters to escape sequences** <a id="format.escape.sequences">[format.escape.sequences]</a>
5280
+
5281
+ | Character | Escape sequence |
5282
+ | ----------------------------- | --------------- |
5283
+ | U+0009 (character tabulation) | `\t` |
5284
+ | % U+000a (line feed) | `\n` |
5285
+ | % U+000d (carriage return) | `\r` |
5286
+ | % U+0022 (quotation mark) | `\"` |
5287
+ | % U+005c (reverse solidus) | `` |
5288
+
5289
+
5290
+ The escaped string representation of a character *C* is equivalent to
5291
+ the escaped string representation of a string of *C*, except that:
5292
+
5293
+ - the result starts and ends with U+0027 (apostrophe) (`'`) instead of
5294
+ U+0022 (quotation mark) (`"`), and
5295
+ - if *C* is U+0027 (apostrophe), the two characters `\'` are appended to
5296
+ *E*, and
5297
+ - if *C* is U+0022 (quotation mark), then *C* is appended unchanged.
5298
+
5299
+ [*Example 1*:
5300
+
5301
+ ``` cpp
5302
+ string s0 = format("[{}]", "h\tllo"); // s0 has value: [h\ \ \ \ llo]
5303
+ string s1 = format("[{:?}]", "h\tllo"); // s1 has value: ["h\ tllo"]
5304
+ string s2 = format("[{:?}]", "\importexample[-2.5pt]{example_01}"); \kern1.25pt// s2 has value: ["\importexample[-2.5pt]{example_01"]}
5305
+ string s3 = format("[{:?}, {:?}]", '\'', '"'); // s3 has value: ['\ '', '"']
5306
+
5307
+ // The following examples assume use of the UTF-8 encoding
5308
+ string s4 = format("[{:?}]", string("\0 \n \t \x02 \x1b", 9));
5309
+ // s4 has value: ["\ u{0\ \ n \ t \ u{2} \ u{1b}"]}
5310
+ string s5 = format("[{:?}]", "\xc3\x28"); // invalid UTF-8, s5 has value: ["\ x{c3\("]}
5311
+ string s6 = format("[{:?}]", "\importexample{example_02}"); \kern0.75pt// s6 has value: ["\importexample{example_03{u}{200d}\importexample{example_04}"]}
5312
+ string s7 = format("[{:?}]", "\u0301"); // s7 has value: ["\ u{301\"]}
5313
+ string s8 = format("[{:?}]", "\\\u0301"); // s8 has value: ["\ \ \ u{301\"]}
5314
+ string s9 = format("[{:?}]", "e\u0301\u0323"); // s9 has value: ["\importexample[-2pt]{example_06"]}
5315
+ ```
5316
+
5317
+ — *end example*]
5318
+
5319
+ #### Class template `basic_format_parse_context` <a id="format.parse.ctx">[[format.parse.ctx]]</a>
5320
+
5321
+ ``` cpp
5322
+ namespace std {
5323
+ template<class charT>
5324
+ class basic_format_parse_context {
5325
+ public:
5326
+ using char_type = charT;
5327
+ using const_iterator = basic_string_view<charT>::const_iterator;
5328
+ using iterator = const_iterator;
5329
+
5330
+ private:
5331
+ iterator begin_; // exposition only
5332
+ iterator end_; // exposition only
5333
+ enum indexing { unknown, manual, automatic }; // exposition only
5334
+ indexing indexing_; // exposition only
5335
+ size_t next_arg_id_; // exposition only
5336
+ size_t num_args_; // exposition only
5337
+
5338
+ public:
5339
+ constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt) noexcept;
5340
+ basic_format_parse_context(const basic_format_parse_context&) = delete;
5341
+ basic_format_parse_context& operator=(const basic_format_parse_context&) = delete;
5342
+
5343
+ constexpr const_iterator begin() const noexcept;
5344
+ constexpr const_iterator end() const noexcept;
5345
+ constexpr void advance_to(const_iterator it);
5346
+
5347
+ constexpr size_t next_arg_id();
5348
+ constexpr void check_arg_id(size_t id);
5349
+
5350
+ template<class... Ts>
5351
+ constexpr void check_dynamic_spec(size_t id) noexcept;
5352
+ constexpr void check_dynamic_spec_integral(size_t id) noexcept;
5353
+ constexpr void check_dynamic_spec_string(size_t id) noexcept;
5354
+ };
5355
+ }
5356
+ ```
5357
+
5358
+ An instance of `basic_format_parse_context` holds the format string
5359
+ parsing state, consisting of the format string range being parsed and
5360
+ the argument counter for automatic indexing.
5361
+
5362
+ If a program declares an explicit or partial specialization of
5363
+ `basic_format_parse_context`, the program is ill-formed, no diagnostic
5364
+ required.
5365
+
5366
+ ``` cpp
5367
+ constexpr explicit basic_format_parse_context(basic_string_view<charT> fmt) noexcept;
5368
+ ```
5369
+
5370
+ *Effects:* Initializes `begin_` with `fmt.begin()`, `end_` with
5371
+ `fmt.end()`, `indexing_` with `unknown`, `next_arg_id_` with `0`, and
5372
+ `num_args_` with `0`.
5373
+
5374
+ [*Note 1*: Any call to `next_arg_id`, `check_arg_id`, or
5375
+ `check_dynamic_spec` on an instance of `basic_format_parse_context`
5376
+ initialized using this constructor is not a core constant
5377
+ expression. — *end note*]
5378
+
5379
+ ``` cpp
5380
+ constexpr const_iterator begin() const noexcept;
5381
+ ```
5382
+
5383
+ *Returns:* `begin_`.
5384
+
5385
+ ``` cpp
5386
+ constexpr const_iterator end() const noexcept;
5387
+ ```
5388
+
5389
+ *Returns:* `end_`.
5390
+
5391
+ ``` cpp
5392
+ constexpr void advance_to(const_iterator it);
5393
+ ```
5394
+
5395
+ *Preconditions:* `end()` is reachable from `it`.
5396
+
5397
+ *Effects:* Equivalent to: `begin_ = it;`
5398
+
5399
+ ``` cpp
5400
+ constexpr size_t next_arg_id();
5401
+ ```
5402
+
5403
+ *Effects:* If `indexing_ != manual` is `true`, equivalent to:
5404
+
5405
+ ``` cpp
5406
+ if (indexing_ == unknown)
5407
+ indexing_ = automatic;
5408
+ return next_arg_id_++;
5409
+ ```
5410
+
5411
+ *Throws:* `format_error` if `indexing_ == manual` is `true`.
5412
+
5413
+ [*Note 2*: This indicates mixing of automatic and manual argument
5414
+ indexing. — *end note*]
5415
+
5416
+ *Remarks:* Let *`cur-arg-id`* be the value of `next_arg_id_` prior to
5417
+ this call. Call expressions where *`cur-arg-id`*` >= num_args_` is
5418
+ `true` are not core constant expressions [[expr.const]].
5419
+
5420
+ ``` cpp
5421
+ constexpr void check_arg_id(size_t id);
5422
+ ```
5423
+
5424
+ *Effects:* If `indexing_ != automatic` is `true`, equivalent to:
5425
+
5426
+ ``` cpp
5427
+ if (indexing_ == unknown)
5428
+ indexing_ = manual;
5429
+ ```
5430
+
5431
+ *Throws:* `format_error` if `indexing_ == automatic` is `true`.
5432
+
5433
+ [*Note 3*: This indicates mixing of automatic and manual argument
5434
+ indexing. — *end note*]
5435
+
5436
+ *Remarks:* A call to this function is a core constant
5437
+ expression [[expr.const]] only if `id < num_args_` is `true`.
5438
+
5439
+ ``` cpp
5440
+ template<class... Ts>
5441
+ constexpr void check_dynamic_spec(size_t id) noexcept;
5442
+ ```
5443
+
5444
+ *Mandates:* `sizeof...(Ts)` ≥ 1. The types in `Ts...` are unique. Each
5445
+ type in `Ts...` is one of `bool`, `char_type`, `int`, `unsigned int`,
5446
+ `long long int`, `unsigned long long int`, `float`, `double`,
5447
+ `long double`, `const char_type*`, `basic_string_view<char_type>`, or
5448
+ `const void*`.
5449
+
5450
+ *Remarks:* A call to this function is a core constant expression only if
5451
+
5452
+ - `id < num_args_` is `true` and
5453
+ - the type of the corresponding format argument (after conversion to
5454
+ `basic_format_arg<Context>`) is one of the types in `Ts...`.
5455
+
5456
+ ``` cpp
5457
+ constexpr void check_dynamic_spec_integral(size_t id) noexcept;
5458
+ ```
5459
+
5460
+ *Effects:* Equivalent to:
5461
+
5462
+ ``` cpp
5463
+ check_dynamic_spec<int, unsigned int, long long int, unsigned long long int>(id);
5464
+ ```
5465
+
5466
+ ``` cpp
5467
+ constexpr void check_dynamic_spec_string(size_t id) noexcept;
5468
+ ```
5469
+
5470
+ *Effects:* Equivalent to:
5471
+
5472
+ ``` cpp
5473
+ check_dynamic_spec<const char_type*, basic_string_view<char_type>>(id);
5474
+ ```
5475
+
5476
+ #### Class template `basic_format_context` <a id="format.context">[[format.context]]</a>
5477
+
5478
+ ``` cpp
5479
+ namespace std {
5480
+ template<class Out, class charT>
5481
+ class basic_format_context {
5482
+ basic_format_args<basic_format_context> args_; // exposition only
5483
+ Out out_; // exposition only
5484
+
5485
+ basic_format_context(const basic_format_context&) = delete;
5486
+ basic_format_context& operator=(const basic_format_context&) = delete;
5487
+
5488
+ public:
5489
+ using iterator = Out;
5490
+ using char_type = charT;
5491
+ template<class T> using formatter_type = formatter<T, charT>;
5492
+
5493
+ basic_format_arg<basic_format_context> arg(size_t id) const noexcept;
5494
+ std::locale locale();
5495
+
5496
+ iterator out();
5497
+ void advance_to(iterator it);
5498
+ };
5499
+ }
5500
+ ```
5501
+
5502
+ An instance of `basic_format_context` holds formatting state consisting
5503
+ of the formatting arguments and the output iterator.
5504
+
5505
+ If a program declares an explicit or partial specialization of
5506
+ `basic_format_context`, the program is ill-formed, no diagnostic
5507
+ required.
5508
+
5509
+ `Out` shall model `output_iterator<const charT&>`.
5510
+
5511
+ `format_context` is an alias for a specialization of
5512
+ `basic_format_context` with an output iterator that appends to `string`,
5513
+ such as `back_insert_iterator<string>`. Similarly, `wformat_context` is
5514
+ an alias for a specialization of `basic_format_context` with an output
5515
+ iterator that appends to `wstring`.
5516
+
5517
+ *Recommended practice:* For a given type `charT`, implementations should
5518
+ provide a single instantiation of `basic_format_context` for appending
5519
+ to `basic_string<charT>`, `vector<charT>`, or any other container with
5520
+ contiguous storage by wrapping those in temporary objects with a uniform
5521
+ interface (such as a `span<charT>`) and polymorphic reallocation.
5522
+
5523
+ ``` cpp
5524
+ basic_format_arg<basic_format_context> arg(size_t id) const noexcept;
5525
+ ```
5526
+
5527
+ *Returns:* `args_.get(id)`.
5528
+
5529
+ ``` cpp
5530
+ std::locale locale();
5531
+ ```
5532
+
5533
+ *Returns:* The locale passed to the formatting function if the latter
5534
+ takes one, and `std::locale()` otherwise.
5535
+
5536
+ ``` cpp
5537
+ iterator out();
5538
+ ```
5539
+
5540
+ *Effects:* Equivalent to: `return std::move(out_);`
5541
+
5542
+ ``` cpp
5543
+ void advance_to(iterator it);
5544
+ ```
5545
+
5546
+ *Effects:* Equivalent to: `out_ = std::move(it);`
5547
+
5548
+ [*Example 1*:
5549
+
5550
+ ``` cpp
5551
+ struct S { int value; };
5552
+
5553
+ template<> struct std::formatter<S> {
5554
+ size_t width_arg_id = 0;
5555
+
5556
+ // Parses a width argument id in the format { digit }.
5557
+ constexpr auto parse(format_parse_context& ctx) {
5558
+ auto iter = ctx.begin();
5559
+ auto is_digit = [](auto c) { return c >= '0' && c <= '9'; };
5560
+ auto get_char = [&]() { return iter != ctx.end() ? *iter : 0; };
5561
+ if (get_char() != '{')
5562
+ return iter;
5563
+ ++iter;
5564
+ char c = get_char();
5565
+ if (!is_digit(c) || (++iter, get_char()) != '}')
5566
+ throw format_error("invalid format");
5567
+ width_arg_id = c - '0';
5568
+ ctx.check_arg_id(width_arg_id);
5569
+ return ++iter;
5570
+ }
5571
+
5572
+ // Formats an S with width given by the argument width_arg_id.
5573
+ auto format(S s, format_context& ctx) const {
5574
+ int width = ctx.arg(width_arg_id).visit([](auto value) -> int {
5575
+ if constexpr (!is_integral_v<decltype(value)>)
5576
+ throw format_error("width is not integral");
5577
+ else if (value < 0 || value > numeric_limits<int>::max())
5578
+ throw format_error("invalid width");
5579
+ else
5580
+ return value;
5581
+ });
5582
+ return format_to(ctx.out(), "{0:x>{1}}", s.value, width);
5583
+ }
5584
+ };
5585
+
5586
+ std::string s = std::format("{0:{1}}", S{42}, 10); // value of s is "xxxxxxxx42"
5587
+ ```
5588
+
5589
+ — *end example*]
5590
+
5591
+ ### Formatting of ranges <a id="format.range">[[format.range]]</a>
5592
+
5593
+ #### Variable template `format_kind` <a id="format.range.fmtkind">[[format.range.fmtkind]]</a>
5594
+
5595
+ ``` cpp
5596
+ template<ranges::input_range R>
5597
+ requires same_as<R, remove_cvref_t<R>>
5598
+ constexpr range_format format_kind<R> = see below;
5599
+ ```
5600
+
5601
+ A program that instantiates the primary template of `format_kind` is
5602
+ ill-formed.
5603
+
5604
+ For a type `R`, `format_kind<R>` is defined as follows:
5605
+
5606
+ - If `same_as<remove_cvref_t<ranges::range_reference_t<R>>, R>` is
5607
+ `true`, `format_kind<R>` is `range_format::disabled`. \[*Note 1*: This
5608
+ prevents constraint recursion for ranges whose reference type is the
5609
+ same range type. For example, `std::filesystem::path` is a range of
5610
+ `std::filesystem::path`. — *end note*]
5611
+ - Otherwise, if the *qualified-id* `R::key_type` is valid and denotes a
5612
+ type:
5613
+ - If the *qualified-id* `R::mapped_type` is valid and denotes a type,
5614
+ let `U` be `remove_cvref_t<ranges::range_reference_t<R>>`. If either
5615
+ `U` is a specialization of `pair` or `U` is a specialization of
5616
+ `tuple` and `tuple_size_v<U> == 2`, `format_kind<R>` is
5617
+ `range_format::map`.
5618
+ - Otherwise, `format_kind<R>` is `range_format::set`.
5619
+ - Otherwise, `format_kind<R>` is `range_format::sequence`.
5620
+
5621
+ *Remarks:* Pursuant to [[namespace.std]], users may specialize
5622
+ `format_kind` for cv-unqualified program-defined types that model
5623
+ `ranges::input_range`. Such specializations shall be usable in constant
5624
+ expressions [[expr.const]] and have type `const range_format`.
5625
+
5626
+ #### Class template `range_formatter` <a id="format.range.formatter">[[format.range.formatter]]</a>
5627
+
5628
+ ``` cpp
5629
+ namespace std {
5630
+ template<class T, class charT = char>
5631
+ requires same_as<remove_cvref_t<T>, T> && formattable<T, charT>
5632
+ class range_formatter {
5633
+ formatter<T, charT> underlying_; // exposition only
5634
+ basic_string_view<charT> separator_ = STATICALLY-WIDEN<charT>(", "); // exposition only
5635
+ basic_string_view<charT> opening-bracket_ = STATICALLY-WIDEN<charT>("["); // exposition only
5636
+ basic_string_view<charT> closing-bracket_ = STATICALLY-WIDEN<charT>("]"); // exposition only
5637
+
5638
+ public:
5639
+ constexpr void set_separator(basic_string_view<charT> sep) noexcept;
5640
+ constexpr void set_brackets(basic_string_view<charT> opening,
5641
+ basic_string_view<charT> closing) noexcept;
5642
+ constexpr formatter<T, charT>& underlying() noexcept { return underlying_; }
5643
+ constexpr const formatter<T, charT>& underlying() const noexcept { return underlying_; }
5644
+
5645
+ template<class ParseContext>
5646
+ constexpr typename ParseContext::iterator
5647
+ parse(ParseContext& ctx);
5648
+
5649
+ template<ranges::input_range R, class FormatContext>
5650
+ requires formattable<ranges::range_reference_t<R>, charT> &&
5651
+ same_as<remove_cvref_t<ranges::range_reference_t<R>>, T>
5652
+ typename FormatContext::iterator
5653
+ format(R&& r, FormatContext& ctx) const;
5654
+ };
5655
+ }
5656
+ ```
5657
+
5658
+ The class template `range_formatter` is a utility for implementing
5659
+ `formatter` specializations for range types.
5660
+
5661
+ `range_formatter` interprets *format-spec* as a *range-format-spec*. The
5662
+ syntax of format specifications is as follows:
5663
+
5664
+ ``` bnf
5665
+ range-format-spec
5666
+ range-fill-and-alignₒₚₜ widthₒₚₜ 'n'ₒₚₜ range-typeₒₚₜ range-underlying-specₒₚₜ
5667
+ ```
5668
+
5669
+ ``` bnf
5670
+ range-fill-and-align
5671
+ range-fillₒₚₜ align
5672
+ ```
5673
+
5674
+ ``` bnf
5675
+ range-fill
5676
+ any character other than '{' or '}' or ':'
5677
+ ```
5678
+
5679
+ ``` bnf
5680
+ range-type
5681
+ 'm'
5682
+ 's'
5683
+ '?s'
5684
+ ```
5685
+
5686
+ ``` bnf
5687
+ range-underlying-spec
5688
+ ':' format-spec
5689
+ ```
5690
+
5691
+ For `range_formatter<T, charT>`, the *format-spec* in a
5692
+ *range-underlying-spec*, if any, is interpreted by
5693
+ `formatter<T, charT>`.
5694
+
5695
+ The *range-fill-and-align* is interpreted the same way as a
5696
+ *fill-and-align* [[format.string.std]]. The productions *align* and
5697
+ *width* are described in [[format.string]].
5698
+
5699
+ The `n` option causes the range to be formatted without the opening and
5700
+ closing brackets.
5701
+
5702
+ [*Note 1*: This is equivalent to invoking
5703
+ `set_brackets({}, {})`. — *end note*]
5704
+
5705
+ The *range-type* specifier changes the way a range is formatted, with
5706
+ certain options only valid with certain argument types. The meaning of
5707
+ the various type options is as specified in [[formatter.range.type]].
5708
+
5709
+ **Table: Meaning of range-type options** <a id="formatter.range.type">[formatter.range.type]</a>
5710
+
5711
+ | Option | Requirements | Meaning |
5712
+ | ------ | ----------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
5713
+ | % `m` | `T` shall be either a specialization of `pair` or a specialization of `tuple` such that `tuple_size_v<T>` is `2`. | Indicates that the opening bracket should be `"{"`, the closing bracket should be `"}"`, the separator should be `", "`, and each range element should be formatted as if `m` were specified for its tuple-type. *If the `n` option is provided in addition to the `m` option, both the opening and closing brackets are still empty.* |
5714
+ | % `s` | `T` shall be `charT`. | Indicates that the range should be formatted as a `string`. |
5715
+ | % `?s` | `T` shall be `charT`. | Indicates that the range should be formatted as an escaped string [[format.string.escaped]]. |
5716
+
5717
+
5718
+ If the *range-type* is `s` or `?s`, then there shall be no `n` option
5719
+ and no *range-underlying-spec*.
5720
+
5721
+ ``` cpp
5722
+ constexpr void set_separator(basic_string_view<charT> sep) noexcept;
5723
+ ```
5724
+
5725
+ *Effects:* Equivalent to: *`separator_`*` = sep;`
5726
+
5727
+ ``` cpp
5728
+ constexpr void set_brackets(basic_string_view<charT> opening,
5729
+ basic_string_view<charT> closing) noexcept;
5730
+ ```
5731
+
5732
+ *Effects:* Equivalent to:
5733
+
5734
+ ``` cpp
5735
+ opening-bracket_ = opening;
5736
+ closing-bracket_ = closing;
5737
+ ```
5738
+
5739
+ ``` cpp
5740
+ template<class ParseContext>
5741
+ constexpr typename ParseContext::iterator
5742
+ parse(ParseContext& ctx);
5743
+ ```
5744
+
5745
+ *Effects:* Parses the format specifiers as a *range-format-spec* and
5746
+ stores the parsed specifiers in `*this`. Calls
5747
+ *`underlying_`*`.parse(ctx)` to parse *format-spec* in
5748
+ *range-format-spec* or, if the latter is not present, an empty
5749
+ *format-spec*. The values of *opening-bracket\_*, *closing-bracket\_*,
5750
+ and *separator\_* are modified if and only if required by the
5751
+ *range-type* or the `n` option, if present. If:
5752
+
5753
+ - the *range-type* is neither `s` nor `?s`,
5754
+ - *`underlying_`*`.set_debug_format()` is a valid expression, and
5755
+ - there is no *range-underlying-spec*,
5756
+
5757
+ then calls *`underlying_`*`.set_debug_format()`.
5758
+
5759
+ *Returns:* An iterator past the end of the *range-format-spec*.
5760
+
5761
+ ``` cpp
5762
+ template<ranges::input_range R, class FormatContext>
5763
+ requires formattable<ranges::range_reference_t<R>, charT> &&
5764
+ same_as<remove_cvref_t<ranges::range_reference_t<R>>, T>
5765
+ typename FormatContext::iterator
5766
+ format(R&& r, FormatContext& ctx) const;
5767
+ ```
5768
+
5769
+ *Effects:* Writes the following into `ctx.out()`, adjusted according to
5770
+ the *range-format-spec*:
5771
+
5772
+ - If the *range-type* was `s`, then as if by formatting
5773
+ `basic_string<charT>(from_range, r)`.
5774
+ - Otherwise, if the *range-type* was `?s`, then as if by formatting
5775
+ `basic_string<charT>(from_range, r)` as an escaped
5776
+ string [[format.string.escaped]].
5777
+ - Otherwise,
5778
+ - *opening-bracket\_*,
5779
+ - for each element `e` of the range `r`:
5780
+ - the result of writing `e` via *underlying\_* and
5781
+ - *separator\_*, unless `e` is the last element of `r`, and
5782
+ - *closing-bracket\_*.
5783
+
5784
+ *Returns:* An iterator past the end of the output range.
5785
+
5786
+ #### Class template *`range-default-formatter`* <a id="format.range.fmtdef">[[format.range.fmtdef]]</a>
5787
+
5788
+ ``` cpp
5789
+ namespace std {
5790
+ template<ranges::input_range R, class charT>
5791
+ struct range-default-formatter<range_format::sequence, R, charT> { // exposition only
5792
+ private:
5793
+ using maybe-const-r = fmt-maybe-const<R, charT>; // exposition only
5794
+ range_formatter<remove_cvref_t<ranges::range_reference_t<maybe-const-r>>,
5795
+ charT> underlying_; // exposition only
5796
+
5797
+ public:
5798
+ constexpr void set_separator(basic_string_view<charT> sep) noexcept;
5799
+ constexpr void set_brackets(basic_string_view<charT> opening,
5800
+ basic_string_view<charT> closing) noexcept;
5801
+
5802
+ template<class ParseContext>
5803
+ constexpr typename ParseContext::iterator
5804
+ parse(ParseContext& ctx);
5805
+
5806
+ template<class FormatContext>
5807
+ typename FormatContext::iterator
5808
+ format(maybe-const-r& elems, FormatContext& ctx) const;
5809
+ };
5810
+ }
5811
+ ```
5812
+
5813
+ ``` cpp
5814
+ constexpr void set_separator(basic_string_view<charT> sep) noexcept;
5815
+ ```
5816
+
5817
+ *Effects:* Equivalent to: *`underlying_`*`.set_separator(sep);`
5818
+
5819
+ ``` cpp
5820
+ constexpr void set_brackets(basic_string_view<charT> opening,
5821
+ basic_string_view<charT> closing) noexcept;
5822
+ ```
5823
+
5824
+ *Effects:* Equivalent to:
5825
+ *`underlying_`*`.set_brackets(opening, closing);`
5826
+
5827
+ ``` cpp
5828
+ template<class ParseContext>
5829
+ constexpr typename ParseContext::iterator
5830
+ parse(ParseContext& ctx);
5831
+ ```
5832
+
5833
+ *Effects:* Equivalent to: `return `*`underlying_`*`.parse(ctx);`
5834
+
5835
+ ``` cpp
5836
+ template<class FormatContext>
5837
+ typename FormatContext::iterator
5838
+ format(maybe-const-r& elems, FormatContext& ctx) const;
5839
+ ```
5840
+
5841
+ *Effects:* Equivalent to: `return `*`underlying_`*`.format(elems, ctx);`
5842
+
5843
+ #### Specialization of *`range-default-formatter`* for maps <a id="format.range.fmtmap">[[format.range.fmtmap]]</a>
5844
+
5845
+ ``` cpp
5846
+ namespace std {
5847
+ template<ranges::input_range R, class charT>
5848
+ struct range-default-formatter<range_format::map, R, charT> {
5849
+ private:
5850
+ using maybe-const-map = fmt-maybe-const<R, charT>; // exposition only
5851
+ using element-type = // exposition only
5852
+ remove_cvref_t<ranges::range_reference_t<maybe-const-map>>;
5853
+ range_formatter<element-type, charT> underlying_; // exposition only
5854
+
5855
+ public:
5856
+ constexpr range-default-formatter();
5857
+
5858
+ template<class ParseContext>
5859
+ constexpr typename ParseContext::iterator
5860
+ parse(ParseContext& ctx);
5861
+
5862
+ template<class FormatContext>
5863
+ typename FormatContext::iterator
5864
+ format(maybe-const-map& r, FormatContext& ctx) const;
5865
+ };
5866
+ }
5867
+ ```
5868
+
5869
+ ``` cpp
5870
+ constexpr range-default-formatter();
5871
+ ```
5872
+
5873
+ *Mandates:* Either:
5874
+
5875
+ - *element-type* is a specialization of `pair`, or
5876
+ - *element-type* is a specialization of `tuple` and
5877
+ `tuple_size_v<`*`element-type`*`> == 2`.
5878
+
5879
+ *Effects:* Equivalent to:
5880
+
5881
+ ``` cpp
5882
+ underlying_.set_brackets(STATICALLY-WIDEN<charT>("{"), STATICALLY-WIDEN<charT>("}"));
5883
+ underlying_.underlying().set_brackets({}, {});
5884
+ underlying_.underlying().set_separator(STATICALLY-WIDEN<charT>(": "));
5885
+ ```
5886
+
5887
+ ``` cpp
5888
+ template<class ParseContext>
5889
+ constexpr typename ParseContext::iterator
5890
+ parse(ParseContext& ctx);
5891
+ ```
5892
+
5893
+ *Effects:* Equivalent to: `return `*`underlying_`*`.parse(ctx);`
5894
+
5895
+ ``` cpp
5896
+ template<class FormatContext>
5897
+ typename FormatContext::iterator
5898
+ format(maybe-const-map& r, FormatContext& ctx) const;
5899
+ ```
5900
+
5901
+ *Effects:* Equivalent to: `return `*`underlying_`*`.format(r, ctx);`
5902
+
5903
+ #### Specialization of *`range-default-formatter`* for sets <a id="format.range.fmtset">[[format.range.fmtset]]</a>
5904
+
5905
+ ``` cpp
5906
+ namespace std {
5907
+ template<ranges::input_range R, class charT>
5908
+ struct range-default-formatter<range_format::set, R, charT> {
5909
+ private:
5910
+ using maybe-const-set = fmt-maybe-const<R, charT>; // exposition only
5911
+ range_formatter<remove_cvref_t<ranges::range_reference_t<maybe-const-set>>,
5912
+ charT> underlying_; // exposition only
5913
+
5914
+ public:
5915
+ constexpr range-default-formatter();
5916
+
5917
+ template<class ParseContext>
5918
+ constexpr typename ParseContext::iterator
5919
+ parse(ParseContext& ctx);
5920
+
5921
+ template<class FormatContext>
5922
+ typename FormatContext::iterator
5923
+ format(maybe-const-set& r, FormatContext& ctx) const;
5924
+ };
5925
+ }
5926
+ ```
5927
+
5928
+ ``` cpp
5929
+ constexpr range-default-formatter();
5930
+ ```
5931
+
5932
+ *Effects:* Equivalent to:
5933
+
5934
+ ``` cpp
5935
+ underlying_.set_brackets(STATICALLY-WIDEN<charT>("{"), STATICALLY-WIDEN<charT>("}"));
5936
+ ```
5937
+
5938
+ ``` cpp
5939
+ template<class ParseContext>
5940
+ constexpr typename ParseContext::iterator
5941
+ parse(ParseContext& ctx);
5942
+ ```
5943
+
5944
+ *Effects:* Equivalent to: `return `*`underlying_`*`.parse(ctx);`
5945
+
5946
+ ``` cpp
5947
+ template<class FormatContext>
5948
+ typename FormatContext::iterator
5949
+ format(maybe-const-set& r, FormatContext& ctx) const;
5950
+ ```
5951
+
5952
+ *Effects:* Equivalent to: `return `*`underlying_`*`.format(r, ctx);`
5953
+
5954
+ #### Specialization of *`range-default-formatter`* for strings <a id="format.range.fmtstr">[[format.range.fmtstr]]</a>
5955
+
5956
+ ``` cpp
5957
+ namespace std {
5958
+ template<range_format K, ranges::input_range R, class charT>
5959
+ requires (K == range_format::string || K == range_format::debug_string)
5960
+ struct range-default-formatter<K, R, charT> {
5961
+ private:
5962
+ formatter<basic_string<charT>, charT> underlying_; // exposition only
5963
+
5964
+ public:
5965
+ template<class ParseContext>
5966
+ constexpr typename ParseContext::iterator
5967
+ parse(ParseContext& ctx);
5968
+
5969
+ template<class FormatContext>
5970
+ typename FormatContext::iterator
5971
+ format(see below& str, FormatContext& ctx) const;
5972
+ };
5973
+ }
5974
+ ```
5975
+
5976
+ *Mandates:* `same_as<remove_cvref_t<range_reference_t<R>>, charT>` is
5977
+ `true`.
5978
+
5979
+ ``` cpp
5980
+ template<class ParseContext>
5981
+ constexpr typename ParseContext::iterator
5982
+ parse(ParseContext& ctx);
5983
+ ```
5984
+
5985
+ *Effects:* Equivalent to:
5986
+
5987
+ ``` cpp
5988
+ auto i = underlying_.parse(ctx);
5989
+ if constexpr (K == range_format::debug_string) {
5990
+ underlying_.set_debug_format();
5991
+ }
5992
+ return i;
5993
+ ```
5994
+
5995
+ ``` cpp
5996
+ template<class FormatContext>
5997
+ typename FormatContext::iterator
5998
+ format(see below& r, FormatContext& ctx) const;
5999
+ ```
6000
+
6001
+ The type of `r` is `const R&` if `ranges::input_range<const R>` is
6002
+ `true` and `R&` otherwise.
6003
+
6004
+ *Effects:* Let *`s`* be a `basic_string<charT>` such that
6005
+ `ranges::equal(`*`s`*`, r)` is `true`. Equivalent to:
6006
+ `return `*`underlying_`*`.format(`*`s`*`, ctx);`
6007
+
6008
+ ### Arguments <a id="format.arguments">[[format.arguments]]</a>
6009
+
6010
+ #### Class template `basic_format_arg` <a id="format.arg">[[format.arg]]</a>
6011
+
6012
+ ``` cpp
6013
+ namespace std {
6014
+ template<class Context>
6015
+ class basic_format_arg {
6016
+ public:
6017
+ class handle;
6018
+
6019
+ private:
6020
+ using char_type = Context::char_type; // exposition only
6021
+
6022
+ variant<monostate, bool, char_type,
6023
+ int, unsigned int, long long int, unsigned long long int,
6024
+ float, double, long double,
6025
+ const char_type*, basic_string_view<char_type>,
6026
+ const void*, handle> value; // exposition only
6027
+
6028
+ template<class T> explicit basic_format_arg(T& v) noexcept; // exposition only
6029
+
6030
+ public:
6031
+ basic_format_arg() noexcept;
6032
+
6033
+ explicit operator bool() const noexcept;
6034
+
6035
+ template<class Visitor>
6036
+ decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);
6037
+ template<class R, class Visitor>
6038
+ R visit(this basic_format_arg arg, Visitor&& vis);
6039
+ };
6040
+ }
6041
+ ```
6042
+
6043
+ An instance of `basic_format_arg` provides access to a formatting
6044
+ argument for user-defined formatters.
6045
+
6046
+ The behavior of a program that adds specializations of
6047
+ `basic_format_arg` is undefined.
6048
+
6049
+ ``` cpp
6050
+ basic_format_arg() noexcept;
6051
+ ```
6052
+
6053
+ *Ensures:* `!(*this)`.
6054
+
6055
+ ``` cpp
6056
+ template<class T> explicit basic_format_arg(T& v) noexcept;
6057
+ ```
6058
+
6059
+ *Constraints:* `T` satisfies `formattable-with<Context>`.
6060
+
6061
+ *Preconditions:* If `decay_t<T>` is `char_type*` or `const char_type*`,
6062
+ `static_cast<const char_type*>(v)` points to an NTCTS [[defns.ntcts]].
6063
+
6064
+ *Effects:* Let `TD` be `remove_const_t<T>`.
6065
+
6066
+ - If `TD` is `bool` or `char_type`, initializes `value` with `v`;
6067
+ - otherwise, if `TD` is `char` and `char_type` is `wchar_t`, initializes
6068
+ `value` with `static_cast<wchar_t>(static_cast<unsigned char>(v))`;
6069
+ - otherwise, if `TD` is a signed integer type [[basic.fundamental]] and
6070
+ `sizeof(TD) <= sizeof(int)`, initializes `value` with
6071
+ `static_cast<int>(v)`;
6072
+ - otherwise, if `TD` is an unsigned integer type and
6073
+ `sizeof(TD) <= sizeof(unsigned int)`, initializes `value` with
6074
+ `static_cast<unsigned int>(v)`;
6075
+ - otherwise, if `TD` is a signed integer type and
6076
+ `sizeof(TD) <= sizeof(long long int)`, initializes `value` with
6077
+ `static_cast<long long int>(v)`;
6078
+ - otherwise, if `TD` is an unsigned integer type and
6079
+ `sizeof(TD) <= sizeof(unsigned long long int)`, initializes `value`
6080
+ with `static_cast<unsigned long long int>(v)`;
6081
+ - otherwise, if `TD` is a standard floating-point type, initializes
6082
+ `value` with `v`;
6083
+ - otherwise, if `TD` is a specialization of `basic_string_view` or
6084
+ `basic_string` and `TD::value_type` is `char_type`, initializes
6085
+ `value` with `basic_string_view<char_type>(v.data(), v.size())`;
6086
+ - otherwise, if `decay_t<TD>` is `char_type*` or `const char_type*`,
6087
+ initializes `value` with `static_cast<const char_type*>(v)`;
6088
+ - otherwise, if `is_void_v<remove_pointer_t<TD>>` is `true` or
6089
+ `is_null_pointer_v<TD>` is `true`, initializes `value` with
6090
+ `static_cast<const void*>(v)`;
6091
+ - otherwise, initializes `value` with `handle(v)`.
6092
+
6093
+ [*Note 1*: Constructing `basic_format_arg` from a pointer to a member
6094
+ is ill-formed unless the user provides an enabled specialization of
6095
+ `formatter` for that pointer to member type. — *end note*]
6096
+
6097
+ ``` cpp
6098
+ explicit operator bool() const noexcept;
6099
+ ```
6100
+
6101
+ *Returns:* `!holds_alternative<monostate>(value)`.
6102
+
6103
+ ``` cpp
6104
+ template<class Visitor>
6105
+ decltype(auto) visit(this basic_format_arg arg, Visitor&& vis);
6106
+ ```
6107
+
6108
+ *Effects:* Equivalent to:
6109
+ `return arg.value.visit(std::forward<Visitor>(vis));`
6110
+
6111
+ ``` cpp
6112
+ template<class R, class Visitor>
6113
+ R visit(this basic_format_arg arg, Visitor&& vis);
6114
+ ```
6115
+
6116
+ *Effects:* Equivalent to:
6117
+ `return arg.value.visit<R>(std::forward<Visitor>(vis));`
6118
+
6119
+ The class `handle` allows formatting an object of a user-defined type.
6120
+
6121
+ ``` cpp
6122
+ namespace std {
6123
+ template<class Context>
6124
+ class basic_format_arg<Context>::handle {
6125
+ const void* ptr_; // exposition only
6126
+ void (*format_)(basic_format_parse_context<char_type>&,
6127
+ Context&, const void*); // exposition only
6128
+
6129
+ template<class T> explicit handle(T& val) noexcept; // exposition only
6130
+
6131
+ public:
6132
+ void format(basic_format_parse_context<char_type>&, Context& ctx) const;
6133
+ };
6134
+ }
6135
+ ```
6136
+
6137
+ ``` cpp
6138
+ template<class T> explicit handle(T& val) noexcept;
6139
+ ```
6140
+
6141
+ Let
6142
+
6143
+ - `TD` be `remove_const_t<T>`,
6144
+ - `TQ` be `const TD` if `const TD` satisfies `formattable-with<Context>`
6145
+ and `TD` otherwise.
6146
+
6147
+ *Mandates:* `TQ` satisfies `formattable-with<Context>`.
6148
+
6149
+ *Effects:* Initializes `ptr_` with `addressof(val)` and `format_` with
6150
+
6151
+ ``` cpp
6152
+ [](basic_format_parse_context<char_type>& parse_ctx,
6153
+ Context& format_ctx, const void* ptr) {
6154
+ typename Context::template formatter_type<TD> f;
6155
+ parse_ctx.advance_to(f.parse(parse_ctx));
6156
+ format_ctx.advance_to(f.format(*const_cast<TQ*>(static_cast<const TD*>(ptr)),
6157
+ format_ctx));
6158
+ }
6159
+ ```
6160
+
6161
+ ``` cpp
6162
+ void format(basic_format_parse_context<char_type>& parse_ctx, Context& format_ctx) const;
6163
+ ```
6164
+
6165
+ *Effects:* Equivalent to: `format_(parse_ctx, format_ctx, ptr_);`
6166
+
6167
+ #### Class template *`format-arg-store`* <a id="format.arg.store">[[format.arg.store]]</a>
6168
+
6169
+ ``` cpp
6170
+ namespace std {
6171
+ template<class Context, class... Args>
6172
+ class format-arg-store { // exposition only
6173
+ array<basic_format_arg<Context>, sizeof...(Args)> args; // exposition only
6174
+ };
6175
+ }
6176
+ ```
6177
+
6178
+ An instance of *`format-arg-store`* stores formatting arguments.
6179
+
6180
+ ``` cpp
6181
+ template<class Context = format_context, class... Args>
6182
+ format-arg-store<Context, Args...> make_format_args(Args&... fmt_args);
6183
+ ```
6184
+
6185
+ *Preconditions:* The type
6186
+ `typename Context::template formatter_type<remove_const_t<``Tᵢ``>>`
6187
+ meets the requirements [[formatter.requirements]] for each `Tᵢ` in
6188
+ `Args`.
6189
+
6190
+ *Returns:* An object of type *`format-arg-store`*`<Context, Args...>`
6191
+ whose *args* data member is initialized with
6192
+ `{basic_format_arg<Context>(fmt_args)...}`.
6193
+
6194
+ ``` cpp
6195
+ template<class... Args>
6196
+ format-arg-store<wformat_context, Args...> make_wformat_args(Args&... args);
6197
+ ```
6198
+
6199
+ *Effects:* Equivalent to:
6200
+ `return make_format_args<wformat_context>(args...);`
6201
+
6202
+ #### Class template `basic_format_args` <a id="format.args">[[format.args]]</a>
6203
+
6204
+ ``` cpp
6205
+ namespace std {
6206
+ template<class Context>
6207
+ class basic_format_args {
6208
+ size_t size_; // exposition only
6209
+ const basic_format_arg<Context>* data_; // exposition only
6210
+
6211
+ public:
6212
+ template<class... Args>
6213
+ basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
6214
+
6215
+ basic_format_arg<Context> get(size_t i) const noexcept;
6216
+ };
6217
+
6218
+ template<class Context, class... Args>
6219
+ basic_format_args(format-arg-store<Context, Args...>) -> basic_format_args<Context>;
6220
+ }
6221
+ ```
6222
+
6223
+ An instance of `basic_format_args` provides access to formatting
6224
+ arguments.
6225
+
6226
+ *Recommended practice:* Implementations should optimize the
6227
+ representation of `basic_format_args` for a small number of formatting
6228
+ arguments.
6229
+
6230
+ [*Note 1*: For example, by storing indices of type alternatives
6231
+ separately from values and packing the former. — *end note*]
6232
+
6233
+ ``` cpp
6234
+ template<class... Args>
6235
+ basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
6236
+ ```
6237
+
6238
+ *Effects:* Initializes `size_` with `sizeof...(Args)` and `data_` with
6239
+ `store.args.data()`.
6240
+
6241
+ ``` cpp
6242
+ basic_format_arg<Context> get(size_t i) const noexcept;
6243
+ ```
6244
+
6245
+ *Returns:* `i < size_ ? data_[i] : basic_format_arg<Context>()`.
6246
+
6247
+ ### Tuple formatter <a id="format.tuple">[[format.tuple]]</a>
6248
+
6249
+ For each of `pair` and `tuple`, the library provides the following
6250
+ formatter specialization where `pair-or-tuple` is the name of the
6251
+ template:
6252
+
6253
+ ``` cpp
6254
+ namespace std {
6255
+ template<class charT, formattable<charT>... Ts>
6256
+ struct formatter<pair-or-tuple<Ts...>, charT> {
6257
+ private:
6258
+ tuple<formatter<remove_cvref_t<Ts>, charT>...> underlying_; // exposition only
6259
+ basic_string_view<charT> separator_ = STATICALLY-WIDEN<charT>(", "); // exposition only
6260
+ basic_string_view<charT> opening-bracket_ = STATICALLY-WIDEN<charT>("("); // exposition only
6261
+ basic_string_view<charT> closing-bracket_ = STATICALLY-WIDEN<charT>(")"); // exposition only
6262
+
6263
+ public:
6264
+ constexpr void set_separator(basic_string_view<charT> sep) noexcept;
6265
+ constexpr void set_brackets(basic_string_view<charT> opening,
6266
+ basic_string_view<charT> closing) noexcept;
6267
+
6268
+ template<class ParseContext>
6269
+ constexpr typename ParseContext::iterator
6270
+ parse(ParseContext& ctx);
6271
+
6272
+ template<class FormatContext>
6273
+ typename FormatContext::iterator
6274
+ format(see below& elems, FormatContext& ctx) const;
6275
+ };
6276
+
6277
+ template<class... Ts>
6278
+ constexpr bool enable_nonlocking_formatter_optimization<pair-or-tuple<Ts...>> =
6279
+ (enable_nonlocking_formatter_optimization<Ts> && ...);
6280
+ }
6281
+ ```
6282
+
6283
+ The `parse` member functions of these formatters interpret the format
6284
+ specification as a *tuple-format-spec* according to the following
6285
+ syntax:
6286
+
6287
+ ``` bnf
6288
+ tuple-format-spec
6289
+ tuple-fill-and-alignₒₚₜ widthₒₚₜ tuple-typeₒₚₜ
6290
+ ```
6291
+
6292
+ ``` bnf
6293
+ tuple-fill-and-align
6294
+ tuple-fillₒₚₜ align
6295
+ ```
6296
+
6297
+ ``` bnf
6298
+ tuple-fill
6299
+ any character other than '{' or '}' or ':'
6300
+ ```
6301
+
6302
+ ``` bnf
6303
+ tuple-type
6304
+ 'm'
6305
+ 'n'
6306
+ ```
6307
+
6308
+ The *tuple-fill-and-align* is interpreted the same way as a
6309
+ *fill-and-align* [[format.string.std]]. The productions *align* and
6310
+ *width* are described in [[format.string]].
6311
+
6312
+ The *tuple-type* specifier changes the way a `pair` or `tuple` is
6313
+ formatted, with certain options only valid with certain argument types.
6314
+ The meaning of the various type options is as specified in
6315
+ [[formatter.tuple.type]].
6316
+
6317
+ **Table: Meaning of tuple-type options** <a id="formatter.tuple.type">[formatter.tuple.type]</a>
6318
+
6319
+ | Option | Requirements | Meaning |
6320
+ | ------ | ------------ | -------------------------------------- |
6321
+ | <charT>(": ")); set_brackets({}, {}); \end{codeblock}% |
6322
+ | % `n` | none | Equivalent to: `set_brackets({}, {});` |
6323
+ | % none | none | No effects |
6324
+
6325
+ ``` cpp
6326
+ constexpr void set_separator(basic_string_view<charT> sep) noexcept;
6327
+ ```
6328
+
6329
+ *Effects:* Equivalent to: *`separator_`*` = sep;`
6330
+
6331
+ ``` cpp
6332
+ constexpr void set_brackets(basic_string_view<charT> opening,
6333
+ basic_string_view<charT> closing) noexcept;
6334
+ ```
6335
+
6336
+ *Effects:* Equivalent to:
6337
+
6338
+ ``` cpp
6339
+ opening-bracket_ = opening;
6340
+ closing-bracket_ = closing;
6341
+ ```
6342
+
6343
+ ``` cpp
6344
+ template<class ParseContext>
6345
+ constexpr typename ParseContext::iterator
6346
+ parse(ParseContext& ctx);
6347
+ ```
6348
+
6349
+ *Effects:* Parses the format specifiers as a *tuple-format-spec* and
6350
+ stores the parsed specifiers in `*this`. The values of
6351
+ *opening-bracket\_*, *closing-bracket\_*, and *separator\_* are modified
6352
+ if and only if required by the *tuple-type*, if present. For each
6353
+ element *`e`* in *underlying\_*, calls *`e`*`.parse(ctx)` to parse an
6354
+ empty *format-spec* and, if *`e`*`.set_debug_format()` is a valid
6355
+ expression, calls *`e`*`.set_debug_format()`.
6356
+
6357
+ *Returns:* An iterator past the end of the *tuple-format-spec*.
6358
+
6359
+ ``` cpp
6360
+ template<class FormatContext>
6361
+ typename FormatContext::iterator
6362
+ format(see below& elems, FormatContext& ctx) const;
6363
+ ```
6364
+
6365
+ The type of `elems` is:
6366
+
6367
+ - If `(formattable<const Ts, charT> && ...)` is `true`,
6368
+ `const `*`pair-or-tuple`*`<Ts...>&`.
6369
+ - Otherwise *`pair-or-tuple`*`<Ts...>&`.
6370
+
6371
+ *Effects:* Writes the following into `ctx.out()`, adjusted according to
6372
+ the *tuple-format-spec*:
6373
+
6374
+ - *opening-bracket\_*,
6375
+ - for each index `I` in the \[`0`, `sizeof...(Ts)`):
6376
+ - if `I != 0`, *separator\_*,
6377
+ - the result of writing `get<I>(elems)` via
6378
+ `get<I>(`*`underlying_`*`)`, and
6379
+ - *closing-bracket\_*.
6380
+
6381
+ *Returns:* An iterator past the end of the output range.
6382
+
6383
+ ### Class `format_error` <a id="format.error">[[format.error]]</a>
6384
+
6385
+ ``` cpp
6386
+ namespace std {
6387
+ class format_error : public runtime_error {
6388
+ public:
6389
+ constexpr explicit format_error(const string& what_arg);
6390
+ constexpr explicit format_error(const char* what_arg);
6391
+ };
6392
+ }
6393
+ ```
6394
+
6395
+ The class `format_error` defines the type of objects thrown as
6396
+ exceptions to report errors from the formatting library.
6397
+
6398
+ ``` cpp
6399
+ constexpr format_error(const string& what_arg);
6400
+ ```
6401
+
6402
+ *Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
6403
+
6404
+ ``` cpp
6405
+ constexpr format_error(const char* what_arg);
6406
+ ```
6407
+
6408
+ *Ensures:* `strcmp(what(), what_arg) == 0`.
6409
+
6410
+ ## Regular expressions library <a id="re">[[re]]</a>
6411
+
6412
+ ### General <a id="re.general">[[re.general]]</a>
6413
+
6414
+ Subclause [[re]] describes components that C++ programs may use to
6415
+ perform operations involving regular expression matching and searching.
6416
+
6417
+ The following subclauses describe a basic regular expression class
6418
+ template and its traits that can handle char-like [[strings.general]]
6419
+ template arguments, two specializations of this class template that
6420
+ handle sequences of `char` and `wchar_t`, a class template that holds
6421
+ the result of a regular expression match, a series of algorithms that
6422
+ allow a character sequence to be operated upon by a regular expression,
6423
+ and two iterator types for enumerating regular expression matches, as
6424
+ summarized in [[re.summary]].
6425
+
6426
+ **Table: Regular expressions library summary** <a id="re.summary">[re.summary]</a>
6427
+
6428
+ | Subclause | | Header |
6429
+ | --------------- | --------------------------- | --------- |
6430
+ | [[re.req]] | Requirements | |
6431
+ | [[re.const]] | Constants | `<regex>` |
6432
+ | [[re.badexp]] | Exception type | |
6433
+ | [[re.traits]] | Traits | |
6434
+ | [[re.regex]] | Regular expression template | |
6435
+ | [[re.submatch]] | Submatches | |
6436
+ | [[re.results]] | Match results | |
6437
+ | [[re.alg]] | Algorithms | |
6438
+ | [[re.iter]] | Iterators | |
6439
+ | [[re.grammar]] | Grammar | |
6440
+
6441
+
6442
+ The ECMAScript Language Specification described in Standard Ecma-262 is
6443
+ called *ECMA-262* in this Clause.
6444
+
6445
+ ### Requirements <a id="re.req">[[re.req]]</a>
6446
+
6447
+ This subclause defines requirements on classes representing regular
6448
+ expression traits.
6449
+
6450
+ [*Note 1*: The class template `regex_traits`, defined in [[re.traits]],
6451
+ meets these requirements. — *end note*]
6452
+
6453
+ The class template `basic_regex`, defined in [[re.regex]], needs a set
6454
+ of related types and functions to complete the definition of its
6455
+ semantics. These types and functions are provided as a set of member
6456
+ *typedef-name*s and functions in the template parameter `traits` used by
6457
+ the `basic_regex` class template. This subclause defines the semantics
6458
+ of these members.
6459
+
6460
+ To specialize class template `basic_regex` for a character container
6461
+ `CharT` and its related regular expression traits class `Traits`, use
6462
+ `basic_regex<CharT, Traits>`.
6463
+
6464
+ In the following requirements,
6465
+
6466
+ - `X` denotes a traits class defining types and functions for the
6467
+ character container type `charT`;
6468
+ - `u` is an object of type `X`;
6469
+ - `v` is an object of type `const X`;
6470
+ - `p` is a value of type `const charT*`;
6471
+ - `I1` and `I2` are input iterators [[input.iterators]];
6472
+ - `F1` and `F2` are forward iterators [[forward.iterators]];
6473
+ - `c` is a value of type `const charT`;
6474
+ - `s` is an object of type `X::string_type`;
6475
+ - `cs` is an object of type `const X::string_type`;
6476
+ - `b` is a value of type `bool`;
6477
+ - `I` is a value of type `int`;
6478
+ - `cl` is an object of type `X::char_class_type`; and
6479
+ - `loc` is an object of type `X::locale_type`.
6480
+
6481
+ A traits class `X` meets the regular expression traits requirements if
6482
+ the following types and expressions are well-formed and have the
6483
+ specified semantics.
6484
+
6485
+ ``` cpp
6486
+ typename X::char_type
6487
+ ```
6488
+
6489
+ *Result:* `charT`, the character container type used in the
6490
+ implementation of class template `basic_regex`.
6491
+
6492
+ ``` cpp
6493
+ typename X::string_type
6494
+ ```
6495
+
6496
+ *Result:* `basic_string<charT>`
6497
+
6498
+ ``` cpp
6499
+ typename X::locale_type
6500
+ ```
6501
+
6502
+ *Result:* A copy constructible type that represents the locale used by
6503
+ the traits class.
6504
+
6505
+ ``` cpp
6506
+ typename X::char_class_type
6507
+ ```
6508
+
6509
+ *Result:* A bitmask type [[bitmask.types]] representing a particular
6510
+ character classification.
6511
+
6512
+ ``` cpp
6513
+ X::length(p)
6514
+ ```
6515
+
6516
+ *Result:* `size_t`
6517
+
6518
+ *Returns:* The smallest `i` such that `p[i] == 0`.
6519
+
6520
+ *Complexity:* Linear in `i`.
6521
+
6522
+ ``` cpp
6523
+ v.translate(c)
6524
+ ```
6525
+
6526
+ *Result:* `X::char_type`
6527
+
6528
+ *Returns:* A character such that for any character `d` that is to be
6529
+ considered equivalent to `c` then `v.translate(c) == v.translate(d)`.
6530
+
6531
+ ``` cpp
6532
+ v.translate_nocase(c)
6533
+ ```
6534
+
6535
+ *Result:* `X::char_type`
6536
+
6537
+ *Returns:* For all characters `C` that are to be considered equivalent
6538
+ to `c` when comparisons are to be performed without regard to case, then
6539
+ `v.translate_nocase(c) == v.translate_nocase(C)`.
6540
+
6541
+ ``` cpp
6542
+ v.transform(F1, F2)
6543
+ ```
6544
+
6545
+ *Result:* `X::string_type`
6546
+
6547
+ *Returns:* A sort key for the character sequence designated by the
6548
+ iterator range \[`F1`, `F2`) such that if the character sequence \[`G1`,
6549
+ `G2`) sorts before the character sequence \[`H1`, `H2`) then
6550
+ `v.transform(G1, G2) < v.transform(H1, H2)`.
6551
+
6552
+ ``` cpp
6553
+ v.transform_primary(F1, F2)
6554
+ ```
6555
+
6556
+ *Result:* `X::string_type`
6557
+
6558
+ *Returns:* A sort key for the character sequence designated by the
6559
+ iterator range \[`F1`, `F2`) such that if the character sequence \[`G1`,
6560
+ `G2`) sorts before the character sequence \[`H1`, `H2`) when character
6561
+ case is not considered then
6562
+ `v.transform_primary(G1, G2) < v.transform_primary(H1, H2)`.
6563
+
6564
+ ``` cpp
6565
+ v.lookup_collatename(F1, F2)
6566
+ ```
6567
+
6568
+ *Result:* `X::string_type`
6569
+
6570
+ *Returns:* A sequence of characters that represents the collating
6571
+ element consisting of the character sequence designated by the iterator
6572
+ range \[`F1`, `F2`). Returns an empty string if the character sequence
6573
+ is not a valid collating element.
6574
+
6575
+ ``` cpp
6576
+ v.lookup_classname(F1, F2, b)
6577
+ ```
6578
+
6579
+ *Result:* `X::char_class_type`
6580
+
6581
+ *Returns:* Converts the character sequence designated by the iterator
6582
+ range \[`F1`, `F2`) into a value of a bitmask type that can subsequently
6583
+ be passed to `isctype`. Values returned from `lookup_classname` can be
6584
+ bitwise ’ed together; the resulting value represents membership in
6585
+ either of the corresponding character classes. If `b` is `true`, the
6586
+ returned bitmask is suitable for matching characters without regard to
6587
+ their case. Returns `0` if the character sequence is not the name of a
6588
+ character class recognized by `X`. The value returned shall be
6589
+ independent of the case of the characters in the sequence.
6590
+
6591
+ ``` cpp
6592
+ v.isctype(c, cl)
6593
+ ```
6594
+
6595
+ *Result:* `bool`
6596
+
6597
+ *Returns:* Returns `true` if character `c` is a member of one of the
6598
+ character classes designated by `cl`, `false` otherwise.
6599
+
6600
+ ``` cpp
6601
+ v.value(c, I)
6602
+ ```
6603
+
6604
+ *Result:* `int`
6605
+
6606
+ *Returns:* Returns the value represented by the digit *c* in base *I* if
6607
+ the character *c* is a valid digit in base *I*; otherwise returns `-1`.
6608
+
6609
+ [*Note 1*: The value of *I* will only be 8, 10, or 16. — *end note*]
6610
+
6611
+ ``` cpp
6612
+ u.imbue(loc)
6613
+ ```
6614
+
6615
+ *Result:* `X::locale_type`
6616
+
6617
+ *Effects:* Imbues `u` with the locale `loc` and returns the previous
6618
+ locale used by `u` if any.
6619
+
6620
+ ``` cpp
6621
+ v.getloc()
6622
+ ```
6623
+
6624
+ *Result:* `X::locale_type`
6625
+
6626
+ *Returns:* Returns the current locale used by `v`, if any.
6627
+
6628
+ [*Note 2*: Class template `regex_traits` meets the requirements for a
6629
+ regular expression traits class when it is specialized for `char` or
6630
+ `wchar_t`. This class template is described in the header `<regex>`, and
6631
+ is described in [[re.traits]]. — *end note*]
6632
+
6633
+ ### Header `<regex>` synopsis <a id="re.syn">[[re.syn]]</a>
6634
+
6635
+ ``` cpp
6636
+ #include <compare> // see [compare.syn]
6637
+ #include <initializer_list> // see [initializer.list.syn]
6638
+
6639
+ namespace std {
6640
+ // [re.const], regex constants
6641
+ namespace regex_constants {
6642
+ using syntax_option_type = T1;
6643
+ using match_flag_type = T2;
6644
+ using error_type = T3;
6645
+ }
6646
+
6647
+ // [re.badexp], class regex_error
6648
+ class regex_error;
6649
+
6650
+ // [re.traits], class template regex_traits
6651
+ template<class charT> struct regex_traits;
6652
+
6653
+ // [re.regex], class template basic_regex
6654
+ template<class charT, class traits = regex_traits<charT>> class basic_regex;
6655
+
6656
+ using regex = basic_regex<char>;
6657
+ using wregex = basic_regex<wchar_t>;
6658
+
6659
+ // [re.regex.swap], basic_regex swap
6660
+ template<class charT, class traits>
6661
+ void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
6662
+
6663
+ // [re.submatch], class template sub_match
6664
+ template<class BidirectionalIterator>
6665
+ class sub_match;
6666
+
6667
+ using csub_match = sub_match<const char*>;
6668
+ using wcsub_match = sub_match<const wchar_t*>;
6669
+ using ssub_match = sub_match<string::const_iterator>;
6670
+ using wssub_match = sub_match<wstring::const_iterator>;
6671
+
6672
+ // [re.submatch.op], sub_match non-member operators
6673
+ template<class BiIter>
6674
+ bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
6675
+ template<class BiIter>
6676
+ auto operator<=>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
6677
+
6678
+ template<class BiIter, class ST, class SA>
6679
+ bool operator==(
6680
+ const sub_match<BiIter>& lhs,
6681
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
6682
+ template<class BiIter, class ST, class SA>
6683
+ auto operator<=>(
6684
+ const sub_match<BiIter>& lhs,
6685
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
6686
+
6687
+ template<class BiIter>
6688
+ bool operator==(const sub_match<BiIter>& lhs,
6689
+ const typename iterator_traits<BiIter>::value_type* rhs);
6690
+ template<class BiIter>
6691
+ auto operator<=>(const sub_match<BiIter>& lhs,
6692
+ const typename iterator_traits<BiIter>::value_type* rhs);
6693
+
6694
+ template<class BiIter>
6695
+ bool operator==(const sub_match<BiIter>& lhs,
6696
+ const typename iterator_traits<BiIter>::value_type& rhs);
6697
+ template<class BiIter>
6698
+ auto operator<=>(const sub_match<BiIter>& lhs,
6699
+ const typename iterator_traits<BiIter>::value_type& rhs);
6700
+
6701
+ template<class charT, class ST, class BiIter>
6702
+ basic_ostream<charT, ST>&
6703
+ operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
6704
+
6705
+ // [re.results], class template match_results
6706
+ template<class BidirectionalIterator,
6707
+ class Allocator = allocator<sub_match<BidirectionalIterator>>>
6708
+ class match_results;
6709
+
6710
+ using cmatch = match_results<const char*>;
6711
+ using wcmatch = match_results<const wchar_t*>;
6712
+ using smatch = match_results<string::const_iterator>;
6713
+ using wsmatch = match_results<wstring::const_iterator>;
6714
+
6715
+ // match_results comparisons
6716
+ template<class BidirectionalIterator, class Allocator>
6717
+ bool operator==(const match_results<BidirectionalIterator, Allocator>& m1,
6718
+ const match_results<BidirectionalIterator, Allocator>& m2);
6719
+
6720
+ // [re.results.swap], match_results swap
6721
+ template<class BidirectionalIterator, class Allocator>
6722
+ void swap(match_results<BidirectionalIterator, Allocator>& m1,
6723
+ match_results<BidirectionalIterator, Allocator>& m2);
6724
+
6725
+ // [re.alg.match], function template regex_match
6726
+ template<class BidirectionalIterator, class Allocator, class charT, class traits>
6727
+ bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
6728
+ match_results<BidirectionalIterator, Allocator>& m,
6729
+ const basic_regex<charT, traits>& e,
6730
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6731
+ template<class BidirectionalIterator, class charT, class traits>
6732
+ bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
6733
+ const basic_regex<charT, traits>& e,
6734
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6735
+ template<class charT, class Allocator, class traits>
6736
+ bool regex_match(const charT* str, match_results<const charT*, Allocator>& m,
6737
+ const basic_regex<charT, traits>& e,
6738
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6739
+ template<class ST, class SA, class Allocator, class charT, class traits>
6740
+ bool regex_match(const basic_string<charT, ST, SA>& s,
6741
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
6742
+ Allocator>& m,
6743
+ const basic_regex<charT, traits>& e,
6744
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6745
+ template<class ST, class SA, class Allocator, class charT, class traits>
6746
+ bool regex_match(const basic_string<charT, ST, SA>&&,
6747
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
6748
+ Allocator>&,
6749
+ const basic_regex<charT, traits>&,
6750
+ regex_constants::match_flag_type = regex_constants::match_default) = delete;
6751
+ template<class charT, class traits>
6752
+ bool regex_match(const charT* str,
6753
+ const basic_regex<charT, traits>& e,
6754
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6755
+ template<class ST, class SA, class charT, class traits>
6756
+ bool regex_match(const basic_string<charT, ST, SA>& s,
6757
+ const basic_regex<charT, traits>& e,
6758
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6759
+
6760
+ // [re.alg.search], function template regex_search
6761
+ template<class BidirectionalIterator, class Allocator, class charT, class traits>
6762
+ bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
6763
+ match_results<BidirectionalIterator, Allocator>& m,
6764
+ const basic_regex<charT, traits>& e,
6765
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6766
+ template<class BidirectionalIterator, class charT, class traits>
6767
+ bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
6768
+ const basic_regex<charT, traits>& e,
6769
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6770
+ template<class charT, class Allocator, class traits>
6771
+ bool regex_search(const charT* str,
6772
+ match_results<const charT*, Allocator>& m,
6773
+ const basic_regex<charT, traits>& e,
6774
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6775
+ template<class charT, class traits>
6776
+ bool regex_search(const charT* str,
6777
+ const basic_regex<charT, traits>& e,
6778
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6779
+ template<class ST, class SA, class charT, class traits>
6780
+ bool regex_search(const basic_string<charT, ST, SA>& s,
6781
+ const basic_regex<charT, traits>& e,
6782
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6783
+ template<class ST, class SA, class Allocator, class charT, class traits>
6784
+ bool regex_search(const basic_string<charT, ST, SA>& s,
6785
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
6786
+ Allocator>& m,
6787
+ const basic_regex<charT, traits>& e,
6788
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6789
+ template<class ST, class SA, class Allocator, class charT, class traits>
6790
+ bool regex_search(const basic_string<charT, ST, SA>&&,
6791
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
6792
+ Allocator>&,
6793
+ const basic_regex<charT, traits>&,
6794
+ regex_constants::match_flag_type
6795
+ = regex_constants::match_default) = delete;
6796
+
6797
+ // [re.alg.replace], function template regex_replace
6798
+ template<class OutputIterator, class BidirectionalIterator,
6799
+ class traits, class charT, class ST, class SA>
6800
+ OutputIterator
6801
+ regex_replace(OutputIterator out,
6802
+ BidirectionalIterator first, BidirectionalIterator last,
6803
+ const basic_regex<charT, traits>& e,
6804
+ const basic_string<charT, ST, SA>& fmt,
6805
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6806
+ template<class OutputIterator, class BidirectionalIterator, class traits, class charT>
6807
+ OutputIterator
6808
+ regex_replace(OutputIterator out,
6809
+ BidirectionalIterator first, BidirectionalIterator last,
6810
+ const basic_regex<charT, traits>& e,
6811
+ const charT* fmt,
6812
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6813
+ template<class traits, class charT, class ST, class SA, class FST, class FSA>
6814
+ basic_string<charT, ST, SA>
6815
+ regex_replace(const basic_string<charT, ST, SA>& s,
6816
+ const basic_regex<charT, traits>& e,
6817
+ const basic_string<charT, FST, FSA>& fmt,
6818
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6819
+ template<class traits, class charT, class ST, class SA>
6820
+ basic_string<charT, ST, SA>
6821
+ regex_replace(const basic_string<charT, ST, SA>& s,
6822
+ const basic_regex<charT, traits>& e,
6823
+ const charT* fmt,
6824
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6825
+ template<class traits, class charT, class ST, class SA>
6826
+ basic_string<charT>
6827
+ regex_replace(const charT* s,
6828
+ const basic_regex<charT, traits>& e,
6829
+ const basic_string<charT, ST, SA>& fmt,
6830
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6831
+ template<class traits, class charT>
6832
+ basic_string<charT>
6833
+ regex_replace(const charT* s,
6834
+ const basic_regex<charT, traits>& e,
6835
+ const charT* fmt,
6836
+ regex_constants::match_flag_type flags = regex_constants::match_default);
6837
+
6838
+ // [re.regiter], class template regex_iterator
6839
+ template<class BidirectionalIterator,
6840
+ class charT = typename iterator_traits<BidirectionalIterator>::value_type,
6841
+ class traits = regex_traits<charT>>
6842
+ class regex_iterator;
6843
+
6844
+ using cregex_iterator = regex_iterator<const char*>;
6845
+ using wcregex_iterator = regex_iterator<const wchar_t*>;
6846
+ using sregex_iterator = regex_iterator<string::const_iterator>;
6847
+ using wsregex_iterator = regex_iterator<wstring::const_iterator>;
6848
+
6849
+ // [re.tokiter], class template regex_token_iterator
6850
+ template<class BidirectionalIterator,
6851
+ class charT = typename iterator_traits<BidirectionalIterator>::value_type,
6852
+ class traits = regex_traits<charT>>
6853
+ class regex_token_iterator;
6854
+
6855
+ using cregex_token_iterator = regex_token_iterator<const char*>;
6856
+ using wcregex_token_iterator = regex_token_iterator<const wchar_t*>;
6857
+ using sregex_token_iterator = regex_token_iterator<string::const_iterator>;
6858
+ using wsregex_token_iterator = regex_token_iterator<wstring::const_iterator>;
6859
+
6860
+ namespace pmr {
6861
+ template<class BidirectionalIterator>
6862
+ using match_results =
6863
+ std::match_results<BidirectionalIterator,
6864
+ polymorphic_allocator<sub_match<BidirectionalIterator>>>;
6865
+
6866
+ using cmatch = match_results<const char*>;
6867
+ using wcmatch = match_results<const wchar_t*>;
6868
+ using smatch = match_results<string::const_iterator>;
6869
+ using wsmatch = match_results<wstring::const_iterator>;
6870
+ }
6871
+ }
6872
+ ```
6873
+
6874
+ ### Namespace `std::regex_constants` <a id="re.const">[[re.const]]</a>
6875
+
6876
+ #### General <a id="re.const.general">[[re.const.general]]</a>
6877
+
6878
+ The namespace `std::regex_constants` holds symbolic constants used by
6879
+ the regular expression library. This namespace provides three types,
6880
+ `syntax_option_type`, `match_flag_type`, and `error_type`, along with
6881
+ several constants of these types.
6882
+
6883
+ #### Bitmask type `syntax_option_type` <a id="re.synopt">[[re.synopt]]</a>
6884
+
6885
+ ``` cpp
6886
+ namespace std::regex_constants {
6887
+ using syntax_option_type = T1;
6888
+ inline constexpr syntax_option_type icase = unspecified;
6889
+ inline constexpr syntax_option_type nosubs = unspecified;
6890
+ inline constexpr syntax_option_type optimize = unspecified;
6891
+ inline constexpr syntax_option_type collate = unspecified;
6892
+ inline constexpr syntax_option_type ECMAScript = unspecified;
6893
+ inline constexpr syntax_option_type basic = unspecified;
6894
+ inline constexpr syntax_option_type extended = unspecified;
6895
+ inline constexpr syntax_option_type awk = unspecified;
6896
+ inline constexpr syntax_option_type grep = unspecified;
6897
+ inline constexpr syntax_option_type egrep = unspecified;
6898
+ inline constexpr syntax_option_type multiline = unspecified;
6899
+ }
6900
+ ```
6901
+
6902
+ The type `syntax_option_type` is an *implementation-defined* bitmask
6903
+ type [[bitmask.types]]. Setting its elements has the effects listed in
6904
+ [[re.synopt]]. A valid value of type `syntax_option_type` shall have at
6905
+ most one of the grammar elements `ECMAScript`, `basic`, `extended`,
6906
+ `awk`, `grep`, `egrep`, set. If no grammar element is set, the default
6907
+ grammar is `ECMAScript`.
6908
+
6909
+ **Table: `syntax_option_type` effects** <a id="re.synopt">[re.synopt]</a>
6910
+
6911
+ | Element | Effect(s) if set |
6912
+ | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
6913
+ | % `icase` | Specifies that matching of regular expressions against a character container sequence shall be performed without regard to case. \indexlibrarymember{syntax_option_type}{icase}% |
6914
+ | % `nosubs` | Specifies that no sub-expressions shall be considered to be marked, so that when a regular expression is matched against a character container sequence, no sub-expression matches shall be stored in the supplied `match_results` object. \indexlibrarymember{syntax_option_type}{nosubs}% |
6915
+ | % `optimize` | Specifies that the regular expression engine should pay more attention to the speed with which regular expressions are matched, and less to the speed with which regular expression objects are constructed. Otherwise it has no detectable effect on the program output. \indexlibrarymember{syntax_option_type}{optimize}% |
6916
+ | % `collate` | Specifies that character ranges of the form `"[a-b]"` shall be locale sensitive.% \indexlibrarymember{syntax_option_type}{collate}% \indextext{locale}% |
6917
+ | % `ECMAScript` | Specifies that the grammar recognized by the regular expression engine shall be that used by ECMAScript in ECMA-262, as modified in~ [[re.grammar]]. \xref{ECMA-262 15.10} \indextext{ECMAScript}% \indexlibrarymember{syntax_option_type}{ECMAScript}% |
6918
+ | % `basic` | Specifies that the grammar recognized by the regular expression engine shall be that used by basic regular expressions in POSIX. \xref{POSIX, Base Definitions and Headers, Section 9.3} \indextext{POSIX!regular expressions}% \indexlibrarymember{syntax_option_type}{basic}% |
6919
+ | % `extended` | Specifies that the grammar recognized by the regular expression engine shall be that used by extended regular expressions in POSIX. \xref{POSIX, Base Definitions and Headers, Section 9.4} \indextext{POSIX!extended regular expressions}% \indexlibrarymember{syntax_option_type}{extended}% |
6920
+ | % `awk` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility awk in POSIX. \indexlibrarymember{syntax_option_type}{awk}% |
6921
+ | % `grep` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep in POSIX. \indexlibrarymember{syntax_option_type}{grep}% |
6922
+ | % `egrep` | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep when given the -E option in POSIX. \indexlibrarymember{syntax_option_type}{egrep}% |
6923
+ | % `multiline` | Specifies that `^` shall match the beginning of a line and `$` shall match the end of a line, if the `ECMAScript` engine is selected. \indexlibrarymember{syntax_option_type}{multiline}% |
6924
+
6925
+
6926
+ #### Bitmask type `match_flag_type` <a id="re.matchflag">[[re.matchflag]]</a>
6927
+
6928
+ ``` cpp
6929
+ namespace std::regex_constants {
6930
+ using match_flag_type = T2;
6931
+ inline constexpr match_flag_type match_default = {};
6932
+ inline constexpr match_flag_type match_not_bol = unspecified;
6933
+ inline constexpr match_flag_type match_not_eol = unspecified;
6934
+ inline constexpr match_flag_type match_not_bow = unspecified;
6935
+ inline constexpr match_flag_type match_not_eow = unspecified;
6936
+ inline constexpr match_flag_type match_any = unspecified;
6937
+ inline constexpr match_flag_type match_not_null = unspecified;
6938
+ inline constexpr match_flag_type match_continuous = unspecified;
6939
+ inline constexpr match_flag_type match_prev_avail = unspecified;
6940
+ inline constexpr match_flag_type format_default = {};
6941
+ inline constexpr match_flag_type format_sed = unspecified;
6942
+ inline constexpr match_flag_type format_no_copy = unspecified;
6943
+ inline constexpr match_flag_type format_first_only = unspecified;
6944
+ }
6945
+ ```
6946
+
6947
+ The type `match_flag_type` is an *implementation-defined* bitmask type
6948
+ [[bitmask.types]]. The constants of that type, except for
6949
+ `match_default` and `format_default`, are bitmask elements. The
6950
+ `match_default` and `format_default` constants are empty bitmasks.
6951
+ Matching a regular expression against a sequence of characters
6952
+ \[`first`, `last`) proceeds according to the rules of the grammar
6953
+ specified for the regular expression object, modified according to the
6954
+ effects listed in [[re.matchflag]] for any bitmask elements set.
6955
+
6956
+ **Table: `regex_constants::match_flag_type` effects** <a id="re.matchflag">[re.matchflag]</a>
6957
+
6958
+ | Element | Effect(s) if set |
6959
+ | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
6960
+ | % \indexlibraryglobal{match_not_bol}% `match_not_bol` | The first character in the sequence {[}`first`, `last`{)} shall be treated as though it is not at the beginning of a line, so the character \verb|^| in the regular expression shall not match {[}`first`, `first`{)}. |
6961
+ | % \indexlibraryglobal{match_not_eol}% `match_not_eol` | The last character in the sequence {[}`first`, `last`{)} shall be treated as though it is not at the end of a line, so the character \verb|"$"| in the regular expression shall not match {[}`last`, `last`{)}. |
6962
+ | % \indexlibraryglobal{match_not_bow}% `match_not_bow` | The expression \verb|"b"| shall not match the sub-sequence {[}`first`, `first`{)}. |
6963
+ | % \indexlibraryglobal{match_not_eow}% `match_not_eow` | The expression \verb|"b"| shall not match the sub-sequence {[}`last`, `last`{)}. |
6964
+ | % \indexlibraryglobal{match_any}% `match_any` | If more than one match is possible then any match is an acceptable result. |
6965
+ | % \indexlibraryglobal{match_not_null}% `match_not_null` | The expression shall not match an empty sequence. |
6966
+ | % \indexlibraryglobal{match_continuous}% `match_continuous` | The expression shall only match a sub-sequence that begins at `first`. |
6967
+ | % \indexlibraryglobal{match_prev_avail}% `match_prev_avail` | \verb!--first! is a valid iterator position. When this flag is set the flags `match_not_bol` and `match_not_bow` shall be ignored by the regular expression algorithms [[re.alg]] and iterators [[re.iter]]. |
6968
+ | % \indexlibraryglobal{format_default}% `format_default` | When a regular expression match is to be replaced by a new string, the new string shall be constructed using the rules used by the ECMAScript replace function in ECMA-262, part 15.5.4.11 String.prototype.replace. In addition, during search and replace operations all non-overlapping occurrences of the regular expression shall be located and replaced, and sections of the input that did not match the expression shall be copied unchanged to the output string. |
6969
+ | % \indexlibraryglobal{format_sed}% `format_sed` | When a regular expression match is to be replaced by a new string, the new string shall be constructed using the rules used by the sed utility in POSIX. |
6970
+ | % \indexlibraryglobal{format_no_copy}% `format_no_copy` | During a search and replace operation, sections of the character container sequence being searched that do not match the regular expression shall not be copied to the output string. |
6971
+ | % \indexlibraryglobal{format_first_only}% `format_first_only` | When specified during a search and replace operation, only the first occurrence of the regular expression shall be replaced. |
6972
+
6973
+
6974
+ #### Implementation-defined `error_type` <a id="re.err">[[re.err]]</a>
6975
+
6976
+ ``` cpp
6977
+ namespace std::regex_constants {
6978
+ using error_type = T3;
6979
+ inline constexpr error_type error_collate = unspecified;
6980
+ inline constexpr error_type error_ctype = unspecified;
6981
+ inline constexpr error_type error_escape = unspecified;
6982
+ inline constexpr error_type error_backref = unspecified;
6983
+ inline constexpr error_type error_brack = unspecified;
6984
+ inline constexpr error_type error_paren = unspecified;
6985
+ inline constexpr error_type error_brace = unspecified;
6986
+ inline constexpr error_type error_badbrace = unspecified;
6987
+ inline constexpr error_type error_range = unspecified;
6988
+ inline constexpr error_type error_space = unspecified;
6989
+ inline constexpr error_type error_badrepeat = unspecified;
6990
+ inline constexpr error_type error_complexity = unspecified;
6991
+ inline constexpr error_type error_stack = unspecified;
6992
+ }
6993
+ ```
6994
+
6995
+ The type `error_type` is an *implementation-defined* enumerated type
6996
+ [[enumerated.types]]. Values of type `error_type` represent the error
6997
+ conditions described in [[re.err]]:
6998
+
6999
+ **Table: `error_type` values in the C locale** <a id="re.err">[re.err]</a>
7000
+
7001
+ | Value | Error condition |
7002
+ | -------------------- | ------------------------------------------------------------------------------------------------------------------ |
7003
+ | `error_collate` | The expression contains an invalid collating element name. |
7004
+ | % `error_ctype` | The expression contains an invalid character class name. |
7005
+ | % `error_escape` | The expression contains an invalid escaped character, or a trailing escape. |
7006
+ | % `error_backref` | The expression contains an invalid back reference. |
7007
+ | % `error_brack` | The expression contains mismatched \verb|[| and \verb|]|. |
7008
+ | % `error_paren` | The expression contains mismatched \verb|(| and \verb|)|. |
7009
+ | % `error_brace` | The expression contains mismatched \verb|{| and \verb|}|. |
7010
+ | % `error_badbrace` | The expression contains an invalid range in a \verb|{}| expression. |
7011
+ | % `error_range` | The expression contains an invalid character range, such as \verb|[b-a]| in most encodings. |
7012
+ | % `error_space` | There is insufficient memory to convert the expression into a finite state machine. |
7013
+ | % `error_badrepeat` | One of \verb|*?+{| is not preceded by a valid regular expression. |
7014
+ | % `error_complexity` | The complexity of an attempted match against a regular expression exceeds a pre-set level. |
7015
+ | % `error_stack` | There is insufficient memory to determine whether the regular expression matches the specified character sequence. |
7016
+
7017
+
7018
+ ### Class `regex_error` <a id="re.badexp">[[re.badexp]]</a>
7019
+
7020
+ ``` cpp
7021
+ namespace std {
7022
+ class regex_error : public runtime_error {
7023
+ public:
7024
+ explicit regex_error(regex_constants::error_type ecode);
7025
+ regex_constants::error_type code() const;
7026
+ };
7027
+ }
7028
+ ```
7029
+
7030
+ The class `regex_error` defines the type of objects thrown as exceptions
7031
+ to report errors from the regular expression library.
7032
+
7033
+ ``` cpp
7034
+ regex_error(regex_constants::error_type ecode);
7035
+ ```
7036
+
7037
+ *Ensures:* `ecode == code()`.
7038
+
7039
+ ``` cpp
7040
+ regex_constants::error_type code() const;
7041
+ ```
7042
+
7043
+ *Returns:* The error code that was passed to the constructor.
7044
+
7045
+ ### Class template `regex_traits` <a id="re.traits">[[re.traits]]</a>
7046
+
7047
+ ``` cpp
7048
+ namespace std {
7049
+ template<class charT>
7050
+ struct regex_traits {
7051
+ using char_type = charT;
7052
+ using string_type = basic_string<char_type>;
7053
+ using locale_type = locale;
7054
+ using char_class_type = bitmask_type;
7055
+
7056
+ regex_traits();
7057
+ static size_t length(const char_type* p);
7058
+ charT translate(charT c) const;
7059
+ charT translate_nocase(charT c) const;
7060
+ template<class ForwardIterator>
7061
+ string_type transform(ForwardIterator first, ForwardIterator last) const;
7062
+ template<class ForwardIterator>
7063
+ string_type transform_primary(
7064
+ ForwardIterator first, ForwardIterator last) const;
7065
+ template<class ForwardIterator>
7066
+ string_type lookup_collatename(
7067
+ ForwardIterator first, ForwardIterator last) const;
7068
+ template<class ForwardIterator>
7069
+ char_class_type lookup_classname(
7070
+ ForwardIterator first, ForwardIterator last, bool icase = false) const;
7071
+ bool isctype(charT c, char_class_type f) const;
7072
+ int value(charT ch, int radix) const;
7073
+ locale_type imbue(locale_type l);
7074
+ locale_type getloc() const;
7075
+ };
7076
+ }
7077
+ ```
7078
+
7079
+ The specializations `regex_traits<char>` and `regex_traits<wchar_t>`
7080
+ meet the requirements for a regular expression traits class [[re.req]].
7081
+
7082
+ ``` cpp
7083
+ using char_class_type = bitmask_type;
7084
+ ```
7085
+
7086
+ The type `char_class_type` is used to represent a character
7087
+ classification and is capable of holding an implementation specific set
7088
+ returned by `lookup_classname`.
7089
+
7090
+ ``` cpp
7091
+ static size_t length(const char_type* p);
7092
+ ```
7093
+
7094
+ *Returns:* `char_traits<charT>::length(p)`.
7095
+
7096
+ ``` cpp
7097
+ charT translate(charT c) const;
7098
+ ```
7099
+
7100
+ *Returns:* `c`.
7101
+
7102
+ ``` cpp
7103
+ charT translate_nocase(charT c) const;
7104
+ ```
7105
+
7106
+ *Returns:* `use_facet<ctype<charT>>(getloc()).tolower(c)`.
7107
+
7108
+ ``` cpp
7109
+ template<class ForwardIterator>
7110
+ string_type transform(ForwardIterator first, ForwardIterator last) const;
7111
+ ```
7112
+
7113
+ *Effects:* As if by:
7114
+
7115
+ ``` cpp
7116
+ string_type str(first, last);
7117
+ return use_facet<collate<charT>>(
7118
+ getloc()).transform(str.data(), str.data() + str.length());
7119
+ ```
7120
+
7121
+ ``` cpp
7122
+ template<class ForwardIterator>
7123
+ string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
7124
+ ```
7125
+
7126
+ *Effects:* If
7127
+
7128
+ ``` cpp
7129
+ typeid(use_facet<collate<charT>>(getloc())) == typeid(collate_byname<charT>)
7130
+ ```
7131
+
7132
+ and the form of the sort key returned by
7133
+ `collate_byname<charT>::transform(first, last)` is known and can be
7134
+ converted into a primary sort key then returns that key, otherwise
7135
+ returns an empty string.
7136
+
7137
+ ``` cpp
7138
+ template<class ForwardIterator>
7139
+ string_type lookup_collatename(ForwardIterator first, ForwardIterator last) const;
7140
+ ```
7141
+
7142
+ *Returns:* A sequence of one or more characters that represents the
7143
+ collating element consisting of the character sequence designated by the
7144
+ iterator range \[`first`, `last`). Returns an empty string if the
7145
+ character sequence is not a valid collating element.
7146
+
7147
+ ``` cpp
7148
+ template<class ForwardIterator>
7149
+ char_class_type lookup_classname(
7150
+ ForwardIterator first, ForwardIterator last, bool icase = false) const;
7151
+ ```
7152
+
7153
+ *Returns:* An unspecified value that represents the character
7154
+ classification named by the character sequence designated by the
7155
+ iterator range \[`first`, `last`). If the parameter `icase` is `true`
7156
+ then the returned mask identifies the character classification without
7157
+ regard to the case of the characters being matched, otherwise it does
7158
+ honor the case of the characters being matched.[^26]
7159
+
7160
+ The value returned shall be independent of the case of the characters in
7161
+ the character sequence. If the name is not recognized then returns
7162
+ `char_class_type()`.
7163
+
7164
+ *Remarks:* For `regex_traits<char>`, at least the narrow character names
7165
+ in [[re.traits.classnames]] shall be recognized. For
7166
+ `regex_traits<wchar_t>`, at least the wide character names in
7167
+ [[re.traits.classnames]] shall be recognized.
7168
+
7169
+ ``` cpp
7170
+ bool isctype(charT c, char_class_type f) const;
7171
+ ```
7172
+
7173
+ *Effects:* Determines if the character `c` is a member of the character
7174
+ classification represented by `f`.
7175
+
7176
+ *Returns:* Given the following function declaration:
7177
+
7178
+ ``` cpp
7179
+ // for exposition only
7180
+ template<class C>
7181
+ ctype_base::mask convert(typename regex_traits<C>::char_class_type f);
7182
+ ```
7183
+
7184
+ that returns a value in which each `ctype_base::mask` value
7185
+ corresponding to a value in `f` named in [[re.traits.classnames]] is
7186
+ set, then the result is determined as if by:
7187
+
7188
+ ``` cpp
7189
+ ctype_base::mask m = convert<charT>(f);
7190
+ const ctype<charT>& ct = use_facet<ctype<charT>>(getloc());
7191
+ if (ct.is(m, c)) {
7192
+ return true;
7193
+ } else if (c == ct.widen('_')) {
7194
+ charT w[1] = { ct.widen('w') };
7195
+ char_class_type x = lookup_classname(w, w+1);
7196
+ return (f&x) == x;
7197
+ } else {
7198
+ return false;
7199
+ }
7200
+ ```
7201
+
7202
+ [*Example 1*:
7203
+
7204
+ ``` cpp
7205
+ regex_traits<char> t;
7206
+ string d("d");
7207
+ string u("upper");
7208
+ regex_traits<char>::char_class_type f;
7209
+ f = t.lookup_classname(d.begin(), d.end());
7210
+ f |= t.lookup_classname(u.begin(), u.end());
7211
+ ctype_base::mask m = convert<char>(f); // m == ctype_base::digit | ctype_base::upper
7212
+ ```
7213
+
7214
+ — *end example*]
7215
+
7216
+ [*Example 2*:
7217
+
7218
+ ``` cpp
7219
+ regex_traits<char> t;
7220
+ string w("w");
7221
+ regex_traits<char>::char_class_type f;
7222
+ f = t.lookup_classname(w.begin(), w.end());
7223
+ t.isctype('A', f); // returns true
7224
+ t.isctype('_', f); // returns true
7225
+ t.isctype(' ', f); // returns false
7226
+ ```
7227
+
7228
+ — *end example*]
7229
+
7230
+ ``` cpp
7231
+ int value(charT ch, int radix) const;
7232
+ ```
7233
+
7234
+ *Preconditions:* The value of `radix` is 8, 10, or 16.
7235
+
7236
+ *Returns:* The value represented by the digit `ch` in base `radix` if
7237
+ the character `ch` is a valid digit in base `radix`; otherwise returns
7238
+ `-1`.
7239
+
7240
+ ``` cpp
7241
+ locale_type imbue(locale_type loc);
7242
+ ```
7243
+
7244
+ *Effects:* Imbues `*this` with a copy of the locale `loc`.
7245
+
7246
+ [*Note 1*: Calling `imbue` with a different locale than the one
7247
+ currently in use invalidates all cached data held by
7248
+ `*this`. — *end note*]
7249
+
7250
+ *Ensures:* `getloc() == loc`.
7251
+
7252
+ *Returns:* If no locale has been previously imbued then a copy of the
7253
+ global locale in effect at the time of construction of `*this`,
7254
+ otherwise a copy of the last argument passed to `imbue`.
7255
+
7256
+ ``` cpp
7257
+ locale_type getloc() const;
7258
+ ```
7259
+
7260
+ *Returns:* If no locale has been imbued then a copy of the global locale
7261
+ in effect at the time of construction of `*this`, otherwise a copy of
7262
+ the last argument passed to `imbue`.
7263
+
7264
+ **Table: Character class names and corresponding `ctype` masks** <a id="re.traits.classnames">[re.traits.classnames]</a>
7265
+
7266
+ | Narrow character name | Wide character name | Corresponding `ctype_base::mask` value |
7267
+ | --------------------- | ------------------- | -------------------------------------- |
7268
+ | `"alnum"` | `L"alnum"` | `ctype_base::alnum` |
7269
+ | `"alpha"` | `L"alpha"` | `ctype_base::alpha` |
7270
+ | `"blank"` | `L"blank"` | `ctype_base::blank` |
7271
+ | `"cntrl"` | `L"cntrl"` | `ctype_base::cntrl` |
7272
+ | `"digit"` | `L"digit"` | `ctype_base::digit` |
7273
+ | `"d"` | `L"d"` | `ctype_base::digit` |
7274
+ | `"graph"` | `L"graph"` | `ctype_base::graph` |
7275
+ | `"lower"` | `L"lower"` | `ctype_base::lower` |
7276
+ | `"print"` | `L"print"` | `ctype_base::print` |
7277
+ | `"punct"` | `L"punct"` | `ctype_base::punct` |
7278
+ | `"space"` | `L"space"` | `ctype_base::space` |
7279
+ | `"s"` | `L"s"` | `ctype_base::space` |
7280
+ | `"upper"` | `L"upper"` | `ctype_base::upper` |
7281
+ | `"w"` | `L"w"` | `ctype_base::alnum` |
7282
+ | `"xdigit"` | `L"xdigit"` | `ctype_base::xdigit` |
7283
+
7284
+
7285
+ ### Class template `basic_regex` <a id="re.regex">[[re.regex]]</a>
7286
+
7287
+ #### General <a id="re.regex.general">[[re.regex.general]]</a>
7288
+
7289
+ For a char-like type `charT`, specializations of class template
7290
+ `basic_regex` represent regular expressions constructed from character
7291
+ sequences of `charT` characters. In the rest of  [[re.regex]], `charT`
7292
+ denotes a given char-like type. Storage for a regular expression is
7293
+ allocated and freed as necessary by the member functions of class
7294
+ `basic_regex`.
7295
+
7296
+ Objects of type specialization of `basic_regex` are responsible for
7297
+ converting the sequence of `charT` objects to an internal
7298
+ representation. It is not specified what form this representation takes,
7299
+ nor how it is accessed by algorithms that operate on regular
7300
+ expressions.
7301
+
7302
+ [*Note 1*: Implementations will typically declare some function
7303
+ templates as friends of `basic_regex` to achieve this. — *end note*]
7304
+
7305
+ The functions described in [[re.regex]] report errors by throwing
7306
+ exceptions of type `regex_error`.
7307
+
7308
+ ``` cpp
7309
+ namespace std {
7310
+ template<class charT, class traits = regex_traits<charT>>
7311
+ class basic_regex {
7312
+ public:
7313
+ // types
7314
+ using value_type = charT;
7315
+ using traits_type = traits;
7316
+ using string_type = traits::string_type;
7317
+ using flag_type = regex_constants::syntax_option_type;
7318
+ using locale_type = traits::locale_type;
7319
+
7320
+ // [re.synopt], constants
7321
+ static constexpr flag_type icase = regex_constants::icase;
7322
+ static constexpr flag_type nosubs = regex_constants::nosubs;
7323
+ static constexpr flag_type optimize = regex_constants::optimize;
7324
+ static constexpr flag_type collate = regex_constants::collate;
7325
+ static constexpr flag_type ECMAScript = regex_constants::ECMAScript;
7326
+ static constexpr flag_type basic = regex_constants::basic;
7327
+ static constexpr flag_type extended = regex_constants::extended;
7328
+ static constexpr flag_type awk = regex_constants::awk;
7329
+ static constexpr flag_type grep = regex_constants::grep;
7330
+ static constexpr flag_type egrep = regex_constants::egrep;
7331
+ static constexpr flag_type multiline = regex_constants::multiline;
7332
+
7333
+ // [re.regex.construct], construct/copy/destroy
7334
+ basic_regex();
7335
+ explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
7336
+ basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
7337
+ basic_regex(const basic_regex&);
7338
+ basic_regex(basic_regex&&) noexcept;
7339
+ template<class ST, class SA>
7340
+ explicit basic_regex(const basic_string<charT, ST, SA>& s,
7341
+ flag_type f = regex_constants::ECMAScript);
7342
+ template<class ForwardIterator>
7343
+ basic_regex(ForwardIterator first, ForwardIterator last,
7344
+ flag_type f = regex_constants::ECMAScript);
7345
+ basic_regex(initializer_list<charT> il, flag_type f = regex_constants::ECMAScript);
7346
+
7347
+ ~basic_regex();
7348
+
7349
+ // [re.regex.assign], assign
7350
+ basic_regex& operator=(const basic_regex& e);
7351
+ basic_regex& operator=(basic_regex&& e) noexcept;
7352
+ basic_regex& operator=(const charT* p);
7353
+ basic_regex& operator=(initializer_list<charT> il);
7354
+ template<class ST, class SA>
7355
+ basic_regex& operator=(const basic_string<charT, ST, SA>& s);
7356
+
7357
+ basic_regex& assign(const basic_regex& e);
7358
+ basic_regex& assign(basic_regex&& e) noexcept;
7359
+ basic_regex& assign(const charT* p, flag_type f = regex_constants::ECMAScript);
7360
+ basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
7361
+ template<class ST, class SA>
7362
+ basic_regex& assign(const basic_string<charT, ST, SA>& s,
7363
+ flag_type f = regex_constants::ECMAScript);
7364
+ template<class InputIterator>
7365
+ basic_regex& assign(InputIterator first, InputIterator last,
7366
+ flag_type f = regex_constants::ECMAScript);
7367
+ basic_regex& assign(initializer_list<charT>,
7368
+ flag_type f = regex_constants::ECMAScript);
7369
+
7370
+ // [re.regex.operations], const operations
7371
+ unsigned mark_count() const;
7372
+ flag_type flags() const;
7373
+
7374
+ // [re.regex.locale], locale
7375
+ locale_type imbue(locale_type loc);
7376
+ locale_type getloc() const;
7377
+
7378
+ // [re.regex.swap], swap
7379
+ void swap(basic_regex&);
7380
+ };
7381
+
7382
+ template<class ForwardIterator>
7383
+ basic_regex(ForwardIterator, ForwardIterator,
7384
+ regex_constants::syntax_option_type = regex_constants::ECMAScript)
7385
+ -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>;
7386
+ }
7387
+ ```
7388
+
7389
+ #### Constructors <a id="re.regex.construct">[[re.regex.construct]]</a>
7390
+
7391
+ ``` cpp
7392
+ basic_regex();
7393
+ ```
7394
+
7395
+ *Ensures:* `*this` does not match any character sequence.
7396
+
7397
+ ``` cpp
7398
+ explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
7399
+ ```
7400
+
7401
+ *Preconditions:* \[`p`, `p + char_traits<charT>::length(p)`) is a valid
7402
+ range.
7403
+
7404
+ *Effects:* The object’s internal finite state machine is constructed
7405
+ from the regular expression contained in the sequence of characters
7406
+ \[`p`, `p + char_traits<charT>::length(p)`), and interpreted according
7407
+ to the flags `f`.
7408
+
7409
+ *Ensures:* `flags()` returns `f`. `mark_count()` returns the number of
7410
+ marked sub-expressions within the expression.
7411
+
7412
+ *Throws:* `regex_error` if \[`p`, `p + char_traits<charT>::length(p)`)
7413
+ is not a valid regular expression.
7414
+
7415
+ ``` cpp
7416
+ basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
7417
+ ```
7418
+
7419
+ *Preconditions:* \[`p`, `p + len`) is a valid range.
7420
+
7421
+ *Effects:* The object’s internal finite state machine is constructed
7422
+ from the regular expression contained in the sequence of characters
7423
+ \[`p`, `p + len`), and interpreted according the flags specified in `f`.
7424
+
7425
+ *Ensures:* `flags()` returns `f`. `mark_count()` returns the number of
7426
+ marked sub-expressions within the expression.
7427
+
7428
+ *Throws:* `regex_error` if \[`p`, `p + len`) is not a valid regular
7429
+ expression.
7430
+
7431
+ ``` cpp
7432
+ basic_regex(const basic_regex& e);
7433
+ ```
7434
+
7435
+ *Ensures:* `flags()` and `mark_count()` return `e.flags()` and
7436
+ `e.mark_count()`, respectively.
7437
+
7438
+ ``` cpp
7439
+ basic_regex(basic_regex&& e) noexcept;
7440
+ ```
7441
+
7442
+ *Ensures:* `flags()` and `mark_count()` return the values that
7443
+ `e.flags()` and `e.mark_count()`, respectively, had before construction.
7444
+
7445
+ ``` cpp
7446
+ template<class ST, class SA>
7447
+ explicit basic_regex(const basic_string<charT, ST, SA>& s,
7448
+ flag_type f = regex_constants::ECMAScript);
7449
+ ```
7450
+
7451
+ *Effects:* The object’s internal finite state machine is constructed
7452
+ from the regular expression contained in the string `s`, and interpreted
7453
+ according to the flags specified in `f`.
7454
+
7455
+ *Ensures:* `flags()` returns `f`. `mark_count()` returns the number of
7456
+ marked sub-expressions within the expression.
7457
+
7458
+ *Throws:* `regex_error` if `s` is not a valid regular expression.
7459
+
7460
+ ``` cpp
7461
+ template<class ForwardIterator>
7462
+ basic_regex(ForwardIterator first, ForwardIterator last,
7463
+ flag_type f = regex_constants::ECMAScript);
7464
+ ```
7465
+
7466
+ *Effects:* The object’s internal finite state machine is constructed
7467
+ from the regular expression contained in the sequence of characters
7468
+ \[`first`, `last`), and interpreted according to the flags specified in
7469
+ `f`.
7470
+
7471
+ *Ensures:* `flags()` returns `f`. `mark_count()` returns the number of
7472
+ marked sub-expressions within the expression.
7473
+
7474
+ *Throws:* `regex_error` if the sequence \[`first`, `last`) is not a
7475
+ valid regular expression.
7476
+
7477
+ ``` cpp
7478
+ basic_regex(initializer_list<charT> il, flag_type f = regex_constants::ECMAScript);
7479
+ ```
7480
+
7481
+ *Effects:* Same as `basic_regex(il.begin(), il.end(), f)`.
7482
+
7483
+ #### Assignment <a id="re.regex.assign">[[re.regex.assign]]</a>
7484
+
7485
+ ``` cpp
7486
+ basic_regex& operator=(const basic_regex& e);
7487
+ ```
7488
+
7489
+ *Ensures:* `flags()` and `mark_count()` return `e.flags()` and
7490
+ `e.mark_count()`, respectively.
7491
+
7492
+ ``` cpp
7493
+ basic_regex& operator=(basic_regex&& e) noexcept;
7494
+ ```
7495
+
7496
+ *Ensures:* `flags()` and `mark_count()` return the values that
7497
+ `e.flags()` and `e.mark_count()`, respectively, had before assignment.
7498
+ `e` is in a valid state with unspecified value.
7499
+
7500
+ ``` cpp
7501
+ basic_regex& operator=(const charT* p);
7502
+ ```
7503
+
7504
+ *Effects:* Equivalent to: `return assign(p);`
7505
+
7506
+ ``` cpp
7507
+ basic_regex& operator=(initializer_list<charT> il);
7508
+ ```
7509
+
7510
+ *Effects:* Equivalent to: `return assign(il.begin(), il.end());`
7511
+
7512
+ ``` cpp
7513
+ template<class ST, class SA>
7514
+ basic_regex& operator=(const basic_string<charT, ST, SA>& s);
7515
+ ```
7516
+
7517
+ *Effects:* Equivalent to: `return assign(s);`
7518
+
7519
+ ``` cpp
7520
+ basic_regex& assign(const basic_regex& e);
7521
+ ```
7522
+
7523
+ *Effects:* Equivalent to: `return *this = e;`
7524
+
7525
+ ``` cpp
7526
+ basic_regex& assign(basic_regex&& e) noexcept;
7527
+ ```
7528
+
7529
+ *Effects:* Equivalent to: `return *this = std::move(e);`
7530
+
7531
+ ``` cpp
7532
+ basic_regex& assign(const charT* p, flag_type f = regex_constants::ECMAScript);
7533
+ ```
7534
+
7535
+ *Effects:* Equivalent to: `return assign(string_type(p), f);`
7536
+
7537
+ ``` cpp
7538
+ basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
7539
+ ```
7540
+
7541
+ *Effects:* Equivalent to: `return assign(string_type(p, len), f);`
7542
+
7543
+ ``` cpp
7544
+ template<class ST, class SA>
7545
+ basic_regex& assign(const basic_string<charT, ST, SA>& s,
7546
+ flag_type f = regex_constants::ECMAScript);
7547
+ ```
7548
+
7549
+ *Effects:* Assigns the regular expression contained in the string `s`,
7550
+ interpreted according the flags specified in `f`. If an exception is
7551
+ thrown, `*this` is unchanged.
7552
+
7553
+ *Ensures:* If no exception is thrown, `flags()` returns `f` and
7554
+ `mark_count()` returns the number of marked sub-expressions within the
7555
+ expression.
7556
+
7557
+ *Returns:* `*this`.
7558
+
7559
+ *Throws:* `regex_error` if `s` is not a valid regular expression.
7560
+
7561
+ ``` cpp
7562
+ template<class InputIterator>
7563
+ basic_regex& assign(InputIterator first, InputIterator last,
7564
+ flag_type f = regex_constants::ECMAScript);
7565
+ ```
7566
+
7567
+ *Effects:* Equivalent to: `return assign(string_type(first, last), f);`
7568
+
7569
+ ``` cpp
7570
+ basic_regex& assign(initializer_list<charT> il,
7571
+ flag_type f = regex_constants::ECMAScript);
7572
+ ```
7573
+
7574
+ *Effects:* Equivalent to: `return assign(il.begin(), il.end(), f);`
7575
+
7576
+ #### Constant operations <a id="re.regex.operations">[[re.regex.operations]]</a>
7577
+
7578
+ ``` cpp
7579
+ unsigned mark_count() const;
7580
+ ```
7581
+
7582
+ *Effects:* Returns the number of marked sub-expressions within the
7583
+ regular expression.
7584
+
7585
+ ``` cpp
7586
+ flag_type flags() const;
7587
+ ```
7588
+
7589
+ *Effects:* Returns a copy of the regular expression syntax flags that
7590
+ were passed to the object’s constructor or to the last call to `assign`.
7591
+
7592
+ #### Locale <a id="re.regex.locale">[[re.regex.locale]]</a>
7593
+
7594
+ ``` cpp
7595
+ locale_type imbue(locale_type loc);
7596
+ ```
7597
+
7598
+ *Effects:* Returns the result of `traits_inst.imbue(loc)` where
7599
+ `traits_inst` is a (default-initialized) instance of the template type
7600
+ argument `traits` stored within the object. After a call to `imbue` the
7601
+ `basic_regex` object does not match any character sequence.
7602
+
7603
+ ``` cpp
7604
+ locale_type getloc() const;
7605
+ ```
7606
+
7607
+ *Effects:* Returns the result of `traits_inst.getloc()` where
7608
+ `traits_inst` is a (default-initialized) instance of the template
7609
+ parameter `traits` stored within the object.
7610
+
7611
+ #### Swap <a id="re.regex.swap">[[re.regex.swap]]</a>
7612
+
7613
+ ``` cpp
7614
+ void swap(basic_regex& e);
7615
+ ```
7616
+
7617
+ *Effects:* Swaps the contents of the two regular expressions.
7618
+
7619
+ *Ensures:* `*this` contains the regular expression that was in `e`, `e`
7620
+ contains the regular expression that was in `*this`.
7621
+
7622
+ *Complexity:* Constant time.
7623
+
7624
+ #### Non-member functions <a id="re.regex.nonmemb">[[re.regex.nonmemb]]</a>
7625
+
7626
+ ``` cpp
7627
+ template<class charT, class traits>
7628
+ void swap(basic_regex<charT, traits>& lhs, basic_regex<charT, traits>& rhs);
7629
+ ```
7630
+
7631
+ *Effects:* Calls `lhs.swap(rhs)`.
7632
+
7633
+ ### Class template `sub_match` <a id="re.submatch">[[re.submatch]]</a>
7634
+
7635
+ #### General <a id="re.submatch.general">[[re.submatch.general]]</a>
7636
+
7637
+ Class template `sub_match` denotes the sequence of characters matched by
7638
+ a particular marked sub-expression.
7639
+
7640
+ ``` cpp
7641
+ namespace std {
7642
+ template<class BidirectionalIterator>
7643
+ class sub_match : public pair<BidirectionalIterator, BidirectionalIterator> {
7644
+ public:
7645
+ using value_type = iterator_traits<BidirectionalIterator>::value_type;
7646
+ using difference_type = iterator_traits<BidirectionalIterator>::difference_type;
7647
+ using iterator = BidirectionalIterator;
7648
+ using string_type = basic_string<value_type>;
7649
+
7650
+ bool matched;
7651
+
7652
+ constexpr sub_match();
7653
+
7654
+ difference_type length() const;
7655
+ operator string_type() const;
7656
+ string_type str() const;
7657
+
7658
+ int compare(const sub_match& s) const;
7659
+ int compare(const string_type& s) const;
7660
+ int compare(const value_type* s) const;
7661
+
7662
+ void swap(sub_match& s) noexcept(see below);
7663
+ };
7664
+ }
7665
+ ```
7666
+
7667
+ #### Members <a id="re.submatch.members">[[re.submatch.members]]</a>
7668
+
7669
+ ``` cpp
7670
+ constexpr sub_match();
7671
+ ```
7672
+
7673
+ *Effects:* Value-initializes the `pair` base class subobject and the
7674
+ member `matched`.
7675
+
7676
+ ``` cpp
7677
+ difference_type length() const;
7678
+ ```
7679
+
7680
+ *Returns:* `matched ? distance(first, second) : 0`.
7681
+
7682
+ ``` cpp
7683
+ operator string_type() const;
7684
+ ```
7685
+
7686
+ *Returns:* `matched ? string_type(first, second) : string_type()`.
7687
+
7688
+ ``` cpp
7689
+ string_type str() const;
7690
+ ```
7691
+
7692
+ *Returns:* `matched ? string_type(first, second) : string_type()`.
7693
+
7694
+ ``` cpp
7695
+ int compare(const sub_match& s) const;
7696
+ ```
7697
+
7698
+ *Returns:* `str().compare(s.str())`.
7699
+
7700
+ ``` cpp
7701
+ int compare(const string_type& s) const;
7702
+ ```
7703
+
7704
+ *Returns:* `str().compare(s)`.
7705
+
7706
+ ``` cpp
7707
+ int compare(const value_type* s) const;
7708
+ ```
7709
+
7710
+ *Returns:* `str().compare(s)`.
7711
+
7712
+ ``` cpp
7713
+ void swap(sub_match& s) noexcept(see below);
7714
+ ```
7715
+
7716
+ *Preconditions:* `BidirectionalIterator` meets the *Cpp17Swappable*
7717
+ requirements [[swappable.requirements]].
7718
+
7719
+ *Effects:* Equivalent to:
7720
+
7721
+ ``` cpp
7722
+ this->pair<BidirectionalIterator, BidirectionalIterator>::swap(s);
7723
+ std::swap(matched, s.matched);
7724
+ ```
7725
+
7726
+ *Remarks:* The exception specification is equivalent to
7727
+ `is_nothrow_swappable_v<BidirectionalIterator>`.
7728
+
7729
+ #### Non-member operators <a id="re.submatch.op">[[re.submatch.op]]</a>
7730
+
7731
+ Let `SM-CAT(I)` be
7732
+
7733
+ ``` cpp
7734
+ compare_three_way_result_t<basic_string<typename iterator_traits<I>::value_type>>
7735
+ ```
7736
+
7737
+ ``` cpp
7738
+ template<class BiIter>
7739
+ bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
7740
+ ```
7741
+
7742
+ *Returns:* `lhs.compare(rhs) == 0`.
7743
+
7744
+ ``` cpp
7745
+ template<class BiIter>
7746
+ auto operator<=>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
7747
+ ```
7748
+
7749
+ *Returns:* `static_cast<`*`SM-CAT`*`(BiIter)>(lhs.compare(rhs) <=> 0)`.
7750
+
7751
+ ``` cpp
7752
+ template<class BiIter, class ST, class SA>
7753
+ bool operator==(
7754
+ const sub_match<BiIter>& lhs,
7755
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
7756
+ ```
7757
+
7758
+ *Returns:*
7759
+
7760
+ ``` cpp
7761
+ lhs.compare(typename sub_match<BiIter>::string_type(rhs.data(), rhs.size())) == 0
7762
+ ```
7763
+
7764
+ ``` cpp
7765
+ template<class BiIter, class ST, class SA>
7766
+ auto operator<=>(
7767
+ const sub_match<BiIter>& lhs,
7768
+ const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
7769
+ ```
7770
+
7771
+ *Returns:*
7772
+
7773
+ ``` cpp
7774
+ static_cast<SM-CAT(BiIter)>(lhs.compare(
7775
+ typename sub_match<BiIter>::string_type(rhs.data(), rhs.size()))
7776
+ <=> 0
7777
+ )
7778
+ ```
7779
+
7780
+ ``` cpp
7781
+ template<class BiIter>
7782
+ bool operator==(const sub_match<BiIter>& lhs,
7783
+ const typename iterator_traits<BiIter>::value_type* rhs);
7784
+ ```
7785
+
7786
+ *Returns:* `lhs.compare(rhs) == 0`.
7787
+
7788
+ ``` cpp
7789
+ template<class BiIter>
7790
+ auto operator<=>(const sub_match<BiIter>& lhs,
7791
+ const typename iterator_traits<BiIter>::value_type* rhs);
7792
+ ```
7793
+
7794
+ *Returns:* `static_cast<`*`SM-CAT`*`(BiIter)>(lhs.compare(rhs) <=> 0)`.
7795
+
7796
+ ``` cpp
7797
+ template<class BiIter>
7798
+ bool operator==(const sub_match<BiIter>& lhs,
7799
+ const typename iterator_traits<BiIter>::value_type& rhs);
7800
+ ```
7801
+
7802
+ *Returns:*
7803
+ `lhs.compare(typename sub_match<BiIter>::string_type(1, rhs)) == 0`.
7804
+
7805
+ ``` cpp
7806
+ template<class BiIter>
7807
+ auto operator<=>(const sub_match<BiIter>& lhs,
7808
+ const typename iterator_traits<BiIter>::value_type& rhs);
7809
+ ```
7810
+
7811
+ *Returns:*
7812
+
7813
+ ``` cpp
7814
+ static_cast<SM-CAT(BiIter)>(lhs.compare(
7815
+ typename sub_match<BiIter>::string_type(1, rhs))
7816
+ <=> 0
7817
+ )
7818
+ ```
7819
+
7820
+ ``` cpp
7821
+ template<class charT, class ST, class BiIter>
7822
+ basic_ostream<charT, ST>&
7823
+ operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
7824
+ ```
7825
+
7826
+ *Returns:* `os << m.str()`.
7827
+
7828
+ ### Class template `match_results` <a id="re.results">[[re.results]]</a>
7829
+
7830
+ #### General <a id="re.results.general">[[re.results.general]]</a>
7831
+
7832
+ Class template `match_results` denotes a collection of character
7833
+ sequences representing the result of a regular expression match. Storage
7834
+ for the collection is allocated and freed as necessary by the member
7835
+ functions of class template `match_results`.
7836
+
7837
+ The class template `match_results` meets the requirements of an
7838
+ allocator-aware container [[container.alloc.reqmts]] and of a sequence
7839
+ container [[container.requirements.general]], [[sequence.reqmts]] except
7840
+ that only copy assignment, move assignment, and operations defined for
7841
+ const-qualified sequence containers are supported and that the semantics
7842
+ of the comparison operator functions are different from those required
7843
+ for a container.
7844
+
7845
+ A default-constructed `match_results` object has no fully established
7846
+ result state. A match result is *ready* when, as a consequence of a
7847
+ completed regular expression match modifying such an object, its result
7848
+ state becomes fully established. The effects of calling most member
7849
+ functions from a `match_results` object that is not ready are undefined.
7850
+
7851
+ The `sub_match` object stored at index 0 represents sub-expression 0,
7852
+ i.e., the whole match. In this case the `sub_match` member `matched` is
7853
+ always `true`. The `sub_match` object stored at index `n` denotes what
7854
+ matched the marked sub-expression `n` within the matched expression. If
7855
+ the sub-expression `n` participated in a regular expression match then
7856
+ the `sub_match` member `matched` evaluates to `true`, and members
7857
+ `first` and `second` denote the range of characters \[`first`, `second`)
7858
+ which formed that match. Otherwise `matched` is `false`, and members
7859
+ `first` and `second` point to the end of the sequence that was searched.
7860
+
7861
+ [*Note 1*: The `sub_match` objects representing different
7862
+ sub-expressions that did not participate in a regular expression match
7863
+ need not be distinct. — *end note*]
7864
+
7865
+ ``` cpp
7866
+ namespace std {
7867
+ template<class BidirectionalIterator,
7868
+ class Allocator = allocator<sub_match<BidirectionalIterator>>>
7869
+ class match_results {
7870
+ public:
7871
+ using value_type = sub_match<BidirectionalIterator>;
7872
+ using const_reference = const value_type&;
7873
+ using reference = value_type&;
7874
+ using const_iterator = implementation-defined // type of match_results::const_iterator;
7875
+ using iterator = const_iterator;
7876
+ using difference_type = iterator_traits<BidirectionalIterator>::difference_type;
7877
+ using size_type = allocator_traits<Allocator>::size_type;
7878
+ using allocator_type = Allocator;
7879
+ using char_type = iterator_traits<BidirectionalIterator>::value_type;
7880
+ using string_type = basic_string<char_type>;
7881
+
7882
+ // [re.results.const], construct/copy/destroy
7883
+ match_results() : match_results(Allocator()) {}
7884
+ explicit match_results(const Allocator& a);
7885
+ match_results(const match_results& m);
7886
+ match_results(const match_results& m, const Allocator& a);
7887
+ match_results(match_results&& m) noexcept;
7888
+ match_results(match_results&& m, const Allocator& a);
7889
+ match_results& operator=(const match_results& m);
7890
+ match_results& operator=(match_results&& m);
7891
+ ~match_results();
7892
+
7893
+ // [re.results.state], state
7894
+ bool ready() const;
7895
+
7896
+ // [re.results.size], size
7897
+ size_type size() const;
7898
+ size_type max_size() const;
7899
+ bool empty() const;
7900
+
7901
+ // [re.results.acc], element access
7902
+ difference_type length(size_type sub = 0) const;
7903
+ difference_type position(size_type sub = 0) const;
7904
+ string_type str(size_type sub = 0) const;
7905
+ const_reference operator[](size_type n) const;
7906
+
7907
+ const_reference prefix() const;
7908
+ const_reference suffix() const;
7909
+ const_iterator begin() const;
7910
+ const_iterator end() const;
7911
+ const_iterator cbegin() const;
7912
+ const_iterator cend() const;
7913
+
7914
+ // [re.results.form], format
7915
+ template<class OutputIter>
7916
+ OutputIter
7917
+ format(OutputIter out,
7918
+ const char_type* fmt_first, const char_type* fmt_last,
7919
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
7920
+ template<class OutputIter, class ST, class SA>
7921
+ OutputIter
7922
+ format(OutputIter out,
7923
+ const basic_string<char_type, ST, SA>& fmt,
7924
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
7925
+ template<class ST, class SA>
7926
+ basic_string<char_type, ST, SA>
7927
+ format(const basic_string<char_type, ST, SA>& fmt,
7928
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
7929
+ string_type
7930
+ format(const char_type* fmt,
7931
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
7932
+
7933
+ // [re.results.all], allocator
7934
+ allocator_type get_allocator() const;
7935
+
7936
+ // [re.results.swap], swap
7937
+ void swap(match_results& that);
7938
+ };
7939
+ }
7940
+ ```
7941
+
7942
+ #### Constructors <a id="re.results.const">[[re.results.const]]</a>
7943
+
7944
+ [[re.results.const]] lists the postconditions of `match_results`
7945
+ copy/move constructors and copy/move assignment operators. For move
7946
+ operations, the results of the expressions depending on the parameter
7947
+ `m` denote the values they had before the respective function calls.
7948
+
7949
+ ``` cpp
7950
+ explicit match_results(const Allocator& a);
7951
+ ```
7952
+
7953
+ *Effects:* The stored `Allocator` value is constructed from `a`.
7954
+
7955
+ *Ensures:* `ready()` returns `false`. `size()` returns `0`.
7956
+
7957
+ ``` cpp
7958
+ match_results(const match_results& m);
7959
+ match_results(const match_results& m, const Allocator& a);
7960
+ ```
7961
+
7962
+ *Effects:* For the first form, the stored `Allocator` value is obtained
7963
+ as specified in [[container.reqmts]]. For the second form, the stored
7964
+ `Allocator` value is constructed from `a`.
7965
+
7966
+ *Ensures:* As specified in [[re.results.const]].
7967
+
7968
+ ``` cpp
7969
+ match_results(match_results&& m) noexcept;
7970
+ match_results(match_results&& m, const Allocator& a);
7971
+ ```
7972
+
7973
+ *Effects:* For the first form, the stored `Allocator` value is move
7974
+ constructed from `m.get_allocator()`. For the second form, the stored
7975
+ `Allocator` value is constructed from `a`.
7976
+
7977
+ *Ensures:* As specified in [[re.results.const]].
7978
+
7979
+ *Throws:* The second form throws nothing if `a == m.get_allocator()` is
7980
+ `true`.
7981
+
7982
+ ``` cpp
7983
+ match_results& operator=(const match_results& m);
7984
+ ```
7985
+
7986
+ *Ensures:* As specified in [[re.results.const]].
7987
+
7988
+ ``` cpp
7989
+ match_results& operator=(match_results&& m);
7990
+ ```
7991
+
7992
+ *Ensures:* As specified in [[re.results.const]].
7993
+
7994
+ **Table: `match_results` copy/move operation postconditions** <a id="re.results.const">[re.results.const]</a>
7995
+
7996
+ | Element | Value |
7997
+ | ------------- | ------------------------------------------------------------ |
7998
+ | `ready()` | `m.ready()` |
7999
+ | `size()` | `m.size()` |
8000
+ | `str(n)` | `m.str(n)` for all non-negative integers `n < m.size()` |
8001
+ | `prefix()` | `m.prefix()` |
8002
+ | `suffix()` | `m.suffix()` |
8003
+ | `(*this)[n]` | `m[n]` for all non-negative integers `n < m.size()` |
8004
+ | `length(n)` | `m.length(n)` for all non-negative integers `n < m.size()` |
8005
+ | `position(n)` | `m.position(n)` for all non-negative integers `n < m.size()` |
8006
+
8007
+
8008
+ #### State <a id="re.results.state">[[re.results.state]]</a>
8009
+
8010
+ ``` cpp
8011
+ bool ready() const;
8012
+ ```
8013
+
8014
+ *Returns:* `true` if `*this` has a fully established result state,
8015
+ otherwise `false`.
8016
+
8017
+ #### Size <a id="re.results.size">[[re.results.size]]</a>
8018
+
8019
+ ``` cpp
8020
+ size_type size() const;
8021
+ ```
8022
+
8023
+ *Returns:* One plus the number of marked sub-expressions in the regular
8024
+ expression that was matched if `*this` represents the result of a
8025
+ successful match. Otherwise returns `0`.
8026
+
8027
+ [*Note 1*: The state of a `match_results` object can be modified only
8028
+ by passing that object to `regex_match` or `regex_search`.
8029
+ Subclauses  [[re.alg.match]] and  [[re.alg.search]] specify the effects
8030
+ of those algorithms on their `match_results` arguments. — *end note*]
8031
+
8032
+ ``` cpp
8033
+ size_type max_size() const;
8034
+ ```
8035
+
8036
+ *Returns:* The maximum number of `sub_match` elements that can be stored
8037
+ in `*this`.
8038
+
8039
+ ``` cpp
8040
+ bool empty() const;
8041
+ ```
8042
+
8043
+ *Returns:* `size() == 0`.
8044
+
8045
+ #### Element access <a id="re.results.acc">[[re.results.acc]]</a>
8046
+
8047
+ ``` cpp
8048
+ difference_type length(size_type sub = 0) const;
8049
+ ```
8050
+
8051
+ *Preconditions:* `ready() == true`.
8052
+
8053
+ *Returns:* `(*this)[sub].length()`.
8054
+
8055
+ ``` cpp
8056
+ difference_type position(size_type sub = 0) const;
8057
+ ```
8058
+
8059
+ *Preconditions:* `ready() == true`.
8060
+
8061
+ *Returns:* The distance from the start of the target sequence to
8062
+ `(*this)[sub].first`.
8063
+
8064
+ ``` cpp
8065
+ string_type str(size_type sub = 0) const;
8066
+ ```
8067
+
8068
+ *Preconditions:* `ready() == true`.
8069
+
8070
+ *Returns:* `string_type((*this)[sub])`.
8071
+
8072
+ ``` cpp
8073
+ const_reference operator[](size_type n) const;
8074
+ ```
8075
+
8076
+ *Preconditions:* `ready() == true`.
8077
+
8078
+ *Returns:* A reference to the `sub_match` object representing the
8079
+ character sequence that matched marked sub-expression `n`. If `n == 0`
8080
+ then returns a reference to a `sub_match` object representing the
8081
+ character sequence that matched the whole regular expression. If
8082
+ `n >= size()` then returns a `sub_match` object representing an
8083
+ unmatched sub-expression.
8084
+
8085
+ ``` cpp
8086
+ const_reference prefix() const;
8087
+ ```
8088
+
8089
+ *Preconditions:* `ready() == true`.
8090
+
8091
+ *Returns:* A reference to the `sub_match` object representing the
8092
+ character sequence from the start of the string being matched/searched
8093
+ to the start of the match found.
8094
+
8095
+ ``` cpp
8096
+ const_reference suffix() const;
8097
+ ```
8098
+
8099
+ *Preconditions:* `ready() == true`.
8100
+
8101
+ *Returns:* A reference to the `sub_match` object representing the
8102
+ character sequence from the end of the match found to the end of the
8103
+ string being matched/searched.
8104
+
8105
+ ``` cpp
8106
+ const_iterator begin() const;
8107
+ const_iterator cbegin() const;
8108
+ ```
8109
+
8110
+ *Returns:* A starting iterator that enumerates over all the
8111
+ sub-expressions stored in `*this`.
8112
+
8113
+ ``` cpp
8114
+ const_iterator end() const;
8115
+ const_iterator cend() const;
8116
+ ```
8117
+
8118
+ *Returns:* A terminating iterator that enumerates over all the
8119
+ sub-expressions stored in `*this`.
8120
+
8121
+ #### Formatting <a id="re.results.form">[[re.results.form]]</a>
8122
+
8123
+ ``` cpp
8124
+ template<class OutputIter>
8125
+ OutputIter format(
8126
+ OutputIter out,
8127
+ const char_type* fmt_first, const char_type* fmt_last,
8128
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
8129
+ ```
8130
+
8131
+ *Preconditions:* `ready() == true` and `OutputIter` meets the
8132
+ requirements for a *Cpp17OutputIterator*[[output.iterators]].
8133
+
8134
+ *Effects:* Copies the character sequence \[`fmt_first`, `fmt_last`) to
8135
+ OutputIter `out`. Replaces each format specifier or escape sequence in
8136
+ the copied range with either the character(s) it represents or the
8137
+ sequence of characters within `*this` to which it refers. The bitmasks
8138
+ specified in `flags` determine which format specifiers and escape
8139
+ sequences are recognized.
8140
+
8141
+ *Returns:* `out`.
8142
+
8143
+ ``` cpp
8144
+ template<class OutputIter, class ST, class SA>
8145
+ OutputIter format(
8146
+ OutputIter out,
8147
+ const basic_string<char_type, ST, SA>& fmt,
8148
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
8149
+ ```
8150
+
8151
+ *Effects:* Equivalent to:
8152
+
8153
+ ``` cpp
8154
+ return format(out, fmt.data(), fmt.data() + fmt.size(), flags);
8155
+ ```
8156
+
8157
+ ``` cpp
8158
+ template<class ST, class SA>
8159
+ basic_string<char_type, ST, SA> format(
8160
+ const basic_string<char_type, ST, SA>& fmt,
8161
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
8162
+ ```
8163
+
8164
+ *Preconditions:* `ready() == true`.
8165
+
8166
+ *Effects:* Constructs an empty string `result` of type
8167
+ `basic_string<char_type, ST, SA>` and calls:
8168
+
8169
+ ``` cpp
8170
+ format(back_inserter(result), fmt, flags);
8171
+ ```
8172
+
8173
+ *Returns:* `result`.
8174
+
8175
+ ``` cpp
8176
+ string_type format(
8177
+ const char_type* fmt,
8178
+ regex_constants::match_flag_type flags = regex_constants::format_default) const;
8179
+ ```
8180
+
8181
+ *Preconditions:* `ready() == true`.
8182
+
8183
+ *Effects:* Constructs an empty string `result` of type `string_type` and
8184
+ calls:
8185
+
8186
+ ``` cpp
8187
+ format(back_inserter(result), fmt, fmt + char_traits<char_type>::length(fmt), flags);
8188
+ ```
8189
+
8190
+ *Returns:* `result`.
8191
+
8192
+ #### Allocator <a id="re.results.all">[[re.results.all]]</a>
8193
+
8194
+ ``` cpp
8195
+ allocator_type get_allocator() const;
8196
+ ```
8197
+
8198
+ *Returns:* A copy of the Allocator that was passed to the object’s
8199
+ constructor or, if that allocator has been replaced, a copy of the most
8200
+ recent replacement.
8201
+
8202
+ #### Swap <a id="re.results.swap">[[re.results.swap]]</a>
8203
+
8204
+ ``` cpp
8205
+ void swap(match_results& that);
8206
+ ```
8207
+
8208
+ *Effects:* Swaps the contents of the two sequences.
8209
+
8210
+ *Ensures:* `*this` contains the sequence of matched sub-expressions that
8211
+ were in `that`, `that` contains the sequence of matched sub-expressions
8212
+ that were in `*this`.
8213
+
8214
+ *Complexity:* Constant time.
8215
+
8216
+ ``` cpp
8217
+ template<class BidirectionalIterator, class Allocator>
8218
+ void swap(match_results<BidirectionalIterator, Allocator>& m1,
8219
+ match_results<BidirectionalIterator, Allocator>& m2);
8220
+ ```
8221
+
8222
+ *Effects:* As if by `m1.swap(m2)`.
8223
+
8224
+ #### Non-member functions <a id="re.results.nonmember">[[re.results.nonmember]]</a>
8225
+
8226
+ ``` cpp
8227
+ template<class BidirectionalIterator, class Allocator>
8228
+ bool operator==(const match_results<BidirectionalIterator, Allocator>& m1,
8229
+ const match_results<BidirectionalIterator, Allocator>& m2);
8230
+ ```
8231
+
8232
+ *Returns:* `true` if neither match result is ready, `false` if one match
8233
+ result is ready and the other is not. If both match results are ready,
8234
+ returns `true` only if
8235
+
8236
+ - `m1.empty() && m2.empty()`, or
8237
+ - `!m1.empty() && !m2.empty()`, and the following conditions are
8238
+ satisfied:
8239
+ - `m1.prefix() == m2.prefix()`,
8240
+ - `m1.size() == m2.size() && equal(m1.begin(), m1.end(), m2.begin())`,
8241
+ and
8242
+ - `m1.suffix() == m2.suffix()`.
8243
+
8244
+ [*Note 1*: The algorithm `equal` is defined in
8245
+ [[algorithms]]. — *end note*]
8246
+
8247
+ ### Regular expression algorithms <a id="re.alg">[[re.alg]]</a>
8248
+
8249
+ #### Exceptions <a id="re.except">[[re.except]]</a>
8250
+
8251
+ The algorithms described in subclause  [[re.alg]] may throw an exception
8252
+ of type `regex_error`. If such an exception `e` is thrown, `e.code()`
8253
+ shall return either `regex_constants::error_complexity` or
8254
+ `regex_constants::error_stack`.
8255
+
8256
+ #### `regex_match` <a id="re.alg.match">[[re.alg.match]]</a>
8257
+
8258
+ ``` cpp
8259
+ template<class BidirectionalIterator, class Allocator, class charT, class traits>
8260
+ bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
8261
+ match_results<BidirectionalIterator, Allocator>& m,
8262
+ const basic_regex<charT, traits>& e,
8263
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8264
+ ```
8265
+
8266
+ *Preconditions:* `BidirectionalIterator` models `bidirectional_iterator`
8267
+ [[iterator.concept.bidir]].
8268
+
8269
+ *Effects:* Determines whether there is a match between the regular
8270
+ expression `e`, and all of the character sequence \[`first`, `last`).
8271
+ The parameter `flags` is used to control how the expression is matched
8272
+ against the character sequence. When determining if there is a match,
8273
+ only potential matches that match the entire character sequence are
8274
+ considered. Returns `true` if such a match exists, `false` otherwise.
8275
+
8276
+ [*Example 1*:
8277
+
8278
+ ``` cpp
8279
+ std::regex re("Get|GetValue");
8280
+ std::cmatch m;
8281
+ regex_search("GetValue", m, re); // returns true, and m[0] contains "Get"
8282
+ regex_match ("GetValue", m, re); // returns true, and m[0] contains "GetValue"
8283
+ regex_search("GetValues", m, re); // returns true, and m[0] contains "Get"
8284
+ regex_match ("GetValues", m, re); // returns false
8285
+ ```
8286
+
8287
+ — *end example*]
8288
+
8289
+ *Ensures:* `m.ready() == true` in all cases. If the function returns
8290
+ `false`, then the effect on parameter `m` is unspecified except that
8291
+ `m.size()` returns `0` and `m.empty()` returns `true`. Otherwise the
8292
+ effects on parameter `m` are given in [[re.alg.match]].
8293
+
8294
+ **Table: Effects of `regex_match` algorithm** <a id="re.alg.match">[re.alg.match]</a>
8295
+
8296
+ | Element | Value |
8297
+ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
8298
+ | `m.size()` | `1 + e.mark_count()` |
8299
+ | `m.empty()` | `false` |
8300
+ | `m.prefix().first` | `first` |
8301
+ | `m.prefix().second` | `first` |
8302
+ | `m.prefix().matched` | `false` |
8303
+ | `m.suffix().first` | `last` |
8304
+ | `m.suffix().second` | `last` |
8305
+ | `m.suffix().matched` | `false` |
8306
+ | `m[0].first` | `first` |
8307
+ | `m[0].second` | `last` |
8308
+ | `m[0].matched` | `true` |
8309
+ | `m[n].first` | For all integers `0 < n < m.size()`, the start of the sequence that matched sub-expression `n`. Alternatively, if sub-expression `n` did not participate in the match, then `last`. |
8310
+ | `m[n].second` | For all integers `0 < n < m.size()`, the end of the sequence that matched sub-expression `n`. Alternatively, if sub-expression `n` did not participate in the match, then `last`. |
8311
+ | `m[n].matched` | For all integers `0 < n < m.size()`, `true` if sub-expression `n` participated in the match, `false` otherwise. |
8312
+
8313
+ ``` cpp
8314
+ template<class BidirectionalIterator, class charT, class traits>
8315
+ bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
8316
+ const basic_regex<charT, traits>& e,
8317
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8318
+ ```
8319
+
8320
+ *Effects:* Behaves “as if” by constructing an instance of
8321
+ `match_results<BidirectionalIterator> what`, and then returning the
8322
+ result of `regex_match(first, last, what, e, flags)`.
8323
+
8324
+ ``` cpp
8325
+ template<class charT, class Allocator, class traits>
8326
+ bool regex_match(const charT* str,
8327
+ match_results<const charT*, Allocator>& m,
8328
+ const basic_regex<charT, traits>& e,
8329
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8330
+ ```
8331
+
8332
+ *Returns:*
8333
+ `regex_match(str, str + char_traits<charT>::length(str), m, e, flags)`.
8334
+
8335
+ ``` cpp
8336
+ template<class ST, class SA, class Allocator, class charT, class traits>
8337
+ bool regex_match(const basic_string<charT, ST, SA>& s,
8338
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
8339
+ Allocator>& m,
8340
+ const basic_regex<charT, traits>& e,
8341
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8342
+ ```
8343
+
8344
+ *Returns:* `regex_match(s.begin(), s.end(), m, e, flags)`.
8345
+
8346
+ ``` cpp
8347
+ template<class charT, class traits>
8348
+ bool regex_match(const charT* str,
8349
+ const basic_regex<charT, traits>& e,
8350
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8351
+ ```
8352
+
8353
+ *Returns:*
8354
+ `regex_match(str, str + char_traits<charT>::length(str), e, flags)`.
8355
+
8356
+ ``` cpp
8357
+ template<class ST, class SA, class charT, class traits>
8358
+ bool regex_match(const basic_string<charT, ST, SA>& s,
8359
+ const basic_regex<charT, traits>& e,
8360
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8361
+ ```
8362
+
8363
+ *Returns:* `regex_match(s.begin(), s.end(), e, flags)`.
8364
+
8365
+ #### `regex_search` <a id="re.alg.search">[[re.alg.search]]</a>
8366
+
8367
+ ``` cpp
8368
+ template<class BidirectionalIterator, class Allocator, class charT, class traits>
8369
+ bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
8370
+ match_results<BidirectionalIterator, Allocator>& m,
8371
+ const basic_regex<charT, traits>& e,
8372
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8373
+ ```
8374
+
8375
+ *Preconditions:* `BidirectionalIterator` models `bidirectional_iterator`
8376
+ [[iterator.concept.bidir]].
8377
+
8378
+ *Effects:* Determines whether there is some sub-sequence within
8379
+ \[`first`, `last`) that matches the regular expression `e`. The
8380
+ parameter `flags` is used to control how the expression is matched
8381
+ against the character sequence. Returns `true` if such a sequence
8382
+ exists, `false` otherwise.
8383
+
8384
+ *Ensures:* `m.ready() == true` in all cases. If the function returns
8385
+ `false`, then the effect on parameter `m` is unspecified except that
8386
+ `m.size()` returns `0` and `m.empty()` returns `true`. Otherwise the
8387
+ effects on parameter `m` are given in [[re.alg.search]].
8388
+
8389
+ **Table: Effects of `regex_search` algorithm** <a id="re.alg.search">[re.alg.search]</a>
8390
+
8391
+ | Element | Value |
8392
+ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
8393
+ | `m.size()` | `1 + e.mark_count()` |
8394
+ | `m.empty()` | `false` |
8395
+ | `m.prefix().first` | `first` |
8396
+ | `m.prefix().second` | `m[0].first` |
8397
+ | `m.prefix().matched` | `m.prefix().first != m.prefix().second` |
8398
+ | `m.suffix().first` | `m[0].second` |
8399
+ | `m.suffix().second` | `last` |
8400
+ | `m.suffix().matched` | `m.suffix().first != m.suffix().second` |
8401
+ | `m[0].first` | The start of the sequence of characters that matched the regular expression |
8402
+ | `m[0].second` | The end of the sequence of characters that matched the regular expression |
8403
+ | `m[0].matched` | `true` |
8404
+ | `m[n].first` | For all integers `0 < n < m.size()`, the start of the sequence that matched sub-expression `n`. Alternatively, if sub-expression `n` did not participate in the match, then `last`. |
8405
+ | `m[n].second` | For all integers `0 < n < m.size()`, the end of the sequence that matched sub-expression `n`. Alternatively, if sub-expression `n` did not participate in the match, then `last`. |
8406
+ | `m[n].matched` | For all integers `0 < n < m.size()`, `true` if sub-expression `n` participated in the match, `false` otherwise. |
8407
+
8408
+ ``` cpp
8409
+ template<class charT, class Allocator, class traits>
8410
+ bool regex_search(const charT* str, match_results<const charT*, Allocator>& m,
8411
+ const basic_regex<charT, traits>& e,
8412
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8413
+ ```
8414
+
8415
+ *Returns:*
8416
+ `regex_search(str, str + char_traits<charT>::length(str), m, e, flags)`.
8417
+
8418
+ ``` cpp
8419
+ template<class ST, class SA, class Allocator, class charT, class traits>
8420
+ bool regex_search(const basic_string<charT, ST, SA>& s,
8421
+ match_results<typename basic_string<charT, ST, SA>::const_iterator,
8422
+ Allocator>& m,
8423
+ const basic_regex<charT, traits>& e,
8424
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8425
+ ```
8426
+
8427
+ *Returns:* `regex_search(s.begin(), s.end(), m, e, flags)`.
8428
+
8429
+ ``` cpp
8430
+ template<class BidirectionalIterator, class charT, class traits>
8431
+ bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
8432
+ const basic_regex<charT, traits>& e,
8433
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8434
+ ```
8435
+
8436
+ *Effects:* Behaves “as if” by constructing an object `what` of type
8437
+ `match_results<BidirectionalIterator>` and returning
8438
+ `regex_search(first, last, what, e, flags)`.
8439
+
8440
+ ``` cpp
8441
+ template<class charT, class traits>
8442
+ bool regex_search(const charT* str,
8443
+ const basic_regex<charT, traits>& e,
8444
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8445
+ ```
8446
+
8447
+ *Returns:*
8448
+ `regex_search(str, str + char_traits<charT>::length(str), e, flags)`.
8449
+
8450
+ ``` cpp
8451
+ template<class ST, class SA, class charT, class traits>
8452
+ bool regex_search(const basic_string<charT, ST, SA>& s,
8453
+ const basic_regex<charT, traits>& e,
8454
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8455
+ ```
8456
+
8457
+ *Returns:* `regex_search(s.begin(), s.end(), e, flags)`.
8458
+
8459
+ #### `regex_replace` <a id="re.alg.replace">[[re.alg.replace]]</a>
8460
+
8461
+ ``` cpp
8462
+ template<class OutputIterator, class BidirectionalIterator,
8463
+ class traits, class charT, class ST, class SA>
8464
+ OutputIterator
8465
+ regex_replace(OutputIterator out,
8466
+ BidirectionalIterator first, BidirectionalIterator last,
8467
+ const basic_regex<charT, traits>& e,
8468
+ const basic_string<charT, ST, SA>& fmt,
8469
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8470
+ template<class OutputIterator, class BidirectionalIterator, class traits, class charT>
8471
+ OutputIterator
8472
+ regex_replace(OutputIterator out,
8473
+ BidirectionalIterator first, BidirectionalIterator last,
8474
+ const basic_regex<charT, traits>& e,
8475
+ const charT* fmt,
8476
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8477
+ ```
8478
+
8479
+ *Effects:* Constructs a `regex_iterator` object `i` as if by
8480
+
8481
+ ``` cpp
8482
+ regex_iterator<BidirectionalIterator, charT, traits> i(first, last, e, flags)
8483
+ ```
8484
+
8485
+ and uses `i` to enumerate through all of the matches `m` of type
8486
+ `match_results<BidirectionalIterator>` that occur within the sequence
8487
+ \[`first`, `last`). If no such matches are found and
8488
+ `!(flags & regex_constants::format_no_copy)`, then calls
8489
+
8490
+ ``` cpp
8491
+ out = copy(first, last, out)
8492
+ ```
8493
+
8494
+ If any matches are found then, for each such match:
8495
+
8496
+ - If `!(flags & regex_constants::format_no_copy)`, calls
8497
+ ``` cpp
8498
+ out = copy(m.prefix().first, m.prefix().second, out)
8499
+ ```
8500
+ - Then calls
8501
+ ``` cpp
8502
+ out = m.format(out, fmt, flags)
8503
+ ```
8504
+
8505
+ for the first form of the function and
8506
+ ``` cpp
8507
+ out = m.format(out, fmt, fmt + char_traits<charT>::length(fmt), flags)
8508
+ ```
8509
+
8510
+ for the second.
8511
+
8512
+ Finally, if such a match is found and
8513
+ `!(flags & regex_constants::format_no_copy)`, calls
8514
+
8515
+ ``` cpp
8516
+ out = copy(last_m.suffix().first, last_m.suffix().second, out)
8517
+ ```
8518
+
8519
+ where `last_m` is a copy of the last match found. If
8520
+ `flags & regex_constants::format_first_only` is nonzero, then only the
8521
+ first match found is replaced.
8522
+
8523
+ *Returns:* `out`.
8524
+
8525
+ ``` cpp
8526
+ template<class traits, class charT, class ST, class SA, class FST, class FSA>
8527
+ basic_string<charT, ST, SA>
8528
+ regex_replace(const basic_string<charT, ST, SA>& s,
8529
+ const basic_regex<charT, traits>& e,
8530
+ const basic_string<charT, FST, FSA>& fmt,
8531
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8532
+ template<class traits, class charT, class ST, class SA>
8533
+ basic_string<charT, ST, SA>
8534
+ regex_replace(const basic_string<charT, ST, SA>& s,
8535
+ const basic_regex<charT, traits>& e,
8536
+ const charT* fmt,
8537
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8538
+ ```
8539
+
8540
+ *Effects:* Constructs an empty string `result` of type
8541
+ `basic_string<charT, ST, SA>` and calls:
8542
+
8543
+ ``` cpp
8544
+ regex_replace(back_inserter(result), s.begin(), s.end(), e, fmt, flags);
8545
+ ```
8546
+
8547
+ *Returns:* `result`.
8548
+
8549
+ ``` cpp
8550
+ template<class traits, class charT, class ST, class SA>
8551
+ basic_string<charT>
8552
+ regex_replace(const charT* s,
8553
+ const basic_regex<charT, traits>& e,
8554
+ const basic_string<charT, ST, SA>& fmt,
8555
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8556
+ template<class traits, class charT>
8557
+ basic_string<charT>
8558
+ regex_replace(const charT* s,
8559
+ const basic_regex<charT, traits>& e,
8560
+ const charT* fmt,
8561
+ regex_constants::match_flag_type flags = regex_constants::match_default);
8562
+ ```
8563
+
8564
+ *Effects:* Constructs an empty string `result` of type
8565
+ `basic_string<charT>` and calls:
8566
+
8567
+ ``` cpp
8568
+ regex_replace(back_inserter(result), s, s + char_traits<charT>::length(s), e, fmt, flags);
8569
+ ```
8570
+
8571
+ *Returns:* `result`.
8572
+
8573
+ ### Regular expression iterators <a id="re.iter">[[re.iter]]</a>
8574
+
8575
+ #### Class template `regex_iterator` <a id="re.regiter">[[re.regiter]]</a>
8576
+
8577
+ ##### General <a id="re.regiter.general">[[re.regiter.general]]</a>
8578
+
8579
+ The class template `regex_iterator` is an iterator adaptor. It
8580
+ represents a new view of an existing iterator sequence, by enumerating
8581
+ all the occurrences of a regular expression within that sequence. A
8582
+ `regex_iterator` uses `regex_search` to find successive regular
8583
+ expression matches within the sequence from which it was constructed.
8584
+ After the iterator is constructed, and every time `operator++` is used,
8585
+ the iterator finds and stores a value of
8586
+ `match_results<BidirectionalIterator>`. If the end of the sequence is
8587
+ reached (`regex_search` returns `false`), the iterator becomes equal to
8588
+ the end-of-sequence iterator value. The default constructor constructs
8589
+ an end-of-sequence iterator object, which is the only legitimate
8590
+ iterator to be used for the end condition. The result of `operator*` on
8591
+ an end-of-sequence iterator is not defined. For any other iterator value
8592
+ a `const match_results<BidirectionalIterator>&` is returned. The result
8593
+ of `operator->` on an end-of-sequence iterator is not defined. For any
8594
+ other iterator value a `const match_results<BidirectionalIterator>*` is
8595
+ returned. It is impossible to store things into `regex_iterator`s. Two
8596
+ end-of-sequence iterators are always equal. An end-of-sequence iterator
8597
+ is not equal to a non-end-of-sequence iterator. Two non-end-of-sequence
8598
+ iterators are equal when they are constructed from the same arguments.
8599
+
8600
+ ``` cpp
8601
+ namespace std {
8602
+ template<class BidirectionalIterator,
8603
+ class charT = typename iterator_traits<BidirectionalIterator>::value_type,
8604
+ class traits = regex_traits<charT>>
8605
+ class regex_iterator {
8606
+ public:
8607
+ using regex_type = basic_regex<charT, traits>;
8608
+ using iterator_category = forward_iterator_tag;
8609
+ using iterator_concept = input_iterator_tag;
8610
+ using value_type = match_results<BidirectionalIterator>;
8611
+ using difference_type = ptrdiff_t;
8612
+ using pointer = const value_type*;
8613
+ using reference = const value_type&;
8614
+
8615
+ regex_iterator();
8616
+ regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
8617
+ const regex_type& re,
8618
+ regex_constants::match_flag_type m = regex_constants::match_default);
8619
+ regex_iterator(BidirectionalIterator, BidirectionalIterator,
8620
+ const regex_type&&,
8621
+ regex_constants::match_flag_type = regex_constants::match_default) = delete;
8622
+ regex_iterator(const regex_iterator&);
8623
+ regex_iterator& operator=(const regex_iterator&);
8624
+ bool operator==(const regex_iterator&) const;
8625
+ bool operator==(default_sentinel_t) const { return *this == regex_iterator(); }
8626
+ const value_type& operator*() const;
8627
+ const value_type* operator->() const;
8628
+ regex_iterator& operator++();
8629
+ regex_iterator operator++(int);
8630
+
8631
+ private:
8632
+ BidirectionalIterator begin; // exposition only
8633
+ BidirectionalIterator end; // exposition only
8634
+ const regex_type* pregex; // exposition only
8635
+ regex_constants::match_flag_type flags; // exposition only
8636
+ match_results<BidirectionalIterator> match; // exposition only
8637
+ };
8638
+ }
8639
+ ```
8640
+
8641
+ An object of type `regex_iterator` that is not an end-of-sequence
8642
+ iterator holds a *zero-length match* if `match[0].matched == true` and
8643
+ `match[0].first == match[0].second`.
8644
+
8645
+ [*Note 1*: For example, this can occur when the part of the regular
8646
+ expression that matched consists only of an assertion (such as `'^'`,
8647
+ `'$'`, `'\b'`, `'\B'`). — *end note*]
8648
+
8649
+ ##### Constructors <a id="re.regiter.cnstr">[[re.regiter.cnstr]]</a>
8650
+
8651
+ ``` cpp
8652
+ regex_iterator();
8653
+ ```
8654
+
8655
+ *Effects:* Constructs an end-of-sequence iterator.
8656
+
8657
+ ``` cpp
8658
+ regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
8659
+ const regex_type& re,
8660
+ regex_constants::match_flag_type m = regex_constants::match_default);
8661
+ ```
8662
+
8663
+ *Effects:* Initializes `begin` and `end` to `a` and `b`, respectively,
8664
+ sets `pregex` to `addressof(re)`, sets `flags` to `m`, then calls
8665
+ `regex_search(begin, end, match, *pregex, flags)`. If this call returns
8666
+ `false` the constructor sets `*this` to the end-of-sequence iterator.
8667
+
8668
+ ##### Comparisons <a id="re.regiter.comp">[[re.regiter.comp]]</a>
8669
+
8670
+ ``` cpp
8671
+ bool operator==(const regex_iterator& right) const;
8672
+ ```
8673
+
8674
+ *Returns:* `true` if `*this` and `right` are both end-of-sequence
8675
+ iterators or if the following conditions all hold:
8676
+
8677
+ - `begin == right.begin`,
8678
+ - `end == right.end`,
8679
+ - `pregex == right.pregex`,
8680
+ - `flags == right.flags`, and
8681
+ - `match[0] == right.match[0]`;
8682
+
8683
+ otherwise `false`.
8684
+
8685
+ ##### Indirection <a id="re.regiter.deref">[[re.regiter.deref]]</a>
8686
+
8687
+ ``` cpp
8688
+ const value_type& operator*() const;
8689
+ ```
8690
+
8691
+ *Returns:* `match`.
8692
+
8693
+ ``` cpp
8694
+ const value_type* operator->() const;
8695
+ ```
8696
+
8697
+ *Returns:* `addressof(match)`.
8698
+
8699
+ ##### Increment <a id="re.regiter.incr">[[re.regiter.incr]]</a>
8700
+
8701
+ ``` cpp
8702
+ regex_iterator& operator++();
8703
+ ```
8704
+
8705
+ *Effects:* Constructs a local variable `start` of type
8706
+ `BidirectionalIterator` and initializes it with the value of
8707
+ `match[0].second`.
8708
+
8709
+ If the iterator holds a zero-length match and `start == end` the
8710
+ operator sets `*this` to the end-of-sequence iterator and returns
8711
+ `*this`.
8712
+
8713
+ Otherwise, if the iterator holds a zero-length match, the operator
8714
+ calls:
8715
+
8716
+ ``` cpp
8717
+ regex_search(start, end, match, *pregex,
8718
+ flags | regex_constants::match_not_null | regex_constants::match_continuous)
8719
+ ```
8720
+
8721
+ If the call returns `true` the operator returns `*this`. Otherwise the
8722
+ operator increments `start` and continues as if the most recent match
8723
+ was not a zero-length match.
8724
+
8725
+ If the most recent match was not a zero-length match, the operator sets
8726
+ `flags` to `flags | regex_constants::match_prev_avail` and calls
8727
+ `regex_search(start, end, match, *pregex, flags)`. If the call returns
8728
+ `false` the iterator sets `*this` to the end-of-sequence iterator. The
8729
+ iterator then returns `*this`.
8730
+
8731
+ In all cases in which the call to `regex_search` returns `true`,
8732
+ `match.prefix().first` shall be equal to the previous value of
8733
+ `match[0].second`, and for each index `i` in the half-open range \[`0`,
8734
+ `match.size()`) for which `match[i].matched` is `true`,
8735
+ `match.position(i)` shall return `distance(begin, match[i].first)`.
8736
+
8737
+ [*Note 1*: This means that `match.position(i)` gives the offset from
8738
+ the beginning of the target sequence, which is often not the same as the
8739
+ offset from the sequence passed in the call to
8740
+ `regex_search`. — *end note*]
8741
+
8742
+ It is unspecified how the implementation makes these adjustments.
8743
+
8744
+ [*Note 2*: This means that an implementation can call an
8745
+ implementation-specific search function, in which case a program-defined
8746
+ specialization of `regex_search` will not be called. — *end note*]
8747
+
8748
+ ``` cpp
8749
+ regex_iterator operator++(int);
8750
+ ```
8751
+
8752
+ *Effects:* As if by:
8753
+
8754
+ ``` cpp
8755
+ regex_iterator tmp = *this;
8756
+ ++(*this);
8757
+ return tmp;
8758
+ ```
8759
+
8760
+ #### Class template `regex_token_iterator` <a id="re.tokiter">[[re.tokiter]]</a>
8761
+
8762
+ ##### General <a id="re.tokiter.general">[[re.tokiter.general]]</a>
8763
+
8764
+ The class template `regex_token_iterator` is an iterator adaptor; that
8765
+ is to say it represents a new view of an existing iterator sequence, by
8766
+ enumerating all the occurrences of a regular expression within that
8767
+ sequence, and presenting one or more sub-expressions for each match
8768
+ found. Each position enumerated by the iterator is a `sub_match` class
8769
+ template instance that represents what matched a particular
8770
+ sub-expression within the regular expression.
8771
+
8772
+ When class `regex_token_iterator` is used to enumerate a single
8773
+ sub-expression with index -1 the iterator performs field splitting: that
8774
+ is to say it enumerates one sub-expression for each section of the
8775
+ character container sequence that does not match the regular expression
8776
+ specified.
8777
+
8778
+ After it is constructed, the iterator finds and stores a value
8779
+ `regex_iterator<BidirectionalIterator> position` and sets the internal
8780
+ count `N` to zero. It also maintains a sequence `subs` which contains a
8781
+ list of the sub-expressions which will be enumerated. Every time
8782
+ `operator++` is used the count `N` is incremented; if `N` exceeds or
8783
+ equals `subs.size()`, then the iterator increments member `position` and
8784
+ sets count `N` to zero.
8785
+
8786
+ If the end of sequence is reached (`position` is equal to the end of
8787
+ sequence iterator), the iterator becomes equal to the end-of-sequence
8788
+ iterator value, unless the sub-expression being enumerated has index -1,
8789
+ in which case the iterator enumerates one last sub-expression that
8790
+ contains all the characters from the end of the last regular expression
8791
+ match to the end of the input sequence being enumerated, provided that
8792
+ this would not be an empty sub-expression.
8793
+
8794
+ The default constructor constructs an end-of-sequence iterator object,
8795
+ which is the only legitimate iterator to be used for the end condition.
8796
+ The result of `operator*` on an end-of-sequence iterator is not defined.
8797
+ For any other iterator value a `const sub_match<BidirectionalIterator>&`
8798
+ is returned. The result of `operator->` on an end-of-sequence iterator
8799
+ is not defined. For any other iterator value a `const
8800
+ sub_match<BidirectionalIterator>*` is returned.
8801
+
8802
+ It is impossible to store things into `regex_token_iterator`s. Two
8803
+ end-of-sequence iterators are always equal. An end-of-sequence iterator
8804
+ is not equal to a non-end-of-sequence iterator. Two non-end-of-sequence
8805
+ iterators are equal when they are constructed from the same arguments.
8806
+
8807
+ ``` cpp
8808
+ namespace std {
8809
+ template<class BidirectionalIterator,
8810
+ class charT = typename iterator_traits<BidirectionalIterator>::value_type,
8811
+ class traits = regex_traits<charT>>
8812
+ class regex_token_iterator {
8813
+ public:
8814
+ using regex_type = basic_regex<charT, traits>;
8815
+ using iterator_category = forward_iterator_tag;
8816
+ using iterator_concept = input_iterator_tag;
8817
+ using value_type = sub_match<BidirectionalIterator>;
8818
+ using difference_type = ptrdiff_t;
8819
+ using pointer = const value_type*;
8820
+ using reference = const value_type&;
8821
+
8822
+ regex_token_iterator();
8823
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8824
+ const regex_type& re,
8825
+ int submatch = 0,
8826
+ regex_constants::match_flag_type m =
8827
+ regex_constants::match_default);
8828
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8829
+ const regex_type& re,
8830
+ const vector<int>& submatches,
8831
+ regex_constants::match_flag_type m =
8832
+ regex_constants::match_default);
8833
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8834
+ const regex_type& re,
8835
+ initializer_list<int> submatches,
8836
+ regex_constants::match_flag_type m =
8837
+ regex_constants::match_default);
8838
+ template<size_t N>
8839
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8840
+ const regex_type& re,
8841
+ const int (&submatches)[N],
8842
+ regex_constants::match_flag_type m =
8843
+ regex_constants::match_default);
8844
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8845
+ const regex_type&& re,
8846
+ int submatch = 0,
8847
+ regex_constants::match_flag_type m =
8848
+ regex_constants::match_default) = delete;
8849
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8850
+ const regex_type&& re,
8851
+ const vector<int>& submatches,
8852
+ regex_constants::match_flag_type m =
8853
+ regex_constants::match_default) = delete;
8854
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8855
+ const regex_type&& re,
8856
+ initializer_list<int> submatches,
8857
+ regex_constants::match_flag_type m =
8858
+ regex_constants::match_default) = delete;
8859
+ template<size_t N>
8860
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8861
+ const regex_type&& re,
8862
+ const int (&submatches)[N],
8863
+ regex_constants::match_flag_type m =
8864
+ regex_constants::match_default) = delete;
8865
+ regex_token_iterator(const regex_token_iterator&);
8866
+ regex_token_iterator& operator=(const regex_token_iterator&);
8867
+ bool operator==(const regex_token_iterator&) const;
8868
+ bool operator==(default_sentinel_t) const { return *this == regex_token_iterator(); }
8869
+ const value_type& operator*() const;
8870
+ const value_type* operator->() const;
8871
+ regex_token_iterator& operator++();
8872
+ regex_token_iterator operator++(int);
8873
+
8874
+ private:
8875
+ using position_iterator =
8876
+ regex_iterator<BidirectionalIterator, charT, traits>; // exposition only
8877
+ position_iterator position; // exposition only
8878
+ const value_type* result; // exposition only
8879
+ value_type suffix; // exposition only
8880
+ size_t N; // exposition only
8881
+ vector<int> subs; // exposition only
8882
+ };
8883
+ }
8884
+ ```
8885
+
8886
+ A *suffix iterator* is a `regex_token_iterator` object that points to a
8887
+ final sequence of characters at the end of the target sequence. In a
8888
+ suffix iterator the member `result` holds a pointer to the data member
8889
+ `suffix`, the value of the member `suffix.match` is `true`,
8890
+ `suffix.first` points to the beginning of the final sequence, and
8891
+ `suffix.second` points to the end of the final sequence.
8892
+
8893
+ [*Note 1*: For a suffix iterator, data member `suffix.first` is the
8894
+ same as the end of the last match found, and `suffix.second` is the same
8895
+ as the end of the target sequence. — *end note*]
8896
+
8897
+ The *current match* is `(*position).prefix()` if `subs[N] == -1`, or
8898
+ `(*position)[subs[N]]` for any other value of `subs[N]`.
8899
+
8900
+ ##### Constructors <a id="re.tokiter.cnstr">[[re.tokiter.cnstr]]</a>
8901
+
8902
+ ``` cpp
8903
+ regex_token_iterator();
8904
+ ```
8905
+
8906
+ *Effects:* Constructs the end-of-sequence iterator.
8907
+
8908
+ ``` cpp
8909
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8910
+ const regex_type& re,
8911
+ int submatch = 0,
8912
+ regex_constants::match_flag_type m = regex_constants::match_default);
8913
+
8914
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8915
+ const regex_type& re,
8916
+ const vector<int>& submatches,
8917
+ regex_constants::match_flag_type m = regex_constants::match_default);
8918
+
8919
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8920
+ const regex_type& re,
8921
+ initializer_list<int> submatches,
8922
+ regex_constants::match_flag_type m = regex_constants::match_default);
8923
+
8924
+ template<size_t N>
8925
+ regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
8926
+ const regex_type& re,
8927
+ const int (&submatches)[N],
8928
+ regex_constants::match_flag_type m = regex_constants::match_default);
8929
+ ```
8930
+
8931
+ *Preconditions:* Each of the initialization values of `submatches` is
8932
+ `>= -1`.
8933
+
8934
+ *Effects:* The first constructor initializes the member `subs` to hold
8935
+ the single value `submatch`. The second, third, and fourth constructors
8936
+ initialize the member `subs` to hold a copy of the sequence of integer
8937
+ values pointed to by the iterator range \[`begin(submatches)`,
8938
+ `end(submatches)`).
8939
+
8940
+ Each constructor then sets `N` to 0, and `position` to
8941
+ `position_iterator(a, b, re, m)`. If `position` is not an
8942
+ end-of-sequence iterator the constructor sets `result` to the address of
8943
+ the current match. Otherwise if any of the values stored in `subs` is
8944
+ equal to -1 the constructor sets `*this` to a suffix iterator that
8945
+ points to the range \[`a`, `b`), otherwise the constructor sets `*this`
8946
+ to an end-of-sequence iterator.
8947
+
8948
+ ##### Comparisons <a id="re.tokiter.comp">[[re.tokiter.comp]]</a>
8949
+
8950
+ ``` cpp
8951
+ bool operator==(const regex_token_iterator& right) const;
8952
+ ```
8953
+
8954
+ *Returns:* `true` if `*this` and `right` are both end-of-sequence
8955
+ iterators, or if `*this` and `right` are both suffix iterators and
8956
+ `suffix == right.suffix`; otherwise returns `false` if `*this` or
8957
+ `right` is an end-of-sequence iterator or a suffix iterator. Otherwise
8958
+ returns `true` if `position == right.position`, `N == right.N`, and
8959
+ `subs == right.subs`. Otherwise returns `false`.
8960
+
8961
+ ##### Indirection <a id="re.tokiter.deref">[[re.tokiter.deref]]</a>
8962
+
8963
+ ``` cpp
8964
+ const value_type& operator*() const;
8965
+ ```
8966
+
8967
+ *Returns:* `*result`.
8968
+
8969
+ ``` cpp
8970
+ const value_type* operator->() const;
8971
+ ```
8972
+
8973
+ *Returns:* `result`.
8974
+
8975
+ ##### Increment <a id="re.tokiter.incr">[[re.tokiter.incr]]</a>
8976
+
8977
+ ``` cpp
8978
+ regex_token_iterator& operator++();
8979
+ ```
8980
+
8981
+ *Effects:* Constructs a local variable `prev` of type
8982
+ `position_iterator`, initialized with the value of `position`.
8983
+
8984
+ If `*this` is a suffix iterator, sets `*this` to an end-of-sequence
8985
+ iterator.
8986
+
8987
+ Otherwise, if `N + 1 < subs.size()`, increments `N` and sets `result` to
8988
+ the address of the current match.
8989
+
8990
+ Otherwise, sets `N` to 0 and increments `position`. If `position` is not
8991
+ an end-of-sequence iterator the operator sets `result` to the address of
8992
+ the current match.
8993
+
8994
+ Otherwise, if any of the values stored in `subs` is equal to -1 and
8995
+ `prev->suffix().length()` is not 0 the operator sets `*this` to a suffix
8996
+ iterator that points to the range \[`prev->suffix().first`,
8997
+ `prev->suffix().second`).
8998
+
8999
+ Otherwise, sets `*this` to an end-of-sequence iterator.
9000
+
9001
+ *Returns:* `*this`.
9002
+
9003
+ ``` cpp
9004
+ regex_token_iterator& operator++(int);
9005
+ ```
9006
+
9007
+ *Effects:* Constructs a copy `tmp` of `*this`, then calls `++(*this)`.
9008
+
9009
+ *Returns:* `tmp`.
9010
+
9011
+ ### Modified ECMAScript regular expression grammar <a id="re.grammar">[[re.grammar]]</a>
9012
+
9013
+ The regular expression grammar recognized by `basic_regex` objects
9014
+ constructed with the ECMAScript flag is that specified by ECMA-262,
9015
+ except as specified below.
9016
+
9017
+ Objects of type specialization of `basic_regex` store within themselves
9018
+ a default-constructed instance of their `traits` template parameter,
9019
+ henceforth referred to as `traits_inst`. This `traits_inst` object is
9020
+ used to support localization of the regular expression; `basic_regex`
9021
+ member functions shall not call any locale dependent C or C++ API,
9022
+ including the formatted string input functions. Instead they shall call
9023
+ the appropriate traits member function to achieve the required effect.
9024
+
9025
+ The following productions within the ECMAScript grammar are modified as
9026
+ follows:
9027
+
9028
+ ``` bnf
9029
+ ClassAtom::
9030
+ '-'
9031
+ ClassAtomNoDash
9032
+ ClassAtomExClass
9033
+ ClassAtomCollatingElement
9034
+ ClassAtomEquivalence
9035
+ ```
9036
+
9037
+ ``` bnf
9038
+ IdentityEscape::
9039
+ SourceCharacter but not 'c'
9040
+ ```
9041
+
9042
+ The following new productions are then added:
9043
+
9044
+ ``` bnf
9045
+ ClassAtomExClass::
9046
+ '[:' ClassName ':]'
9047
+ ```
9048
+
9049
+ ``` bnf
9050
+ ClassAtomCollatingElement::
9051
+ '[.' ClassName '.]'
9052
+ ```
9053
+
9054
+ ``` bnf
9055
+ ClassAtomEquivalence::
9056
+ '[=' ClassName '=]'
9057
+ ```
9058
+
9059
+ ``` bnf
9060
+ ClassName::
9061
+ ClassNameCharacter
9062
+ ClassNameCharacter ClassName
9063
+ ```
9064
+
9065
+ ``` bnf
9066
+ ClassNameCharacter::
9067
+ SourceCharacter but not one of '.' or '=' or ':'
9068
+ ```
9069
+
9070
+ The productions , and provide functionality equivalent to that of the
9071
+ same features in regular expressions in POSIX.
9072
+
9073
+ The regular expression grammar may be modified by any
9074
+ `regex_constants::syntax_option_type` flags specified when constructing
9075
+ an object of type specialization of `basic_regex` according to the rules
9076
+ in [[re.synopt]].
9077
+
9078
+ A production, when used in , is not valid if
9079
+ `traits_inst.lookup_classname` returns zero for that name. The names
9080
+ recognized as valid s are determined by the type of the traits class,
9081
+ but at least the following names shall be recognized: `alnum`, `alpha`,
9082
+ `blank`, `cntrl`, `digit`, `graph`, `lower`, `print`, `punct`, `space`,
9083
+ `upper`, `xdigit`, `d`, `s`, `w`. In addition the following expressions
9084
+ shall be equivalent:
9085
+
9086
+ ``` cpp
9087
+ \d and [[:digit:]]
9088
+
9089
+ \D and [^[:digit:]]
9090
+
9091
+ \s and [[:space:]]
9092
+
9093
+ \S and [^[:space:]]
9094
+
9095
+ \w and [_[:alnum:]]
9096
+
9097
+ \W and [^_[:alnum:]]
9098
+ ```
9099
+
9100
+ A production when used in a production is not valid if the value
9101
+ returned by `traits_inst.lookup_collatename` for that name is an empty
9102
+ string.
9103
+
9104
+ The results from multiple calls to `traits_inst.lookup_classname` can be
9105
+ bitwise ’ed together and subsequently passed to `traits_inst.isctype`.
9106
+
9107
+ A production when used in a production is not valid if the value
9108
+ returned by `traits_inst.lookup_collatename` for that name is an empty
9109
+ string or if the value returned by `traits_inst.transform_primary` for
9110
+ the result of the call to `traits_inst.lookup_collatename` is an empty
9111
+ string.
9112
+
9113
+ When the sequence of characters being transformed to a finite state
9114
+ machine contains an invalid class name the translator shall throw an
9115
+ exception object of type `regex_error`.
9116
+
9117
+ If the *CV* of a *UnicodeEscapeSequence* is greater than the largest
9118
+ value that can be held in an object of type `charT` the translator shall
9119
+ throw an exception object of type `regex_error`.
9120
+
9121
+ [*Note 1*: This means that values of the form `"\uxxxx"` that do not
9122
+ fit in a character are invalid. — *end note*]
9123
+
9124
+ Where the regular expression grammar requires the conversion of a
9125
+ sequence of characters to an integral value, this is accomplished by
9126
+ calling `traits_inst.value`.
9127
+
9128
+ The behavior of the internal finite state machine representation when
9129
+ used to match a sequence of characters is as described in ECMA-262. The
9130
+ behavior is modified according to any `match_flag_type` flags
9131
+ [[re.matchflag]] specified when using the regular expression object in
9132
+ one of the regular expression algorithms [[re.alg]]. The behavior is
9133
+ also localized by interaction with the traits class template parameter
9134
+ as follows:
9135
+
9136
+ - During matching of a regular expression finite state machine against a
9137
+ sequence of characters, two characters `c` and `d` are compared using
9138
+ the following rules:
9139
+ - if `(flags() & regex_constants::icase)` the two characters are equal
9140
+ if
9141
+ `traits_inst.translate_nocase(c) == traits_inst.translate_nocase(d)`;
9142
+ - otherwise, if `flags() & regex_constants::collate` the two
9143
+ characters are equal if
9144
+ `traits_inst.translate(c) == traits_inst.translate(d)`;
9145
+ - otherwise, the two characters are equal if `c == d`.
9146
+ - During matching of a regular expression finite state machine against a
9147
+ sequence of characters, comparison of a collating element range
9148
+ `c1-c2` against a character `c` is conducted as follows: if
9149
+ `flags() & regex_constants::collate` is `false` then the character `c`
9150
+ is matched if `c1
9151
+ <= c && c <= c2`, otherwise `c` is matched in accordance with the
9152
+ following algorithm:
9153
+ ``` cpp
9154
+ string_type str1 = string_type(1,
9155
+ flags() & icase ?
9156
+ traits_inst.translate_nocase(c1) : traits_inst.translate(c1));
9157
+ string_type str2 = string_type(1,
9158
+ flags() & icase ?
9159
+ traits_inst.translate_nocase(c2) : traits_inst.translate(c2));
9160
+ string_type str = string_type(1,
9161
+ flags() & icase ?
9162
+ traits_inst.translate_nocase(c) : traits_inst.translate(c));
9163
+ return traits_inst.transform(str1.begin(), str1.end())
9164
+ <= traits_inst.transform(str.begin(), str.end())
9165
+ && traits_inst.transform(str.begin(), str.end())
9166
+ <= traits_inst.transform(str2.begin(), str2.end());
9167
+ ```
9168
+ - During matching of a regular expression finite state machine against a
9169
+ sequence of characters, testing whether a collating element is a
9170
+ member of a primary equivalence class is conducted by first converting
9171
+ the collating element and the equivalence class to sort keys using
9172
+ `traits::transform_primary`, and then comparing the sort keys for
9173
+ equality.
9174
+ - During matching of a regular expression finite state machine against a
9175
+ sequence of characters, a character `c` is a member of a character
9176
+ class designated by an iterator range \[`first`, `last`) if
9177
+ `traits_inst.isctype(c, traits_inst.lookup_classname(first, last, flags() & icase))`
9178
+ is `true`.
9179
+
9180
+ ## Null-terminated sequence utilities <a id="text.c.strings">[[text.c.strings]]</a>
9181
+
9182
+ ### Header `<cctype>` synopsis <a id="cctype.syn">[[cctype.syn]]</a>
9183
+
9184
+ ``` cpp
9185
+ namespace std {
9186
+ int isalnum(int c);
9187
+ int isalpha(int c);
9188
+ int isblank(int c);
9189
+ int iscntrl(int c);
9190
+ int isdigit(int c);
9191
+ int isgraph(int c);
9192
+ int islower(int c);
9193
+ int isprint(int c);
9194
+ int ispunct(int c);
9195
+ int isspace(int c);
9196
+ int isupper(int c);
9197
+ int isxdigit(int c);
9198
+ int tolower(int c);
9199
+ int toupper(int c);
9200
+ }
9201
+ ```
9202
+
9203
+ The contents and meaning of the header `<cctype>` are the same as the C
9204
+ standard library header `<ctype.h>`.
9205
+
9206
+ See also: ISO C 7.4
9207
+
9208
+ ### Header `<cwctype>` synopsis <a id="cwctype.syn">[[cwctype.syn]]</a>
9209
+
9210
+ ``` cpp
9211
+ namespace std {
9212
+ using wint_t = see below;
9213
+ using wctrans_t = see below;
9214
+ using wctype_t = see below;
9215
+
9216
+ int iswalnum(wint_t wc);
9217
+ int iswalpha(wint_t wc);
9218
+ int iswblank(wint_t wc);
9219
+ int iswcntrl(wint_t wc);
9220
+ int iswdigit(wint_t wc);
9221
+ int iswgraph(wint_t wc);
9222
+ int iswlower(wint_t wc);
9223
+ int iswprint(wint_t wc);
9224
+ int iswpunct(wint_t wc);
9225
+ int iswspace(wint_t wc);
9226
+ int iswupper(wint_t wc);
9227
+ int iswxdigit(wint_t wc);
9228
+ int iswctype(wint_t wc, wctype_t desc);
9229
+ wctype_t wctype(const char* property);
9230
+ wint_t towlower(wint_t wc);
9231
+ wint_t towupper(wint_t wc);
9232
+ wint_t towctrans(wint_t wc, wctrans_t desc);
9233
+ wctrans_t wctrans(const char* property);
9234
+ }
9235
+
9236
+ #define WEOF see below
9237
+ ```
9238
+
9239
+ The contents and meaning of the header `<cwctype>` are the same as the C
9240
+ standard library header `<wctype.h>`.
9241
+
9242
+ See also: ISO C 7.32
9243
+
9244
+ ### Header `<cwchar>` synopsis <a id="cwchar.syn">[[cwchar.syn]]</a>
9245
+
9246
+ ``` cpp
9247
+ #define __STDC_VERSION_WCHAR_H__ 202311L
9248
+
9249
+ namespace std {
9250
+ using size_t = see [support.types.layout]; // freestanding
9251
+ using mbstate_t = see below; // freestanding
9252
+ using wint_t = see below; // freestanding
9253
+
9254
+ struct tm;
9255
+
9256
+ int fwprintf(FILE* stream, const wchar_t* format, ...);
9257
+ int fwscanf(FILE* stream, const wchar_t* format, ...);
9258
+ int swprintf(wchar_t* s, size_t n, const wchar_t* format, ...);
9259
+ int swscanf(const wchar_t* s, const wchar_t* format, ...);
9260
+ int vfwprintf(FILE* stream, const wchar_t* format, va_list arg);
9261
+ int vfwscanf(FILE* stream, const wchar_t* format, va_list arg);
9262
+ int vswprintf(wchar_t* s, size_t n, const wchar_t* format, va_list arg);
9263
+ int vswscanf(const wchar_t* s, const wchar_t* format, va_list arg);
9264
+ int vwprintf(const wchar_t* format, va_list arg);
9265
+ int vwscanf(const wchar_t* format, va_list arg);
9266
+ int wprintf(const wchar_t* format, ...);
9267
+ int wscanf(const wchar_t* format, ...);
9268
+ wint_t fgetwc(FILE* stream);
9269
+ wchar_t* fgetws(wchar_t* s, int n, FILE* stream);
9270
+ wint_t fputwc(wchar_t c, FILE* stream);
9271
+ int fputws(const wchar_t* s, FILE* stream);
9272
+ int fwide(FILE* stream, int mode);
9273
+ wint_t getwc(FILE* stream);
9274
+ wint_t getwchar();
9275
+ wint_t putwc(wchar_t c, FILE* stream);
9276
+ wint_t putwchar(wchar_t c);
9277
+ wint_t ungetwc(wint_t c, FILE* stream);
9278
+ double wcstod(const wchar_t* nptr, wchar_t** endptr);
9279
+ float wcstof(const wchar_t* nptr, wchar_t** endptr);
9280
+ long double wcstold(const wchar_t* nptr, wchar_t** endptr);
9281
+ long int wcstol(const wchar_t* nptr, wchar_t** endptr, int base);
9282
+ long long int wcstoll(const wchar_t* nptr, wchar_t** endptr, int base);
9283
+ unsigned long int wcstoul(const wchar_t* nptr, wchar_t** endptr, int base);
9284
+ unsigned long long int wcstoull(const wchar_t* nptr, wchar_t** endptr, int base);
9285
+ wchar_t* wcscpy(wchar_t* s1, const wchar_t* s2); // freestanding
9286
+ wchar_t* wcsncpy(wchar_t* s1, const wchar_t* s2, size_t n); // freestanding
9287
+ wchar_t* wmemcpy(wchar_t* s1, const wchar_t* s2, size_t n); // freestanding
9288
+ wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n); // freestanding
9289
+ wchar_t* wcscat(wchar_t* s1, const wchar_t* s2); // freestanding
9290
+ wchar_t* wcsncat(wchar_t* s1, const wchar_t* s2, size_t n); // freestanding
9291
+ int wcscmp(const wchar_t* s1, const wchar_t* s2); // freestanding
9292
+ int wcscoll(const wchar_t* s1, const wchar_t* s2);
9293
+ int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n); // freestanding
9294
+ size_t wcsxfrm(wchar_t* s1, const wchar_t* s2, size_t n);
9295
+ int wmemcmp(const wchar_t* s1, const wchar_t* s2, size_t n); // freestanding
9296
+ const wchar_t* wcschr(const wchar_t* s, wchar_t c); // freestanding; see [library.c]
9297
+ wchar_t* wcschr(wchar_t* s, wchar_t c); // freestanding; see [library.c]
9298
+ size_t wcscspn(const wchar_t* s1, const wchar_t* s2); // freestanding
9299
+ const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2); // freestanding; see [library.c]
9300
+ wchar_t* wcspbrk(wchar_t* s1, const wchar_t* s2); // freestanding; see [library.c]
9301
+ const wchar_t* wcsrchr(const wchar_t* s, wchar_t c); // freestanding; see [library.c]
9302
+ wchar_t* wcsrchr(wchar_t* s, wchar_t c); // freestanding; see [library.c]
9303
+ size_t wcsspn(const wchar_t* s1, const wchar_t* s2); // freestanding
9304
+ const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2); // freestanding; see [library.c]
9305
+ wchar_t* wcsstr(wchar_t* s1, const wchar_t* s2); // freestanding; see [library.c]
9306
+ wchar_t* wcstok(wchar_t* s1, const wchar_t* s2, wchar_t** ptr); // freestanding
9307
+ const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n); // freestanding; see [library.c]
9308
+ wchar_t* wmemchr(wchar_t* s, wchar_t c, size_t n); // freestanding; see [library.c]
9309
+ size_t wcslen(const wchar_t* s); // freestanding
9310
+ wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n); // freestanding
9311
+ size_t wcsftime(wchar_t* s, size_t maxsize, const wchar_t* format, const tm* timeptr);
9312
+ wint_t btowc(int c);
9313
+ int wctob(wint_t c);
9314
+
9315
+ // [c.mb.wcs], multibyte / wide string and character conversion functions
9316
+ int mbsinit(const mbstate_t* ps);
9317
+ size_t mbrlen(const char* s, size_t n, mbstate_t* ps);
9318
+ size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps);
9319
+ size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps);
9320
+ size_t mbsrtowcs(wchar_t* dst, const char** src, size_t len, mbstate_t* ps);
9321
+ size_t wcsrtombs(char* dst, const wchar_t** src, size_t len, mbstate_t* ps);
9322
+ }
9323
+
9324
+ #define NULL see [support.types.nullptr] // freestanding
9325
+ #define WCHAR_MAX see below // freestanding
9326
+ #define WCHAR_MIN see below // freestanding
9327
+ #define WEOF see below // freestanding
9328
+ #define WCHAR_WIDTH see below // freestanding
9329
+ ```
9330
+
9331
+ The contents and meaning of the header `<cwchar>` are the same as the C
9332
+ standard library header `<wchar.h>`, except that it does not declare a
9333
+ type `wchar_t`.
9334
+
9335
+ [*Note 1*: The functions `wcschr`, `wcspbrk`, `wcsrchr`, `wcsstr`, and
9336
+ `wmemchr` have different signatures in this document, but they have the
9337
+ same behavior as in the C standard library [[library.c]]. — *end note*]
9338
+
9339
+ See also: ISO C 7.31
9340
+
9341
+ ### Header `<cuchar>` synopsis <a id="cuchar.syn">[[cuchar.syn]]</a>
9342
+
9343
+ ``` cpp
9344
+ #define __STDC_VERSION_UCHAR_H__ 202311L
9345
+
9346
+ namespace std {
9347
+ using mbstate_t = see below;
9348
+ using size_t = see [support.types.layout];
9349
+
9350
+ size_t mbrtoc8(char8_t* pc8, const char* s, size_t n, mbstate_t* ps);
9351
+ size_t c8rtomb(char* s, char8_t c8, mbstate_t* ps);
9352
+ size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps);
9353
+ size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps);
9354
+ size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps);
9355
+ size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps);
9356
+ }
9357
+ ```
9358
+
9359
+ The contents and meaning of the header `<cuchar>` are the same as the C
9360
+ standard library header `<uchar.h>`, except that it does not declare
9361
+ types `char8_t`, `char16_t`, or `char32_t`.
9362
+
9363
+ See also: ISO C 7.30
9364
+
9365
+ ### Multibyte / wide string and character conversion functions <a id="c.mb.wcs">[[c.mb.wcs]]</a>
9366
+
9367
+ [*Note 1*: The headers `<cstdlib>`, `<cuchar>`, and `<cwchar>` declare
9368
+ the functions described in this subclause. — *end note*]
9369
+
9370
+ ``` cpp
9371
+ int mbsinit(const mbstate_t* ps);
9372
+ int mblen(const char* s, size_t n);
9373
+ size_t mbstowcs(wchar_t* pwcs, const char* s, size_t n);
9374
+ size_t wcstombs(char* s, const wchar_t* pwcs, size_t n);
9375
+ ```
9376
+
9377
+ *Effects:* These functions have the semantics specified in the C
9378
+ standard library.
9379
+
9380
+ See also: ISO C 7.24.8.2, 7.24.9, 7.31.6.3.1
9381
+
9382
+ ``` cpp
9383
+ int mbtowc(wchar_t* pwc, const char* s, size_t n);
9384
+ int wctomb(char* s, wchar_t wchar);
9385
+ ```
9386
+
9387
+ *Effects:* These functions have the semantics specified in the C
9388
+ standard library.
9389
+
9390
+ *Remarks:* Calls to these functions may introduce a data
9391
+ race [[res.on.data.races]] with other calls to the same function.
9392
+
9393
+ See also: ISO C 7.24.8
9394
+
9395
+ ``` cpp
9396
+ size_t mbrlen(const char* s, size_t n, mbstate_t* ps);
9397
+ size_t mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps);
9398
+ size_t wcrtomb(char* s, wchar_t wc, mbstate_t* ps);
9399
+ size_t mbrtoc8(char8_t* pc8, const char* s, size_t n, mbstate_t* ps);
9400
+ size_t c8rtomb(char* s, char8_t c8, mbstate_t* ps);
9401
+ size_t mbrtoc16(char16_t* pc16, const char* s, size_t n, mbstate_t* ps);
9402
+ size_t c16rtomb(char* s, char16_t c16, mbstate_t* ps);
9403
+ size_t mbrtoc32(char32_t* pc32, const char* s, size_t n, mbstate_t* ps);
9404
+ size_t c32rtomb(char* s, char32_t c32, mbstate_t* ps);
9405
+ size_t mbsrtowcs(wchar_t* dst, const char** src, size_t len, mbstate_t* ps);
9406
+ size_t wcsrtombs(char* dst, const wchar_t** src, size_t len, mbstate_t* ps);
9407
+ ```
9408
+
9409
+ *Effects:* These functions have the semantics specified in the C
9410
+ standard library.
9411
+
9412
+ *Remarks:* Calling these functions with an `mbstate_t*` argument that is
9413
+ a null pointer value may introduce a data race [[res.on.data.races]]
9414
+ with other calls to the same function with an `mbstate_t*` argument that
9415
+ is a null pointer value.
9416
+
9417
+ See also: ISO C 7.30.2, 7.31.6.4, 7.31.6.5
9418
+
9419
+ <!-- Link reference definitions -->
9420
+ [alg.lex.comparison]: algorithms.md#alg.lex.comparison
9421
+ [alg.sort]: algorithms.md#alg.sort
9422
+ [algorithms]: algorithms.md#algorithms
9423
+ [algorithms.requirements]: algorithms.md#algorithms.requirements
9424
+ [basic.fundamental]: basic.md#basic.fundamental
9425
+ [basic.start.static]: basic.md#basic.start.static
9426
+ [bitmask.types]: library.md#bitmask.types
9427
+ [c.files]: input.md#c.files
9428
+ [c.locales]: #c.locales
9429
+ [c.mb.wcs]: #c.mb.wcs
9430
+ [category.collate]: #category.collate
9431
+ [category.ctype]: #category.ctype
9432
+ [category.ctype.general]: #category.ctype.general
9433
+ [category.messages]: #category.messages
9434
+ [category.messages.general]: #category.messages.general
9435
+ [category.monetary]: #category.monetary
9436
+ [category.monetary.general]: #category.monetary.general
9437
+ [category.numeric]: #category.numeric
9438
+ [category.numeric.general]: #category.numeric.general
9439
+ [category.time]: #category.time
9440
+ [category.time.general]: #category.time.general
9441
+ [cctype.syn]: #cctype.syn
9442
+ [character.seq.general]: library.md#character.seq.general
9443
+ [charconv]: #charconv
9444
+ [charconv.from.chars]: #charconv.from.chars
9445
+ [charconv.syn]: #charconv.syn
9446
+ [charconv.to.chars]: #charconv.to.chars
9447
+ [classification]: #classification
9448
+ [clocale.data.races]: #clocale.data.races
9449
+ [clocale.syn]: #clocale.syn
9450
+ [container.alloc.reqmts]: containers.md#container.alloc.reqmts
9451
+ [container.reqmts]: containers.md#container.reqmts
9452
+ [container.requirements.general]: containers.md#container.requirements.general
9453
+ [conversions.character]: #conversions.character
9454
+ [cpp17.copyassignable]: #cpp17.copyassignable
9455
+ [cpp17.copyconstructible]: #cpp17.copyconstructible
9456
+ [cpp17.defaultconstructible]: #cpp17.defaultconstructible
9457
+ [cpp17.destructible]: #cpp17.destructible
9458
+ [cuchar.syn]: #cuchar.syn
9459
+ [cwchar.syn]: #cwchar.syn
9460
+ [cwctype.syn]: #cwctype.syn
9461
+ [defns.character.container]: intro.md#defns.character.container
9462
+ [defns.ntcts]: intro.md#defns.ntcts
9463
+ [enumerated.types]: library.md#enumerated.types
9464
+ [expr.const]: expr.md#expr.const
9465
+ [facet.ctype.char.dtor]: #facet.ctype.char.dtor
9466
+ [facet.ctype.char.members]: #facet.ctype.char.members
9467
+ [facet.ctype.char.statics]: #facet.ctype.char.statics
9468
+ [facet.ctype.char.virtuals]: #facet.ctype.char.virtuals
9469
+ [facet.ctype.special]: #facet.ctype.special
9470
+ [facet.ctype.special.general]: #facet.ctype.special.general
9471
+ [facet.num.get.members]: #facet.num.get.members
9472
+ [facet.num.get.virtuals]: #facet.num.get.virtuals
9473
+ [facet.num.put.members]: #facet.num.put.members
9474
+ [facet.num.put.virtuals]: #facet.num.put.virtuals
9475
+ [facet.numpunct]: #facet.numpunct
9476
+ [facet.numpunct.members]: #facet.numpunct.members
9477
+ [facet.numpunct.virtuals]: #facet.numpunct.virtuals
9478
+ [file.streams]: input.md#file.streams
9479
+ [format]: #format
9480
+ [format.align]: #format.align
9481
+ [format.arg]: #format.arg
9482
+ [format.arg.store]: #format.arg.store
9483
+ [format.args]: #format.args
9484
+ [format.arguments]: #format.arguments
9485
+ [format.context]: #format.context
9486
+ [format.err.report]: #format.err.report
9487
+ [format.error]: #format.error
9488
+ [format.escape.sequences]: #format.escape.sequences
9489
+ [format.fmt.string]: #format.fmt.string
9490
+ [format.formattable]: #format.formattable
9491
+ [format.formatter]: #format.formatter
9492
+ [format.formatter.locking]: #format.formatter.locking
9493
+ [format.formatter.spec]: #format.formatter.spec
9494
+ [format.functions]: #format.functions
9495
+ [format.parse.ctx]: #format.parse.ctx
9496
+ [format.range]: #format.range
9497
+ [format.range.fmtdef]: #format.range.fmtdef
9498
+ [format.range.fmtkind]: #format.range.fmtkind
9499
+ [format.range.fmtmap]: #format.range.fmtmap
9500
+ [format.range.fmtset]: #format.range.fmtset
9501
+ [format.range.fmtstr]: #format.range.fmtstr
9502
+ [format.range.formatter]: #format.range.formatter
9503
+ [format.sign]: #format.sign
9504
+ [format.string]: #format.string
9505
+ [format.string.escaped]: #format.string.escaped
9506
+ [format.string.general]: #format.string.general
9507
+ [format.string.std]: #format.string.std
9508
+ [format.syn]: #format.syn
9509
+ [format.tuple]: #format.tuple
9510
+ [format.type.bool]: #format.type.bool
9511
+ [format.type.char]: #format.type.char
9512
+ [format.type.float]: #format.type.float
9513
+ [format.type.int]: #format.type.int
9514
+ [format.type.ptr]: #format.type.ptr
9515
+ [format.type.string]: #format.type.string
9516
+ [formatter]: #formatter
9517
+ [formatter.basic]: #formatter.basic
9518
+ [formatter.range.type]: #formatter.range.type
9519
+ [formatter.requirements]: #formatter.requirements
9520
+ [formatter.tuple.type]: #formatter.tuple.type
9521
+ [forward.iterators]: iterators.md#forward.iterators
9522
+ [input.iterators]: iterators.md#input.iterators
9523
+ [ios.base]: input.md#ios.base
9524
+ [istream.formatted]: input.md#istream.formatted
9525
+ [istream.formatted.reqmts]: input.md#istream.formatted.reqmts
9526
+ [iterator.concept.bidir]: iterators.md#iterator.concept.bidir
9527
+ [iterator.concept.output]: iterators.md#iterator.concept.output
9528
+ [iterator.requirements]: iterators.md#iterator.requirements
9529
+ [iterator.requirements.general]: iterators.md#iterator.requirements.general
9530
+ [lex.charset]: lex.md#lex.charset
9531
+ [lex.string.literal]: lex.md#lex.string.literal
9532
+ [library.c]: library.md#library.c
9533
+ [locale]: #locale
9534
+ [locale.categories]: #locale.categories
9535
+ [locale.categories.general]: #locale.categories.general
9536
+ [locale.category]: #locale.category
9537
+ [locale.category.facets]: #locale.category.facets
9538
+ [locale.codecvt]: #locale.codecvt
9539
+ [locale.codecvt.byname]: #locale.codecvt.byname
9540
+ [locale.codecvt.general]: #locale.codecvt.general
9541
+ [locale.codecvt.inout]: #locale.codecvt.inout
9542
+ [locale.codecvt.members]: #locale.codecvt.members
9543
+ [locale.codecvt.unshift]: #locale.codecvt.unshift
9544
+ [locale.codecvt.virtuals]: #locale.codecvt.virtuals
9545
+ [locale.collate]: #locale.collate
9546
+ [locale.collate.byname]: #locale.collate.byname
9547
+ [locale.collate.general]: #locale.collate.general
9548
+ [locale.collate.members]: #locale.collate.members
9549
+ [locale.collate.virtuals]: #locale.collate.virtuals
9550
+ [locale.cons]: #locale.cons
9551
+ [locale.convenience]: #locale.convenience
9552
+ [locale.ctype]: #locale.ctype
9553
+ [locale.ctype.byname]: #locale.ctype.byname
9554
+ [locale.ctype.general]: #locale.ctype.general
9555
+ [locale.ctype.members]: #locale.ctype.members
9556
+ [locale.ctype.virtuals]: #locale.ctype.virtuals
9557
+ [locale.facet]: #locale.facet
9558
+ [locale.general]: #locale.general
9559
+ [locale.global.templates]: #locale.global.templates
9560
+ [locale.id]: #locale.id
9561
+ [locale.members]: #locale.members
9562
+ [locale.messages]: #locale.messages
9563
+ [locale.messages.byname]: #locale.messages.byname
9564
+ [locale.messages.general]: #locale.messages.general
9565
+ [locale.messages.members]: #locale.messages.members
9566
+ [locale.messages.virtuals]: #locale.messages.virtuals
9567
+ [locale.money.get]: #locale.money.get
9568
+ [locale.money.get.general]: #locale.money.get.general
9569
+ [locale.money.get.members]: #locale.money.get.members
9570
+ [locale.money.get.virtuals]: #locale.money.get.virtuals
9571
+ [locale.money.put]: #locale.money.put
9572
+ [locale.money.put.general]: #locale.money.put.general
9573
+ [locale.money.put.members]: #locale.money.put.members
9574
+ [locale.money.put.virtuals]: #locale.money.put.virtuals
9575
+ [locale.moneypunct]: #locale.moneypunct
9576
+ [locale.moneypunct.byname]: #locale.moneypunct.byname
9577
+ [locale.moneypunct.general]: #locale.moneypunct.general
9578
+ [locale.moneypunct.members]: #locale.moneypunct.members
9579
+ [locale.moneypunct.virtuals]: #locale.moneypunct.virtuals
9580
+ [locale.nm.put]: #locale.nm.put
9581
+ [locale.nm.put.general]: #locale.nm.put.general
9582
+ [locale.num.get]: #locale.num.get
9583
+ [locale.num.get.general]: #locale.num.get.general
9584
+ [locale.numpunct]: #locale.numpunct
9585
+ [locale.numpunct.byname]: #locale.numpunct.byname
9586
+ [locale.numpunct.general]: #locale.numpunct.general
9587
+ [locale.operators]: #locale.operators
9588
+ [locale.spec]: #locale.spec
9589
+ [locale.statics]: #locale.statics
9590
+ [locale.syn]: #locale.syn
9591
+ [locale.time.get]: #locale.time.get
9592
+ [locale.time.get.byname]: #locale.time.get.byname
9593
+ [locale.time.get.dogetdate]: #locale.time.get.dogetdate
9594
+ [locale.time.get.general]: #locale.time.get.general
9595
+ [locale.time.get.members]: #locale.time.get.members
9596
+ [locale.time.get.virtuals]: #locale.time.get.virtuals
9597
+ [locale.time.put]: #locale.time.put
9598
+ [locale.time.put.byname]: #locale.time.put.byname
9599
+ [locale.time.put.general]: #locale.time.put.general
9600
+ [locale.time.put.members]: #locale.time.put.members
9601
+ [locale.time.put.virtuals]: #locale.time.put.virtuals
9602
+ [locale.types]: #locale.types
9603
+ [locales]: #locales
9604
+ [localization]: #localization
9605
+ [localization.general]: #localization.general
9606
+ [localization.summary]: #localization.summary
9607
+ [namespace.std]: library.md#namespace.std
9608
+ [ostream.formatted.reqmts]: input.md#ostream.formatted.reqmts
9609
+ [output.iterators]: iterators.md#output.iterators
9610
+ [re]: #re
9611
+ [re.alg]: #re.alg
9612
+ [re.alg.match]: #re.alg.match
9613
+ [re.alg.replace]: #re.alg.replace
9614
+ [re.alg.search]: #re.alg.search
9615
+ [re.badexp]: #re.badexp
9616
+ [re.const]: #re.const
9617
+ [re.const.general]: #re.const.general
9618
+ [re.err]: #re.err
9619
+ [re.except]: #re.except
9620
+ [re.general]: #re.general
9621
+ [re.grammar]: #re.grammar
9622
+ [re.iter]: #re.iter
9623
+ [re.matchflag]: #re.matchflag
9624
+ [re.regex]: #re.regex
9625
+ [re.regex.assign]: #re.regex.assign
9626
+ [re.regex.construct]: #re.regex.construct
9627
+ [re.regex.general]: #re.regex.general
9628
+ [re.regex.locale]: #re.regex.locale
9629
+ [re.regex.nonmemb]: #re.regex.nonmemb
9630
+ [re.regex.operations]: #re.regex.operations
9631
+ [re.regex.swap]: #re.regex.swap
9632
+ [re.regiter]: #re.regiter
9633
+ [re.regiter.cnstr]: #re.regiter.cnstr
9634
+ [re.regiter.comp]: #re.regiter.comp
9635
+ [re.regiter.deref]: #re.regiter.deref
9636
+ [re.regiter.general]: #re.regiter.general
9637
+ [re.regiter.incr]: #re.regiter.incr
9638
+ [re.req]: #re.req
9639
+ [re.results]: #re.results
9640
+ [re.results.acc]: #re.results.acc
9641
+ [re.results.all]: #re.results.all
9642
+ [re.results.const]: #re.results.const
9643
+ [re.results.form]: #re.results.form
9644
+ [re.results.general]: #re.results.general
9645
+ [re.results.nonmember]: #re.results.nonmember
9646
+ [re.results.size]: #re.results.size
9647
+ [re.results.state]: #re.results.state
9648
+ [re.results.swap]: #re.results.swap
9649
+ [re.submatch]: #re.submatch
9650
+ [re.submatch.general]: #re.submatch.general
9651
+ [re.submatch.members]: #re.submatch.members
9652
+ [re.submatch.op]: #re.submatch.op
9653
+ [re.summary]: #re.summary
9654
+ [re.syn]: #re.syn
9655
+ [re.synopt]: #re.synopt
9656
+ [re.tokiter]: #re.tokiter
9657
+ [re.tokiter.cnstr]: #re.tokiter.cnstr
9658
+ [re.tokiter.comp]: #re.tokiter.comp
9659
+ [re.tokiter.deref]: #re.tokiter.deref
9660
+ [re.tokiter.general]: #re.tokiter.general
9661
+ [re.tokiter.incr]: #re.tokiter.incr
9662
+ [re.traits]: #re.traits
9663
+ [re.traits.classnames]: #re.traits.classnames
9664
+ [res.on.data.races]: library.md#res.on.data.races
9665
+ [res.on.exception.handling]: library.md#res.on.exception.handling
9666
+ [round.style]: support.md#round.style
9667
+ [sequence.reqmts]: containers.md#sequence.reqmts
9668
+ [setlocale.data.races]: #setlocale.data.races
9669
+ [strings.general]: strings.md#strings.general
9670
+ [support.runtime]: support.md#support.runtime
9671
+ [swappable.requirements]: library.md#swappable.requirements
9672
+ [tab:locale.category.facets]: #tab:locale.category.facets
9673
+ [tab:locale.spec]: #tab:locale.spec
9674
+ [term.trivially.copyable.type]: basic.md#term.trivially.copyable.type
9675
+ [text]: #text
9676
+ [text.c.strings]: #text.c.strings
9677
+ [text.encoding]: #text.encoding
9678
+ [text.encoding.aliases]: #text.encoding.aliases
9679
+ [text.encoding.class]: #text.encoding.class
9680
+ [text.encoding.cmp]: #text.encoding.cmp
9681
+ [text.encoding.general]: #text.encoding.general
9682
+ [text.encoding.hash]: #text.encoding.hash
9683
+ [text.encoding.id]: #text.encoding.id
9684
+ [text.encoding.members]: #text.encoding.members
9685
+ [text.encoding.overview]: #text.encoding.overview
9686
+ [text.encoding.syn]: #text.encoding.syn
9687
+ [text.general]: #text.general
9688
+ [text.summary]: #text.summary
9689
+ [time.format]: time.md#time.format
9690
+ [unord.hash]: utilities.md#unord.hash
9691
+ [vector]: containers.md#vector
9692
+
9693
+ [^1]: In this subclause, the type name `tm` is an incomplete type that
9694
+ is defined in `<ctime>`.
9695
+
9696
+ [^2]: Note that in the call to `put`, the stream is implicitly converted
9697
+ to an `ostreambuf_iterator<charT, traits>`.
9698
+
9699
+ [^3]: This is a complete list of requirements; there are no other
9700
+ requirements. Thus, a facet class need not have a public copy
9701
+ constructor, assignment, default constructor, destructor, etc.
9702
+
9703
+ [^4]: When used in a loop, it is faster to cache the `ctype<>` facet and
9704
+ use it directly, or use the vector form of `ctype<>::is`.
9705
+
9706
+ [^5]: The parameter `c` of `do_widen` is intended to accept values
9707
+ derived from *character-literal*s for conversion to the locale’s
9708
+ encoding.
9709
+
9710
+ [^6]: In other words, the transformed character is not a member of any
9711
+ character classification that `c` is not also a member of.
9712
+
9713
+ [^7]: Only the `char` (not `unsigned char` and `signed char`) form is
9714
+ provided. The specialization is specified in the standard, and not
9715
+ left as an implementation detail, because it affects the derivation
9716
+ interface for `ctype<char>`.
9717
+
9718
+ [^8]: Informally, this means that `basic_filebuf` assumes that the
9719
+ mappings from internal to external characters is 1 to N: that a
9720
+ `codecvt` facet that is used by `basic_filebuf` can translate
9721
+ characters one internal character at a time.
9722
+
9723
+ [^9]: Typically these will be characters to return the state to
9724
+ `stateT()`.
9725
+
9726
+ [^10]: If `encoding()` yields `-1`, then more than `max_length()`
9727
+ `externT` elements can be consumed when producing a single `internT`
9728
+ character, and additional `externT` elements can appear at the end
9729
+ of a sequence after those that yield the final `internT` character.
9730
+
9731
+ [^11]: Parsing `"-1"` correctly into, e.g., an `unsigned short` requires
9732
+ that the corresponding member `get()` at least extract the sign
9733
+ before delegating.
9734
+
9735
+ [^12]: The conversion specification `#o` generates a leading `0` which
9736
+ is *not* a padding character.
9737
+
9738
+ [^13]: Thus, the string `"\003"` specifies groups of 3 digits each, and
9739
+ `"3"` probably indicates groups of 51 (!) digits each, because 51 is
9740
+ the ASCII value of `"3"`.
9741
+
9742
+ [^14]: This function is useful when one string is being compared to many
9743
+ other strings.
9744
+
9745
+ [^15]: In other words, user confirmation is required for reliable
9746
+ parsing of user-entered dates and times, but machine-generated
9747
+ formats can be parsed reliably. This allows parsers to be aggressive
9748
+ about interpreting user variations on standard formats.
9749
+
9750
+ [^16]: This function is intended as a convenience only, for common
9751
+ formats, and can return `no_order` in valid locales.
9752
+
9753
+ [^17]: The semantics here are different from `ct.narrow`.
9754
+
9755
+ [^18]: An array of `char`, rather than an array of `part`, is specified
9756
+ for `pattern::field` purely for efficiency.
9757
+
9758
+ [^19]: In common U.S. locales this is `’.’`.
9759
+
9760
+ [^20]: In common U.S. locales this is `’,’`.
9761
+
9762
+ [^21]: To specify grouping by 3s, the value is `"\003"` *not* `"3"`.
9763
+
9764
+ [^22]: This is usually the empty string.
9765
+
9766
+ [^23]: In common U.S. locales, this is 2.
9767
+
9768
+ [^24]: Note that the international symbol returned by `do_curr_symbol()`
9769
+ usually contains a space, itself; for example, `"USD "`.
9770
+
9771
+ [^25]: Windows® is a registered trademark of Microsoft Corporation. This
9772
+ information is given for the convenience of users of this document
9773
+ and does not constitute an endorsement by ISO or IEC of this
9774
+ product.
9775
+
9776
+ [^26]: For example, if the parameter `icase` is `true` then
9777
+ `[[:lower:]]` is the same as `[[:alpha:]]`.