clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name backward.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/data/b2soft/buildbot/development/build -fcoverage-compilation-dir=/data/b2soft/buildbot/development/build -resource-dir /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++ -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/x86_64-redhat-linux -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/backward -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/python3.12 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/CLHEP -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/Geant4 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/root -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/belle_legacy -I include/ -D _PACKAGE_="ecl" -D G4UI_USE_TCSH -D RaveDllExport= -D HAS_SQLITE -D HAS_CALLGRIND -I include -I /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/libxml2 -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++ -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/x86_64-redhat-linux -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/backward -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-missing-braces -Wno-unused-command-line-argument -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /scan_build/2026-05-31-004316-385593-1 -x c++ ecl/geometry/src/backward.cc
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | #include <ecl/geometry/GeoECLCreator.h> |
| 11 | |
| 12 | |
| 13 | #include <ecl/dataobjects/ECLElementNumbers.h> |
| 14 | #include <ecl/geometry/BelleLathe.h> |
| 15 | #include <ecl/geometry/BelleCrystal.h> |
| 16 | #include <ecl/geometry/shapes.h> |
| 17 | |
| 18 | |
| 19 | #include <geometry/Materials.h> |
| 20 | |
| 21 | |
| 22 | #include <G4AssemblyVolume.hh> |
| 23 | #include <G4Box.hh> |
| 24 | #include <G4LogicalVolume.hh> |
| 25 | #include <G4PVPlacement.hh> |
| 26 | #include <G4PVReplica.hh> |
| 27 | #include <G4Region.hh> |
| 28 | #include <G4Trap.hh> |
| 29 | #include <G4TwoVector.hh> |
| 30 | #include <G4VisAttributes.hh> |
| 31 | |
| 32 | |
| 33 | #include <CLHEP/Matrix/Vector.h> |
| 34 | |
| 35 | |
| 36 | #include <iostream> |
| 37 | |
| 38 | using namespace std; |
| 39 | using namespace Belle2; |
| 40 | using namespace Belle2::geometry; |
| 41 | |
| 42 | void Belle2::ECL::GeoECLCreator::backward(G4LogicalVolume& _top) |
| 43 | { |
| 44 | G4LogicalVolume* top = &_top; |
| 45 | |
| 46 | const bool sec = 0; |
| 47 | const double phi0 = 0; |
| 48 | const double dphi = sec ? M_PI / 16 : 2 * M_PI; |
| |
| 49 | |
| 50 | const bool b_inner_support_ring = true; |
| 51 | const bool b_outer_support_ring = true; |
| 52 | const bool b_support_wall = true; |
| 53 | const bool b_ribs = true; |
| 54 | const bool b_septum_wall = true; |
| 55 | const bool b_crystals = true; |
| 56 | const bool b_preamplifier = true; |
| 57 | const bool b_support_leg = true; |
| 58 | const int overlap = m_overlap; |
| 59 | |
| 60 | int npoints = 1000 * 1000; |
| 61 | |
| 62 | |
| 63 | vector<cplacement_t> bp = load_placements(m_sap, ECLParts::backward); |
| 64 | vector<cplacement_t>::iterator fp = find_if(bp.begin(), bp.end(), [](const cplacement_t& p) { |
| 65 | const int ECL_backward_part = 1000; |
| 66 | return p.nshape == ECL_backward_part; |
| 67 | }); |
| 68 | |
| 69 | G4Transform3D gTrans = (fp == bp.end()) ? G4Translate3D(0, 0, -1020) : get_transform(*fp); |
| |
| 70 | if (fp != bp.end()) bp.erase(fp); |
| 3 | | Assuming the condition is false | |
|
| |
| 71 | |
| 72 | if (b_inner_support_ring) { |
| |
| 73 | zr_t vc1[] = {{0., 452.3 + 3}, {0., 452.3}, {3., 474.9 - 20 / cosd(27.81)}, {434., 702.27 - 20 / cosd(27.81)}, {434., 702.27}, {3., 474.9}, {3., 452.3 + 3}}; |
| 74 | std::vector<zr_t> contour1(vc1, vc1 + sizeof(vc1) / sizeof(zr_t)); |
| 75 | G4VSolid* part1solid = new BelleLathe("part1solid", phi0, dphi, contour1); |
| 76 | G4LogicalVolume* part1logical = new G4LogicalVolume(part1solid, Materials::get("SUS304"), "part1logical", 0, 0, 0); |
| 77 | part1logical->SetVisAttributes(att("iron")); |
| 78 | auto pv = new G4PVPlacement(gTrans * G4RotateY3D(M_PI), part1logical, "ECL_BackwardSupport_part1physical", top, false, 0, 0); |
| 79 | if (overlap) pv->CheckOverlaps(npoints); |
| |
| |
| 80 | } |
| 81 | |
| 82 | if (b_support_wall) { |
| |
| 83 | |
| 84 | double L = (435 - 202.67 - 3 - 1.6 * cosd(52.90 + 90)) / cosd(52.90); |
| 85 | zr_t vc23[] = {{0, 452.3 + 3}, {3, 452.3 + 3}, {3, 1190.2}, {3 + L * cosd(52.90), 1190.2 + L * sind(52.90)}, |
| 86 | {3 + L * cosd(52.90) + 1.6 * cosd(52.90 + 90), 1190.2 + L * sind(52.90) + 1.6 * sind(52.90 + 90)}, {3 + 1.6 * cosd(52.90 + 90), 1190.2 + 1.6 * sind(52.90 + 90)}, {0, 1190.2} |
| 87 | }; |
| 88 | std::vector<zr_t> contour23(vc23, vc23 + sizeof(vc23) / sizeof(zr_t)); |
| 89 | G4VSolid* part23solid = new BelleLathe("part23solid", phi0, dphi, contour23); |
| 90 | G4LogicalVolume* part23logical = new G4LogicalVolume(part23solid, Materials::get("A5052"), "part23logical", 0, 0, 0); |
| 91 | part23logical->SetVisAttributes(att("alum")); |
| 92 | auto pv = new G4PVPlacement(gTrans * G4RotateY3D(M_PI), part23logical, "ECL_BackwardSupport_part23physical", top, false, 0, 0); |
| 93 | if (overlap) pv->CheckOverlaps(npoints); |
| |
| 94 | } |
| 95 | |
| 96 | if (b_outer_support_ring) { |
| |
| 97 | zr_t vc4[] = {{434 - 214.8, 1496 - 20}, {434, 1496 - 20}, {434, 1496 - 5}, {434 + 5, 1496 - 5}, {434 + 5, 1496}, {434 - 199.66, 1496}}; |
| 98 | std::vector<zr_t> contour4(vc4, vc4 + sizeof(vc4) / sizeof(zr_t)); |
| 99 | G4VSolid* part4solid = new BelleLathe("part4solid", phi0, dphi, contour4); |
| 100 | G4LogicalVolume* part4logical = new G4LogicalVolume(part4solid, Materials::get("SUS304"), "part4logical", 0, 0, 0); |
| 101 | part4logical->SetVisAttributes(att("iron")); |
| 102 | auto pv = new G4PVPlacement(gTrans * G4RotateY3D(M_PI), part4logical, "ECL_BackwardSupport_part4physical", top, false, 0, 0); |
| 103 | if (overlap) pv->CheckOverlaps(npoints); |
| |
| 104 | } |
| 105 | |
| 106 | zr_t cont_array_in[] = {{3., 474.9}, {434., 702.27}, {434, 1496 - 20}, {434 - 214.8, 1496 - 20}, {3, 1190.2}}; |
| 107 | std::vector<zr_t> contour_in(cont_array_in, cont_array_in + sizeof(cont_array_in) / sizeof(zr_t)); |
| 108 | G4VSolid* innervolume_solid = new BelleLathe("innervolume_solid", 0, 2 * M_PI, contour_in); |
| 109 | G4LogicalVolume* innervolume_logical = new G4LogicalVolume(innervolume_solid, Materials::get("G4_AIR"), |
| 110 | "innervolume_logical", 0, 0, 0); |
| 111 | innervolume_logical->SetVisAttributes(att("air")); |
| 112 | |
| 113 | |
| 114 | G4Region* aRegion = new G4Region("ECLBackwardEnvelope"); |
| 115 | innervolume_logical->SetRegion(aRegion); |
| 116 | aRegion->AddRootLogicalVolume(innervolume_logical); |
| 117 | |
| 118 | auto gpvbp = new G4PVPlacement(gTrans * G4RotateY3D(M_PI), |
| 119 | innervolume_logical, "ECLBackwardPhysical", |
| 120 | top, false, 0, 0); |
| 121 | if (overlap) gpvbp->CheckOverlaps(npoints); |
| |
| 122 | |
| 123 | G4VSolid* innervolumesector_solid = new BelleLathe("innervolumesector_solid", -M_PI / 8, M_PI / 4, contour_in); |
| 124 | G4LogicalVolume* innervolumesector_logical = new G4LogicalVolume(innervolumesector_solid, Materials::get("G4_AIR"), |
| 125 | "innervolumesector_logical", 0, 0, 0); |
| 126 | innervolumesector_logical->SetVisAttributes(att("air")); |
| 127 | new G4PVReplica("ECLBackwardSectorPhysical", innervolumesector_logical, innervolume_logical, kPhi, 8, M_PI / 4, 0); |
| 128 | |
| 129 | if (b_ribs) { |
| |
| 130 | double H = 60, W = 20; |
| 131 | double X0 = 702.27 + 0.001, X1 = 1496 - 20; |
| 132 | G4TwoVector r0o(X1, 0), r1o(X1 * sqrt(1 - pow(W / X1, 2)), W); |
| 133 | double beta = asin(W / X0); |
| 134 | G4TwoVector r0i(X0 / cos(beta / 2), 0), r1i(X0 * cos(beta / 2) - tan(beta / 2) * (W - X0 * sin(beta / 2)), W); |
| 135 | double dxymzp = (r0o - r0i).x(), dxypzp = (r1o - r1i).x(); |
| 136 | double theta = atan(tand(27.81) / 2); |
| 137 | double dxymzm = dxymzp + tand(27.81) * H, dxypzm = dxypzp + tand(27.81) * H; |
| 138 | |
| 139 | G4TwoVector m0 = (r0i + r0o) * 0.5, m1 = (r1i + r1o) * 0.5, dm = m1 - m0; |
| 140 | double alpha = atan(dm.x() / dm.y()); |
| 141 | |
| 142 | G4VSolid* solid6_p1 = new G4Trap("solid6_p1", H / 2, theta, 0, W / 2, dxymzm / 2, dxypzm / 2, alpha, W / 2, dxymzp / 2, dxypzp / 2, |
| 143 | alpha); |
| 144 | G4LogicalVolume* lsolid6_p1 = new G4LogicalVolume(solid6_p1, Materials::get("SUS304"), "lsolid6", 0, 0, 0); |
| 145 | lsolid6_p1->SetVisAttributes(att("asolid6")); |
| 146 | G4Transform3D tsolid6_p1(G4Translate3D(X0 * cos(beta / 2) + (dxymzp / 2 + dxypzp / 2) / 2 - tan(theta)*H / 2, W / 2, 434 - H / 2)); |
| 147 | auto pv61 = new G4PVPlacement(G4RotateZ3D(-M_PI / 8)*tsolid6_p1, lsolid6_p1, "psolid6_p1", innervolumesector_logical, false, 0, 0); |
| 148 | if (overlap) pv61->CheckOverlaps(npoints); |
| |
| 149 | auto pv62 = new G4PVPlacement(G4RotateZ3D(0)*tsolid6_p1, lsolid6_p1, "psolid6_p2", innervolumesector_logical, false, 0, 0); |
| 150 | if (overlap) pv62->CheckOverlaps(npoints); |
| |
| 151 | |
| 152 | H = 40; |
| 153 | dxymzm = dxymzp + tand(27.81) * H, dxypzm = dxypzp + tand(27.81) * H; |
| 154 | G4VSolid* solid6_p2 = new G4Trap("solid6_p2", H / 2, theta, 0, W / 2, dxypzm / 2, dxymzm / 2, -alpha, W / 2, dxypzp / 2, dxymzp / 2, |
| 155 | -alpha); |
| 156 | G4LogicalVolume* lsolid6_p2 = new G4LogicalVolume(solid6_p2, Materials::get("SUS304"), "lsolid6", 0, 0, 0); |
| 157 | lsolid6_p2->SetVisAttributes(att("asolid6")); |
| 158 | G4Transform3D tsolid6_p2(G4Translate3D(X0 * cos(beta / 2) + (dxymzp / 2 + dxypzp / 2) / 2 - tan(theta)*H / 2, -W / 2, 434 - H / 2)); |
| 159 | auto pv63 = new G4PVPlacement(G4RotateZ3D(0)*tsolid6_p2, lsolid6_p2, "psolid6_p3", innervolumesector_logical, false, 0, 0); |
| 160 | if (overlap) pv63->CheckOverlaps(npoints); |
| |
| 161 | auto pv64 = new G4PVPlacement(G4RotateZ3D(M_PI / 8)*tsolid6_p2, lsolid6_p2, "psolid6_p4", innervolumesector_logical, false, 0, 0); |
| |
| 162 | if (overlap) pv64->CheckOverlaps(npoints); |
| |
| 163 | |
| 164 | G4VSolid* solid7_p8 = new G4Box("solid7_p8", 171. / 2, (140. - 40) / 2 / 2, 40. / 2); |
| 19 | | Potential leak of memory pointed to by 'pv64' |
|
| 165 | G4LogicalVolume* lsolid7 = new G4LogicalVolume(solid7_p8, Materials::get("SUS304"), "lsolid7", 0, 0, 0); |
| 166 | lsolid7->SetVisAttributes(att("asolid7")); |
| 167 | double dx = sqrt(X1 * X1 - 70 * 70) - 171. / 2; |
| 168 | G4Transform3D tsolid7_p1(G4Translate3D(dx, -20 - 25, 434 - 40. / 2)); |
| 169 | auto pv71 = new G4PVPlacement(tsolid7_p1, lsolid7, "psolid7_p1", innervolumesector_logical, false, 0, 0); |
| 170 | if (overlap) pv71->CheckOverlaps(npoints); |
| 171 | G4Transform3D tsolid7_p2(G4Translate3D(dx, 20 + 25, 434 - 40. / 2)); |
| 172 | auto pv72 = new G4PVPlacement(tsolid7_p2, lsolid7, "psolid7_p2", innervolumesector_logical, false, 0, 0); |
| 173 | if (overlap) pv72->CheckOverlaps(npoints); |
| 174 | |
| 175 | double L = X1 - (X0 - tand(27.81) * 40) - 10; |
| 176 | G4VSolid* solid13 = new G4Box("solid13", L / 2, 5. / 2, 18. / 2); |
| 177 | G4LogicalVolume* lsolid13 = new G4LogicalVolume(solid13, Materials::get("SUS304"), "lsolid13", 0, 0, 0); |
| 178 | lsolid13->SetVisAttributes(att("asolid13")); |
| 179 | G4Transform3D tsolid13(G4TranslateZ3D(434 - 60 + 18. / 2)*G4TranslateY3D(-5. / 2 - 0.5 / 2)*G4TranslateX3D(X0 - tand( |
| 180 | 27.81) * 40 + L / 2 + 5)); |
| 181 | auto pv131 = new G4PVPlacement(tsolid13, lsolid13, "psolid13_p1", innervolumesector_logical, false, 0, 0); |
| 182 | if (overlap) pv131->CheckOverlaps(npoints); |
| 183 | auto pv132 = new G4PVPlacement(G4RotateZ3D(M_PI / 8)*tsolid13, lsolid13, "psolid13_p2", innervolumesector_logical, false, 0, 0); |
| 184 | if (overlap) pv132->CheckOverlaps(npoints); |
| 185 | } |
| 186 | |
| 187 | |
| 188 | double zsep = 135; |
| 189 | if (b_septum_wall) { |
| 190 | double d = 5; |
| 191 | Point_t vin[] = {{434. - zsep, 702.27 - tand(27.81)* zsep}, {434. - 60, 702.27 - tand(27.81) * 60}, {434. - 60, 1496 - 20 - d}, {434. - zsep, 1496 - 20 - d}}; |
| 192 | const int n = sizeof(vin) / sizeof(Point_t); |
| 193 | Point_t c = centerofgravity(vin, vin + n); |
| 194 | G4ThreeVector contour_swall[n * 2]; |
| 195 | for (int i = 0; i < n; i++) contour_swall[i + 0] = G4ThreeVector(vin[i].x - c.x, vin[i].y - c.y, -0.5 / 2); |
| 196 | for (int i = 0; i < n; i++) contour_swall[i + n] = G4ThreeVector(vin[i].x - c.x, vin[i].y - c.y, 0.5 / 2); |
| 197 | |
| 198 | G4VSolid* septumwall_solid = new BelleCrystal("septumwall_solid", n, contour_swall); |
| 199 | |
| 200 | G4LogicalVolume* septumwall_logical = new G4LogicalVolume(septumwall_solid, Materials::get("A5052"), |
| 201 | "septumwall_logical", 0, 0, 0); |
| 202 | septumwall_logical->SetVisAttributes(att("alum2")); |
| 203 | auto pv = new G4PVPlacement(G4RotateZ3D(-M_PI / 2)*G4RotateY3D(-M_PI / 2)*G4Translate3D(c.x, c.y, 0), septumwall_logical, |
| 204 | "septumwall_physical", innervolumesector_logical, false, 0, 0); |
| 205 | if (overlap) pv->CheckOverlaps(npoints); |
| 206 | |
| 207 | for (int i = 0; i < n; i++) contour_swall[i + 0] = G4ThreeVector(vin[i].x - c.x, vin[i].y - c.y, -0.5 / 2 / 2); |
| 208 | for (int i = 0; i < n; i++) contour_swall[i + n] = G4ThreeVector(vin[i].x - c.x, vin[i].y - c.y, 0.5 / 2 / 2); |
| 209 | |
| 210 | G4VSolid* septumwall2_solid = new BelleCrystal("septumwall2_solid", n, contour_swall); |
| 211 | |
| 212 | G4LogicalVolume* septumwall2_logical = new G4LogicalVolume(septumwall2_solid, Materials::get("A5052"), |
| 213 | "septumwall2_logical", 0, 0, 0); |
| 214 | septumwall2_logical->SetVisAttributes(att("alum2")); |
| 215 | auto pv0 = new G4PVPlacement(G4RotateZ3D(-M_PI / 8)*G4RotateZ3D(-M_PI / 2)*G4RotateY3D(-M_PI / 2)*G4Translate3D(c.x, c.y, |
| 216 | 0.5 / 2 / 2), |
| 217 | septumwall2_logical, "septumwall2_physical", innervolumesector_logical, false, 0, 0); |
| 218 | if (overlap) pv0->CheckOverlaps(npoints); |
| 219 | auto pv1 = new G4PVPlacement(G4RotateZ3D(M_PI / 8)*G4RotateZ3D(-M_PI / 2)*G4RotateY3D(-M_PI / 2)*G4Translate3D(c.x, c.y, |
| 220 | -0.5 / 2 / 2), |
| 221 | septumwall2_logical, "septumwall2_physical", innervolumesector_logical, false, 1, 0); |
| 222 | if (overlap) pv1->CheckOverlaps(npoints); |
| 223 | } |
| 224 | |
| 225 | zr_t vcr[] = {{3., 474.9}, {434. - zsep, 702.27 - tand(27.81)* zsep}, {434 - zsep, 1496 - 20}, {434 - 214.8, 1496 - 20}, {3, 1190.2}}; |
| 226 | std::vector<zr_t> ccr(vcr, vcr + sizeof(vcr) / sizeof(zr_t)); |
| 227 | G4VSolid* crystalvolume_solid = new BelleLathe("crystalvolume_solid", 0, M_PI / 8, ccr); |
| 228 | G4LogicalVolume* crystalvolume_logical = new G4LogicalVolume(crystalvolume_solid, Materials::get("G4_AIR"), |
| 229 | "crystalvolume_logical", 0, 0, 0); |
| 230 | crystalvolume_logical->SetVisAttributes(att("air")); |
| 231 | auto gpv0 = new G4PVPlacement(G4RotateZ3D(-M_PI / 8), crystalvolume_logical, "ECLBackwardCrystalSectorPhysical_0", |
| 232 | innervolumesector_logical, |
| 233 | false, 0, 0); |
| 234 | if (overlap) gpv0->CheckOverlaps(npoints); |
| 235 | auto gpv1 = new G4PVPlacement(G4RotateZ3D(0), crystalvolume_logical, "ECLBackwardCrystalSectorPhysical_1", |
| 236 | innervolumesector_logical, false, 1, |
| 237 | 0); |
| 238 | if (overlap) gpv1->CheckOverlaps(npoints); |
| 239 | |
| 240 | if (b_septum_wall) { |
| 241 | double d = 5, dr = 0.001; |
| 242 | Point_t vin[] = {{3., 474.9}, {434. - zsep, 702.27 - tand(27.81)* zsep}, {434 - zsep, 1496 - 20 - d - dr}, {434 - 214.8 - d / tand(52.90), 1496 - 20 - d - dr}, {3, 1190.2 - dr}}; |
| 243 | const int n = sizeof(vin) / sizeof(Point_t); |
| 244 | Point_t c = centerofgravity(vin, vin + n); |
| 245 | G4ThreeVector contour_swall[n * 2]; |
| 246 | |
| 247 | for (int i = 0; i < n; i++) contour_swall[i + 0] = G4ThreeVector(vin[i].x - c.x, vin[i].y - c.y, -0.5 / 2 / 2); |
| 248 | for (int i = 0; i < n; i++) contour_swall[i + n] = G4ThreeVector(vin[i].x - c.x, vin[i].y - c.y, 0.5 / 2 / 2); |
| 249 | |
| 250 | G4VSolid* septumwall3_solid = new BelleCrystal("septumwall3_solid", n, contour_swall); |
| 251 | |
| 252 | G4LogicalVolume* septumwall3_logical = new G4LogicalVolume(septumwall3_solid, Materials::get("A5052"), |
| 253 | "septumwall3_logical", 0, 0, 0); |
| 254 | septumwall3_logical->SetVisAttributes(att("alum2")); |
| 255 | auto pv0 = new G4PVPlacement(G4RotateZ3D(-M_PI / 2)*G4RotateY3D(-M_PI / 2)*G4Translate3D(c.x, c.y, 0.5 / 2 / 2), |
| 256 | septumwall3_logical, |
| 257 | "septumwall3_physical_0", crystalvolume_logical, false, 0, overlap); |
| 258 | if (overlap) pv0->CheckOverlaps(npoints); |
| 259 | auto pv1 = new G4PVPlacement(G4RotateZ3D(M_PI / 8)*G4RotateZ3D(-M_PI / 2)*G4RotateY3D(-M_PI / 2)*G4Translate3D(c.x, c.y, |
| 260 | -0.5 / 2 / 2), |
| 261 | septumwall3_logical, "septumwall3_physical_1", crystalvolume_logical, false, 1, overlap); |
| 262 | if (overlap) pv1->CheckOverlaps(npoints); |
| 263 | } |
| 264 | |
| 265 | if (b_crystals) { |
| 266 | |
| 267 | vector<shape_t*> cryst = load_shapes(m_sap, ECLParts::backward); |
| 268 | vector<G4LogicalVolume*> wrapped_crystals; |
| 269 | for (auto it = cryst.begin(); it != cryst.end(); it++) { |
| 270 | shape_t* s = *it; |
| 271 | wrapped_crystals.push_back(wrapped_crystal(s, "backward", 0.20 - 0.02)); |
| 272 | } |
| 273 | for (vector<cplacement_t>::const_iterator it = bp.begin(); it != bp.end(); ++it) { |
| 274 | const cplacement_t& t = *it; |
| 275 | auto s = find_if(cryst.begin(), cryst.end(), [&t](const shape_t* shape) {return shape->nshape == t.nshape;}); |
| 276 | if (s == cryst.end()) continue; |
| 277 | |
| 278 | G4Transform3D twc = G4Translate3D(0, 0, 3) * get_transform(t); |
| 279 | int indx = it - bp.begin(); |
| 280 | auto pv = new G4PVPlacement(twc, wrapped_crystals[s - cryst.begin()], suf("ECLBackwardWrappedCrystal_Physical", indx), |
| 281 | crystalvolume_logical, |
| 282 | false, (ECLElementNumbers::c_NCrystalsForwardBarrel) / 16 + indx, 0); |
| 283 | if (overlap)pv->CheckOverlaps(npoints); |
| 284 | } |
| 285 | |
| 286 | for (shape_t* shape : cryst) { |
| 287 | delete shape; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | if (b_preamplifier) { |
| 292 | for (vector<cplacement_t>::const_iterator it = bp.begin(); it != bp.end(); ++it) { |
| 293 | G4Transform3D twc = G4Translate3D(0, 0, 3) * get_transform(*it); |
| 294 | int indx = it - bp.begin(); |
| 295 | auto pv = new G4PVPlacement(twc * G4TranslateZ3D(300 / 2 + 0.20 + get_pa_box_height() / 2)*G4RotateZ3D(-M_PI / 2), get_preamp(), |
| 296 | suf("phys_backward_preamplifier", indx), crystalvolume_logical, false, (ECLElementNumbers::c_NCrystalsForwardBarrel) / 16 + indx, |
| 297 | 0); |
| 298 | if (overlap)pv->CheckOverlaps(npoints); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | if (b_support_leg) { |
| 303 | const G4VisAttributes* batt = att("iron"); |
| 304 | |
| 305 | G4VSolid* s1 = new G4Box("leg_p1", 130. / 2, 185. / 2, (40. - 5) / 2); |
| 306 | G4LogicalVolume* l1 = new G4LogicalVolume(s1, Materials::get("SUS304"), "l1", 0, 0, 0); |
| 307 | G4Transform3D t1 = G4Translate3D(0, 185. / 2, (40. - 5) / 2); |
| 308 | l1->SetVisAttributes(batt); |
| 309 | |
| 310 | Point_t v3[] = {{ -212. / 2, -135. / 2}, {212. / 2 - 30, -135. / 2}, {212. / 2, -135. / 2 + 30}, {212. / 2, 135. / 2}, { -212. / 2, 135. / 2}}; |
| 311 | const int n3 = sizeof(v3) / sizeof(Point_t); |
| 312 | G4ThreeVector c3[n3 * 2]; |
| 313 | |
| 314 | for (int i = 0; i < n3; i++) c3[i + 0] = G4ThreeVector(v3[i].x, v3[i].y, -60. / 2); |
| 315 | for (int i = 0; i < n3; i++) c3[i + n3] = G4ThreeVector(v3[i].x, v3[i].y, 60. / 2); |
| 316 | |
| 317 | G4VSolid* s3 = new BelleCrystal("leg_p3", n3, c3); |
| 318 | G4LogicalVolume* l3 = new G4LogicalVolume(s3, Materials::get("SUS304"), "l3", 0, 0, 0); |
| 319 | G4Transform3D t3 = G4Translate3D(0, 135. / 2 + 35, 40. - 5. + 212. / 2) * G4RotateY3D(-M_PI / 2); |
| 320 | l3->SetVisAttributes(batt); |
| 321 | |
| 322 | G4VSolid* s6 = new G4Box("leg_p6", 140. / 2, 189. / 2, 160. / 2); |
| 323 | G4LogicalVolume* l6 = new G4LogicalVolume(s6, Materials::get("G4_AIR"), "l6", 0, 0, 0); |
| 324 | G4Transform3D t6 = G4Translate3D(0, 170. + 189. / 2, 57. + 35. + 160. / 2); |
| 325 | l6->SetVisAttributes(att("air")); |
| 326 | |
| 327 | G4VSolid* s6a = new G4Box("leg_p6a", 140. / 2, (189. - 45.) / 2, 160. / 2); |
| 328 | G4LogicalVolume* l6a = new G4LogicalVolume(s6a, Materials::get("SUS304"), "l6a", 0, 0, 0); |
| 329 | l6a->SetVisAttributes(batt); |
| 330 | new G4PVPlacement(G4TranslateY3D(-45. / 2), l6a, "l6a_physical", l6, false, 0, overlap); |
| 331 | |
| 332 | G4VSolid* s6b = new G4Box("leg_p6b", 60. / 2, 45. / 2, 160. / 2); |
| 333 | G4LogicalVolume* l6b = new G4LogicalVolume(s6b, Materials::get("SUS304"), "l6b", 0, 0, 0); |
| 334 | l6b->SetVisAttributes(batt); |
| 335 | double dy = 189. / 2 - 45 + 45. / 2; |
| 336 | new G4PVPlacement(G4TranslateY3D(dy), l6b, "l6b_physical", l6, false, 0, overlap); |
| 337 | |
| 338 | G4VSolid* s6c = new G4Box("leg_p6c", 40. / 2, 45. / 2, 22.5 / 2); |
| 339 | G4LogicalVolume* l6c = new G4LogicalVolume(s6c, Materials::get("SUS304"), "l6c", 0, 0, 0); |
| 340 | l6c->SetVisAttributes(batt); |
| 341 | new G4PVPlacement(G4Translate3D(30 + 20, dy, 20 + 22.5 / 2), l6c, "l6c_physical", l6, false, 0, overlap); |
| 342 | new G4PVPlacement(G4Translate3D(30 + 20, dy, -20 - 22.5 / 2), l6c, "l6c_physical", l6, false, 1, overlap); |
| 343 | new G4PVPlacement(G4Translate3D(-30 - 20, dy, 20 + 22.5 / 2), l6c, "l6c_physical", l6, false, 2, overlap); |
| 344 | new G4PVPlacement(G4Translate3D(-30 - 20, dy, -20 - 22.5 / 2), l6c, "l6c_physical", l6, false, 3, overlap); |
| 345 | |
| 346 | G4AssemblyVolume* support_leg = new G4AssemblyVolume(); |
| 347 | |
| 348 | support_leg->AddPlacedVolume(l1, t1); |
| 349 | |
| 350 | support_leg->AddPlacedVolume(l3, t3); |
| 351 | |
| 352 | |
| 353 | support_leg->AddPlacedVolume(l6, t6); |
| 354 | |
| 355 | G4VSolid* s_all = new G4Box("leg_all", 140. / 2, 359. / 2, (257. - 5.) / 2); |
| 356 | G4LogicalVolume* l_all = new G4LogicalVolume(s_all, Materials::get("G4_AIR"), "l_all", 0, 0, 0); |
| 357 | l_all->SetVisAttributes(att("air")); |
| 358 | G4Transform3D tp = G4Translate3D(0, -359. / 2, -(257. - 5.) / 2); |
| 359 | support_leg->MakeImprint(l_all, tp, 0, overlap); |
| 360 | |
| 361 | |
| 362 | for (int i = 0; i < 8; i++) |
| 363 | new G4PVPlacement(gTrans * G4RotateX3D(M_PI)*G4RotateZ3D(-M_PI / 2 + M_PI / 8 + i * M_PI / 4)*G4Translate3D(0, |
| 364 | 1496 - 185 + 359. / 2, |
| 365 | 434 + 5 + (257. - 5.) / 2), l_all, "ECL_BackwardSupport_lall_physical", top, false, i, overlap); |
| 366 | |
| 367 | |
| 368 | G4VSolid* s1a = new G4Box("leg_p1a", 130. / 2, 178. / 2, 5. / 2); |
| 369 | G4LogicalVolume* l1a = new G4LogicalVolume(s1a, Materials::get("SUS304"), "l1a", 0, 0, 0); |
| 370 | l1a->SetVisAttributes(batt); |
| 371 | for (int i = 0; i < 8; i++) |
| 372 | new G4PVPlacement(gTrans * G4RotateX3D(M_PI)*G4RotateZ3D(-M_PI / 2 + M_PI / 8 + i * M_PI / 4)*G4Translate3D(0, |
| 373 | 1496 - 185 + 178. / 2, |
| 374 | 434 + 5 - 5. / 2), l1a, "l1a_physical", top, false, i, overlap); |
| 375 | |
| 376 | delete support_leg; |
| 377 | } |
| 378 | |
| 379 | } |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | #ifndef _STL_VECTOR_H |
| 57 | #define _STL_VECTOR_H 1 |
| 58 | |
| 59 | #include <bits/stl_iterator_base_funcs.h> |
| 60 | #include <bits/functexcept.h> |
| 61 | #include <bits/concept_check.h> |
| 62 | #if __cplusplus >= 201103L |
| 63 | #include <initializer_list> |
| 64 | #endif |
| 65 | #if __cplusplus >= 202002L |
| 66 | # include <compare> |
| 67 | #endif |
| 68 | #if __glibcxx_concepts // C++ >= C++20 |
| 69 | # include <bits/ranges_base.h> // ranges::distance |
| 70 | #endif |
| 71 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 72 | # include <bits/ranges_algobase.h> // ranges::copy |
| 73 | # include <bits/ranges_util.h> // ranges::subrange |
| 74 | #endif |
| 75 | |
| 76 | #include <debug/assertions.h> |
| 77 | |
| 78 | #if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR |
| 79 | extern "C" void |
| 80 | __sanitizer_annotate_contiguous_container(const void*, const void*, |
| 81 | const void*, const void*); |
| 82 | #endif |
| 83 | |
| 84 | namespace std _GLIBCXX_VISIBILITY(default) |
| 85 | { |
| 86 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 87 | _GLIBCXX_BEGIN_NAMESPACE_CONTAINER |
| 88 | |
| 89 | |
| 90 | template<typename _Tp, typename _Alloc> |
| 91 | struct _Vector_base |
| 92 | { |
| 93 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
| 94 | rebind<_Tp>::other _Tp_alloc_type; |
| 95 | typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type>::pointer |
| 96 | pointer; |
| 97 | |
| 98 | struct _Vector_impl_data |
| 99 | { |
| 100 | pointer _M_start; |
| 101 | pointer _M_finish; |
| 102 | pointer _M_end_of_storage; |
| 103 | |
| 104 | _GLIBCXX20_CONSTEXPR |
| 105 | _Vector_impl_data() _GLIBCXX_NOEXCEPT |
| 106 | : _M_start(), _M_finish(), _M_end_of_storage() |
| 107 | { } |
| 108 | |
| 109 | #if __cplusplus >= 201103L |
| 110 | _GLIBCXX20_CONSTEXPR |
| 111 | _Vector_impl_data(_Vector_impl_data&& __x) noexcept |
| 112 | : _M_start(__x._M_start), _M_finish(__x._M_finish), |
| 113 | _M_end_of_storage(__x._M_end_of_storage) |
| 114 | { __x._M_start = __x._M_finish = __x._M_end_of_storage = pointer(); } |
| 115 | #endif |
| 116 | |
| 117 | _GLIBCXX20_CONSTEXPR |
| 118 | void |
| 119 | _M_copy_data(_Vector_impl_data const& __x) _GLIBCXX_NOEXCEPT |
| 120 | { |
| 121 | _M_start = __x._M_start; |
| 122 | _M_finish = __x._M_finish; |
| 123 | _M_end_of_storage = __x._M_end_of_storage; |
| 124 | } |
| 125 | |
| 126 | _GLIBCXX20_CONSTEXPR |
| 127 | void |
| 128 | _M_swap_data(_Vector_impl_data& __x) _GLIBCXX_NOEXCEPT |
| 129 | { |
| 130 | |
| 131 | |
| 132 | _Vector_impl_data __tmp; |
| 133 | __tmp._M_copy_data(*this); |
| 134 | _M_copy_data(__x); |
| 135 | __x._M_copy_data(__tmp); |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | struct _Vector_impl |
| 140 | : public _Tp_alloc_type, public _Vector_impl_data |
| 141 | { |
| 142 | _GLIBCXX20_CONSTEXPR |
| 143 | _Vector_impl() _GLIBCXX_NOEXCEPT_IF( |
| 144 | is_nothrow_default_constructible<_Tp_alloc_type>::value) |
| 145 | #if __cpp_lib_concepts |
| 146 | requires is_default_constructible_v<_Tp_alloc_type> |
| 147 | #endif |
| 148 | : _Tp_alloc_type() |
| 149 | { } |
| 150 | |
| 151 | _GLIBCXX20_CONSTEXPR |
| 152 | _Vector_impl(_Tp_alloc_type const& __a) _GLIBCXX_NOEXCEPT |
| 153 | : _Tp_alloc_type(__a) |
| 154 | { } |
| 155 | |
| 156 | #if __cplusplus >= 201103L |
| 157 | |
| 158 | |
| 159 | _GLIBCXX20_CONSTEXPR |
| 160 | _Vector_impl(_Vector_impl&& __x) noexcept |
| 161 | : _Tp_alloc_type(std::move(__x)), _Vector_impl_data(std::move(__x)) |
| 162 | { } |
| 163 | |
| 164 | _GLIBCXX20_CONSTEXPR |
| 165 | _Vector_impl(_Tp_alloc_type&& __a) noexcept |
| 166 | : _Tp_alloc_type(std::move(__a)) |
| 167 | { } |
| 168 | |
| 169 | _GLIBCXX20_CONSTEXPR |
| 170 | _Vector_impl(_Tp_alloc_type&& __a, _Vector_impl&& __rv) noexcept |
| 171 | : _Tp_alloc_type(std::move(__a)), _Vector_impl_data(std::move(__rv)) |
| 172 | { } |
| 173 | #endif |
| 174 | |
| 175 | #if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR |
| 176 | template<typename = _Tp_alloc_type> |
| 177 | struct _Asan |
| 178 | { |
| 179 | typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type> |
| 180 | ::size_type size_type; |
| 181 | |
| 182 | static _GLIBCXX20_CONSTEXPR void |
| 183 | _S_shrink(_Vector_impl&, size_type) { } |
| 184 | static _GLIBCXX20_CONSTEXPR void |
| 185 | _S_on_dealloc(_Vector_impl&) { } |
| 186 | |
| 187 | typedef _Vector_impl& _Reinit; |
| 188 | |
| 189 | struct _Grow |
| 190 | { |
| 191 | _GLIBCXX20_CONSTEXPR _Grow(_Vector_impl&, size_type) { } |
| 192 | _GLIBCXX20_CONSTEXPR void _M_grew(size_type) { } |
| 193 | }; |
| 194 | }; |
| 195 | |
| 196 | |
| 197 | template<typename _Up> |
| 198 | struct _Asan<allocator<_Up> > |
| 199 | { |
| 200 | typedef typename __gnu_cxx::__alloc_traits<_Tp_alloc_type> |
| 201 | ::size_type size_type; |
| 202 | |
| 203 | |
| 204 | |
| 205 | static _GLIBCXX20_CONSTEXPR void |
| 206 | _S_adjust(_Vector_impl& __impl, pointer __prev, pointer __curr) |
| 207 | { |
| 208 | #if __cpp_lib_is_constant_evaluated |
| 209 | if (std::is_constant_evaluated()) |
| 210 | return; |
| 211 | #endif |
| 212 | __sanitizer_annotate_contiguous_container(__impl._M_start, |
| 213 | __impl._M_end_of_storage, __prev, __curr); |
| 214 | } |
| 215 | |
| 216 | static _GLIBCXX20_CONSTEXPR void |
| 217 | _S_grow(_Vector_impl& __impl, size_type __n) |
| 218 | { _S_adjust(__impl, __impl._M_finish, __impl._M_finish + __n); } |
| 219 | |
| 220 | static _GLIBCXX20_CONSTEXPR void |
| 221 | _S_shrink(_Vector_impl& __impl, size_type __n) |
| 222 | { _S_adjust(__impl, __impl._M_finish + __n, __impl._M_finish); } |
| 223 | |
| 224 | static _GLIBCXX20_CONSTEXPR void |
| 225 | _S_on_dealloc(_Vector_impl& __impl) |
| 226 | { |
| 227 | if (__impl._M_start) |
| 228 | _S_adjust(__impl, __impl._M_finish, __impl._M_end_of_storage); |
| 229 | } |
| 230 | |
| 231 | |
| 232 | struct _Reinit |
| 233 | { |
| 234 | explicit _GLIBCXX20_CONSTEXPR |
| 235 | _Reinit(_Vector_impl& __impl) : _M_impl(__impl) |
| 236 | { |
| 237 | |
| 238 | _S_on_dealloc(_M_impl); |
| 239 | } |
| 240 | |
| 241 | _GLIBCXX20_CONSTEXPR |
| 242 | ~_Reinit() |
| 243 | { |
| 244 | |
| 245 | if (_M_impl._M_start) |
| 246 | _S_adjust(_M_impl, _M_impl._M_end_of_storage, |
| 247 | _M_impl._M_finish); |
| 248 | } |
| 249 | |
| 250 | _Vector_impl& _M_impl; |
| 251 | |
| 252 | #if __cplusplus >= 201103L |
| 253 | _Reinit(const _Reinit&) = delete; |
| 254 | _Reinit& operator=(const _Reinit&) = delete; |
| 255 | #endif |
| 256 | }; |
| 257 | |
| 258 | |
| 259 | struct _Grow |
| 260 | { |
| 261 | _GLIBCXX20_CONSTEXPR |
| 262 | _Grow(_Vector_impl& __impl, size_type __n) |
| 263 | : _M_impl(__impl), _M_n(__n) |
| 264 | { _S_grow(_M_impl, __n); } |
| 265 | |
| 266 | _GLIBCXX20_CONSTEXPR |
| 267 | ~_Grow() { if (_M_n) _S_shrink(_M_impl, _M_n); } |
| 268 | |
| 269 | _GLIBCXX20_CONSTEXPR |
| 270 | void _M_grew(size_type __n) { _M_n -= __n; } |
| 271 | |
| 272 | #if __cplusplus >= 201103L |
| 273 | _Grow(const _Grow&) = delete; |
| 274 | _Grow& operator=(const _Grow&) = delete; |
| 275 | #endif |
| 276 | private: |
| 277 | _Vector_impl& _M_impl; |
| 278 | size_type _M_n; |
| 279 | }; |
| 280 | }; |
| 281 | |
| 282 | #define _GLIBCXX_ASAN_ANNOTATE_REINIT \ |
| 283 | typename _Base::_Vector_impl::template _Asan<>::_Reinit const \ |
| 284 | __attribute__((__unused__)) __reinit_guard(this->_M_impl) |
| 285 | #define _GLIBCXX_ASAN_ANNOTATE_GROW(n) \ |
| 286 | typename _Base::_Vector_impl::template _Asan<>::_Grow \ |
| 287 | __attribute__((__unused__)) __grow_guard(this->_M_impl, (n)) |
| 288 | #define _GLIBCXX_ASAN_ANNOTATE_GREW(n) __grow_guard._M_grew(n) |
| 289 | #define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n) \ |
| 290 | _Base::_Vector_impl::template _Asan<>::_S_shrink(this->_M_impl, n) |
| 291 | #define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC \ |
| 292 | _Base::_Vector_impl::template _Asan<>::_S_on_dealloc(this->_M_impl) |
| 293 | #else // ! (_GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR) |
| 294 | #define _GLIBCXX_ASAN_ANNOTATE_REINIT |
| 295 | #define _GLIBCXX_ASAN_ANNOTATE_GROW(n) |
| 296 | #define _GLIBCXX_ASAN_ANNOTATE_GREW(n) |
| 297 | #define _GLIBCXX_ASAN_ANNOTATE_SHRINK(n) |
| 298 | #define _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC |
| 299 | #endif // _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR |
| 300 | }; |
| 301 | |
| 302 | public: |
| 303 | typedef _Alloc allocator_type; |
| 304 | |
| 305 | _GLIBCXX20_CONSTEXPR |
| 306 | _Tp_alloc_type& |
| 307 | _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT |
| 308 | { return this->_M_impl; } |
| 309 | |
| 310 | _GLIBCXX20_CONSTEXPR |
| 311 | const _Tp_alloc_type& |
| 312 | _M_get_Tp_allocator() const _GLIBCXX_NOEXCEPT |
| 313 | { return this->_M_impl; } |
| 314 | |
| 315 | _GLIBCXX20_CONSTEXPR |
| 316 | allocator_type |
| 317 | get_allocator() const _GLIBCXX_NOEXCEPT |
| 318 | { return allocator_type(_M_get_Tp_allocator()); } |
| 319 | |
| 320 | #if __cplusplus >= 201103L |
| 321 | _Vector_base() = default; |
| 322 | #else |
| 323 | _Vector_base() { } |
| 324 | #endif |
| 325 | |
| 326 | _GLIBCXX20_CONSTEXPR |
| 327 | _Vector_base(const allocator_type& __a) _GLIBCXX_NOEXCEPT |
| 328 | : _M_impl(__a) { } |
| 329 | |
| 330 | |
| 331 | #if !_GLIBCXX_INLINE_VERSION |
| 332 | _GLIBCXX20_CONSTEXPR |
| 333 | _Vector_base(size_t __n) |
| 334 | : _M_impl() |
| 335 | { _M_create_storage(__n); } |
| 336 | #endif |
| 337 | |
| 338 | _GLIBCXX20_CONSTEXPR |
| 339 | _Vector_base(size_t __n, const allocator_type& __a) |
| 340 | : _M_impl(__a) |
| 341 | { _M_create_storage(__n); } |
| 342 | |
| 343 | #if __cplusplus >= 201103L |
| 344 | _Vector_base(_Vector_base&&) = default; |
| 345 | |
| 346 | |
| 347 | # if !_GLIBCXX_INLINE_VERSION |
| 348 | _GLIBCXX20_CONSTEXPR |
| 349 | _Vector_base(_Tp_alloc_type&& __a) noexcept |
| 350 | : _M_impl(std::move(__a)) { } |
| 351 | |
| 352 | _GLIBCXX20_CONSTEXPR |
| 353 | _Vector_base(_Vector_base&& __x, const allocator_type& __a) |
| 354 | : _M_impl(__a) |
| 355 | { |
| 356 | if (__x.get_allocator() == __a) |
| 357 | this->_M_impl._M_swap_data(__x._M_impl); |
| 358 | else |
| 359 | { |
| 360 | size_t __n = __x._M_impl._M_finish - __x._M_impl._M_start; |
| 361 | _M_create_storage(__n); |
| 362 | } |
| 363 | } |
| 364 | # endif |
| 365 | |
| 366 | _GLIBCXX20_CONSTEXPR |
| 367 | _Vector_base(const allocator_type& __a, _Vector_base&& __x) |
| 368 | : _M_impl(_Tp_alloc_type(__a), std::move(__x._M_impl)) |
| 369 | { } |
| 370 | #endif |
| 371 | |
| 372 | _GLIBCXX20_CONSTEXPR |
| 373 | ~_Vector_base() _GLIBCXX_NOEXCEPT |
| 374 | { |
| 375 | _M_deallocate(_M_impl._M_start, |
| 376 | _M_impl._M_end_of_storage - _M_impl._M_start); |
| 377 | } |
| 378 | |
| 379 | public: |
| 380 | _Vector_impl _M_impl; |
| 381 | |
| 382 | _GLIBCXX20_CONSTEXPR |
| 383 | pointer |
| 384 | _M_allocate(size_t __n) |
| 385 | { |
| 386 | typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr; |
| 387 | return __n != 0 ? _Tr::allocate(_M_impl, __n) : pointer(); |
| 388 | } |
| 389 | |
| 390 | _GLIBCXX20_CONSTEXPR |
| 391 | void |
| 392 | _M_deallocate(pointer __p, size_t __n) |
| 393 | { |
| 394 | typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tr; |
| 395 | if (__p) |
| 396 | _Tr::deallocate(_M_impl, __p, __n); |
| 397 | } |
| 398 | |
| 399 | protected: |
| 400 | |
| 401 | _GLIBCXX20_CONSTEXPR |
| 402 | void |
| 403 | _M_create_storage(size_t __n) |
| 404 | { |
| 405 | this->_M_impl._M_start = this->_M_allocate(__n); |
| 406 | this->_M_impl._M_finish = this->_M_impl._M_start; |
| 407 | this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; |
| 408 | } |
| 409 | |
| 410 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | template<ranges::input_range _Rg> |
| 417 | constexpr void |
| 418 | _M_append_range_to(_Rg&& __rg, pointer& __ptr) |
| 419 | { |
| 420 | __ptr = std::__uninitialized_copy_a(ranges::begin(__rg), |
| 421 | ranges::end(__rg), |
| 422 | __ptr, _M_get_Tp_allocator()); |
| 423 | } |
| 424 | |
| 425 | |
| 426 | |
| 427 | template<ranges::input_range _Rg> |
| 428 | constexpr void |
| 429 | _M_append_range(_Rg&& __rg) |
| 430 | { _M_append_range_to(std::forward<_Rg>(__rg), _M_impl._M_finish); } |
| 431 | #endif |
| 432 | }; |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | template<typename _Tp, typename _Alloc = std::allocator<_Tp> > |
| 458 | class vector : protected _Vector_base<_Tp, _Alloc> |
| 459 | { |
| 460 | #ifdef _GLIBCXX_CONCEPT_CHECKS |
| 461 | |
| 462 | typedef typename _Alloc::value_type _Alloc_value_type; |
| 463 | # if __cplusplus < 201103L |
| 464 | __glibcxx_class_requires(_Tp, _SGIAssignableConcept) |
| 465 | # endif |
| 466 | __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept) |
| 467 | #endif |
| 468 | |
| 469 | #if __cplusplus >= 201103L |
| 470 | static_assert(is_same<typename remove_cv<_Tp>::type, _Tp>::value, |
| 471 | "std::vector must have a non-const, non-volatile value_type"); |
| 472 | # if __cplusplus > 201703L || defined __STRICT_ANSI__ |
| 473 | static_assert(is_same<typename _Alloc::value_type, _Tp>::value, |
| 474 | "std::vector must have the same value_type as its allocator"); |
| 475 | # endif |
| 476 | #endif |
| 477 | |
| 478 | typedef _Vector_base<_Tp, _Alloc> _Base; |
| 479 | typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; |
| 480 | typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Alloc_traits; |
| 481 | |
| 482 | public: |
| 483 | typedef _Tp value_type; |
| 484 | typedef typename _Base::pointer pointer; |
| 485 | typedef typename _Alloc_traits::const_pointer const_pointer; |
| 486 | typedef typename _Alloc_traits::reference reference; |
| 487 | typedef typename _Alloc_traits::const_reference const_reference; |
| 488 | typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator; |
| 489 | typedef __gnu_cxx::__normal_iterator<const_pointer, vector> |
| 490 | const_iterator; |
| 491 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 492 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 493 | typedef size_t size_type; |
| 494 | typedef ptrdiff_t difference_type; |
| 495 | typedef _Alloc allocator_type; |
| 496 | |
| 497 | private: |
| 498 | #if __cplusplus >= 201103L |
| 499 | static constexpr bool |
| 500 | _S_nothrow_relocate(true_type) |
| 501 | { |
| 502 | return noexcept(std::__relocate_a(std::declval<pointer>(), |
| 503 | std::declval<pointer>(), |
| 504 | std::declval<pointer>(), |
| 505 | std::declval<_Tp_alloc_type&>())); |
| 506 | } |
| 507 | |
| 508 | static constexpr bool |
| 509 | _S_nothrow_relocate(false_type) |
| 510 | { return false; } |
| 511 | |
| 512 | static constexpr bool |
| 513 | _S_use_relocate() |
| 514 | { |
| 515 | |
| 516 | |
| 517 | |
| 518 | return _S_nothrow_relocate(__is_move_insertable<_Tp_alloc_type>{}); |
| 519 | } |
| 520 | |
| 521 | static pointer |
| 522 | _S_do_relocate(pointer __first, pointer __last, pointer __result, |
| 523 | _Tp_alloc_type& __alloc, true_type) noexcept |
| 524 | { |
| 525 | return std::__relocate_a(__first, __last, __result, __alloc); |
| 526 | } |
| 527 | |
| 528 | static pointer |
| 529 | _S_do_relocate(pointer, pointer, pointer __result, |
| 530 | _Tp_alloc_type&, false_type) noexcept |
| 531 | { return __result; } |
| 532 | |
| 533 | static _GLIBCXX20_CONSTEXPR pointer |
| 534 | _S_relocate(pointer __first, pointer __last, pointer __result, |
| 535 | _Tp_alloc_type& __alloc) noexcept |
| 536 | { |
| 537 | #if __cpp_if_constexpr |
| 538 | |
| 539 | return std::__relocate_a(__first, __last, __result, __alloc); |
| 540 | #else |
| 541 | using __do_it = __bool_constant<_S_use_relocate()>; |
| 542 | return _S_do_relocate(__first, __last, __result, __alloc, __do_it{}); |
| 543 | #endif |
| 544 | } |
| 545 | #endif // C++11 |
| 546 | |
| 547 | protected: |
| 548 | using _Base::_M_allocate; |
| 549 | using _Base::_M_deallocate; |
| 550 | using _Base::_M_impl; |
| 551 | using _Base::_M_get_Tp_allocator; |
| 552 | |
| 553 | public: |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | #if __cplusplus >= 201103L |
| 561 | vector() = default; |
| 562 | #else |
| 563 | vector() { } |
| 564 | #endif |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | explicit |
| 571 | _GLIBCXX20_CONSTEXPR |
| 572 | vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT |
| 573 | : _Base(__a) { } |
| 574 | |
| 575 | #if __cplusplus >= 201103L |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | explicit |
| 585 | _GLIBCXX20_CONSTEXPR |
| 586 | vector(size_type __n, const allocator_type& __a = allocator_type()) |
| 587 | : _Base(_S_check_init_len(__n, __a), __a) |
| 588 | { _M_default_initialize(__n); } |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | _GLIBCXX20_CONSTEXPR |
| 599 | vector(size_type __n, const value_type& __value, |
| 600 | const allocator_type& __a = allocator_type()) |
| 601 | : _Base(_S_check_init_len(__n, __a), __a) |
| 602 | { _M_fill_initialize(__n, __value); } |
| 603 | #else |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | explicit |
| 613 | vector(size_type __n, const value_type& __value = value_type(), |
| 614 | const allocator_type& __a = allocator_type()) |
| 615 | : _Base(_S_check_init_len(__n, __a), __a) |
| 616 | { _M_fill_initialize(__n, __value); } |
| 617 | #endif |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | _GLIBCXX20_CONSTEXPR |
| 631 | vector(const vector& __x) |
| 632 | : _Base(__x.size(), |
| 633 | _Alloc_traits::_S_select_on_copy(__x._M_get_Tp_allocator())) |
| 634 | { |
| 635 | this->_M_impl._M_finish = |
| 636 | std::__uninitialized_copy_a(__x.begin(), __x.end(), |
| 637 | this->_M_impl._M_start, |
| 638 | _M_get_Tp_allocator()); |
| 639 | } |
| 640 | |
| 641 | #if __cplusplus >= 201103L |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | vector(vector&&) noexcept = default; |
| 651 | |
| 652 | |
| 653 | _GLIBCXX20_CONSTEXPR |
| 654 | vector(const vector& __x, const __type_identity_t<allocator_type>& __a) |
| 655 | : _Base(__x.size(), __a) |
| 656 | { |
| 657 | this->_M_impl._M_finish = |
| 658 | std::__uninitialized_copy_a(__x.begin(), __x.end(), |
| 659 | this->_M_impl._M_start, |
| 660 | _M_get_Tp_allocator()); |
| 661 | } |
| 662 | |
| 663 | private: |
| 664 | _GLIBCXX20_CONSTEXPR |
| 665 | vector(vector&& __rv, const allocator_type& __m, true_type) noexcept |
| 666 | : _Base(__m, std::move(__rv)) |
| 667 | { } |
| 668 | |
| 669 | _GLIBCXX20_CONSTEXPR |
| 670 | vector(vector&& __rv, const allocator_type& __m, false_type) |
| 671 | : _Base(__m) |
| 672 | { |
| 673 | if (__rv.get_allocator() == __m) |
| 674 | this->_M_impl._M_swap_data(__rv._M_impl); |
| 675 | else if (!__rv.empty()) |
| 676 | { |
| 677 | this->_M_create_storage(__rv.size()); |
| 678 | this->_M_impl._M_finish = |
| 679 | std::__uninitialized_move_a(__rv.begin(), __rv.end(), |
| 680 | this->_M_impl._M_start, |
| 681 | _M_get_Tp_allocator()); |
| 682 | __rv.clear(); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | public: |
| 687 | |
| 688 | _GLIBCXX20_CONSTEXPR |
| 689 | vector(vector&& __rv, const __type_identity_t<allocator_type>& __m) |
| 690 | noexcept( noexcept( |
| 691 | vector(std::declval<vector&&>(), std::declval<const allocator_type&>(), |
| 692 | std::declval<typename _Alloc_traits::is_always_equal>())) ) |
| 693 | : vector(std::move(__rv), __m, typename _Alloc_traits::is_always_equal{}) |
| 694 | { } |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | _GLIBCXX20_CONSTEXPR |
| 708 | vector(initializer_list<value_type> __l, |
| 709 | const allocator_type& __a = allocator_type()) |
| 710 | : _Base(__a) |
| 711 | { |
| 712 | _M_range_initialize_n(__l.begin(), __l.end(), __l.size()); |
| 713 | } |
| 714 | #endif |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | #if __cplusplus >= 201103L |
| 733 | template<typename _InputIterator, |
| 734 | typename = std::_RequireInputIter<_InputIterator>> |
| 735 | _GLIBCXX20_CONSTEXPR |
| 736 | vector(_InputIterator __first, _InputIterator __last, |
| 737 | const allocator_type& __a = allocator_type()) |
| 738 | : _Base(__a) |
| 739 | { |
| 740 | #if __glibcxx_concepts // C++ >= C++20 |
| 741 | if constexpr (sized_sentinel_for<_InputIterator, _InputIterator> |
| 742 | || forward_iterator<_InputIterator>) |
| 743 | { |
| 744 | const auto __n |
| 745 | = static_cast<size_type>(ranges::distance(__first, __last)); |
| 746 | _M_range_initialize_n(__first, __last, __n); |
| 747 | return; |
| 748 | } |
| 749 | else |
| 750 | #endif |
| 751 | _M_range_initialize(__first, __last, |
| 752 | std::__iterator_category(__first)); |
| 753 | } |
| 754 | #else |
| 755 | template<typename _InputIterator> |
| 756 | vector(_InputIterator __first, _InputIterator __last, |
| 757 | const allocator_type& __a = allocator_type()) |
| 758 | : _Base(__a) |
| 759 | { |
| 760 | |
| 761 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
| 762 | _M_initialize_dispatch(__first, __last, _Integral()); |
| 763 | } |
| 764 | #endif |
| 765 | |
| 766 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 767 | |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | template<__detail::__container_compatible_range<_Tp> _Rg> |
| 773 | constexpr |
| 774 | vector(from_range_t, _Rg&& __rg, const _Alloc& __a = _Alloc()) |
| 775 | : vector(__a) |
| 776 | { |
| 777 | if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>) |
| 778 | { |
| 779 | const auto __n = static_cast<size_type>(ranges::distance(__rg)); |
| 780 | _M_range_initialize_n(ranges::begin(__rg), ranges::end(__rg), |
| 781 | __n); |
| 782 | } |
| 783 | else |
| 784 | { |
| 785 | auto __first = ranges::begin(__rg); |
| 786 | const auto __last = ranges::end(__rg); |
| 787 | for (; __first != __last; ++__first) |
| 788 | emplace_back(*__first); |
| 789 | } |
| 790 | } |
| 791 | #endif |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | _GLIBCXX20_CONSTEXPR |
| 800 | ~vector() _GLIBCXX_NOEXCEPT |
| 801 | { |
| 802 | std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, |
| 803 | _M_get_Tp_allocator()); |
| 804 | _GLIBCXX_ASAN_ANNOTATE_BEFORE_DEALLOC; |
| 805 | } |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | _GLIBCXX20_CONSTEXPR |
| 817 | vector& |
| 818 | operator=(const vector& __x); |
| 819 | |
| 820 | #if __cplusplus >= 201103L |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | _GLIBCXX20_CONSTEXPR |
| 832 | vector& |
| 833 | operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move()) |
| 834 | { |
| 835 | constexpr bool __move_storage = |
| 836 | _Alloc_traits::_S_propagate_on_move_assign() |
| 837 | || _Alloc_traits::_S_always_equal(); |
| 838 | _M_move_assign(std::move(__x), __bool_constant<__move_storage>()); |
| 839 | return *this; |
| 840 | } |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | _GLIBCXX20_CONSTEXPR |
| 854 | vector& |
| 855 | operator=(initializer_list<value_type> __l) |
| 856 | { |
| 857 | this->_M_assign_aux(__l.begin(), __l.end(), |
| 858 | random_access_iterator_tag()); |
| 859 | return *this; |
| 860 | } |
| 861 | #endif |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | |
| 868 | |
| 869 | |
| 870 | |
| 871 | |
| 872 | |
| 873 | _GLIBCXX20_CONSTEXPR |
| 874 | void |
| 875 | assign(size_type __n, const value_type& __val) |
| 876 | { _M_fill_assign(__n, __val); } |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | |
| 889 | |
| 890 | #if __cplusplus >= 201103L |
| 891 | template<typename _InputIterator, |
| 892 | typename = std::_RequireInputIter<_InputIterator>> |
| 893 | _GLIBCXX20_CONSTEXPR |
| 894 | void |
| 895 | assign(_InputIterator __first, _InputIterator __last) |
| 896 | { _M_assign_aux(__first, __last, std::__iterator_category(__first)); } |
| 897 | #else |
| 898 | template<typename _InputIterator> |
| 899 | void |
| 900 | assign(_InputIterator __first, _InputIterator __last) |
| 901 | { |
| 902 | |
| 903 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
| 904 | _M_assign_dispatch(__first, __last, _Integral()); |
| 905 | } |
| 906 | #endif |
| 907 | |
| 908 | #if __cplusplus >= 201103L |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | _GLIBCXX20_CONSTEXPR |
| 921 | void |
| 922 | assign(initializer_list<value_type> __l) |
| 923 | { |
| 924 | this->_M_assign_aux(__l.begin(), __l.end(), |
| 925 | random_access_iterator_tag()); |
| 926 | } |
| 927 | #endif |
| 928 | |
| 929 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 930 | |
| 931 | |
| 932 | |
| 933 | |
| 934 | |
| 935 | |
| 936 | template<__detail::__container_compatible_range<_Tp> _Rg> |
| 937 | constexpr void |
| 938 | assign_range(_Rg&& __rg) |
| 939 | { |
| 940 | static_assert(assignable_from<_Tp&, ranges::range_reference_t<_Rg>>); |
| 941 | |
| 942 | if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>) |
| 943 | { |
| 944 | const auto __n = size_type(ranges::distance(__rg)); |
| 945 | if (__n <= size()) |
| 946 | { |
| 947 | auto __res = ranges::copy(__rg, this->_M_impl._M_start); |
| 948 | _M_erase_at_end(__res.out); |
| 949 | return; |
| 950 | } |
| 951 | |
| 952 | reserve(__n); |
| 953 | auto __first = ranges::copy_n(ranges::begin(__rg), size(), |
| 954 | this->_M_impl._M_start).in; |
| 955 | [[maybe_unused]] const auto __diff = __n - size(); |
| 956 | _GLIBCXX_ASAN_ANNOTATE_GROW(__diff); |
| 957 | _Base::_M_append_range(ranges::subrange(std::move(__first), |
| 958 | ranges::end(__rg))); |
| 959 | _GLIBCXX_ASAN_ANNOTATE_GREW(__diff); |
| 960 | } |
| 961 | else |
| 962 | { |
| 963 | auto __first = ranges::begin(__rg); |
| 964 | const auto __last = ranges::end(__rg); |
| 965 | pointer __ptr = this->_M_impl._M_start; |
| 966 | pointer const __end = this->_M_impl._M_finish; |
| 967 | |
| 968 | while (__ptr < __end && __first != __last) |
| 969 | { |
| 970 | *__ptr = *__first; |
| 971 | ++__ptr; |
| 972 | ++__first; |
| 973 | } |
| 974 | |
| 975 | if (__first == __last) |
| 976 | _M_erase_at_end(__ptr); |
| 977 | else |
| 978 | { |
| 979 | do |
| 980 | emplace_back(*__first); |
| 981 | while (++__first != __last); |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | #endif // containers_ranges |
| 986 | |
| 987 | |
| 988 | using _Base::get_allocator; |
| 989 | |
| 990 | |
| 991 | |
| 992 | |
| 993 | |
| 994 | |
| 995 | |
| 996 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 997 | iterator |
| 998 | begin() _GLIBCXX_NOEXCEPT |
| 999 | { return iterator(this->_M_impl._M_start); } |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | |
| 1006 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1007 | const_iterator |
| 1008 | begin() const _GLIBCXX_NOEXCEPT |
| 1009 | { return const_iterator(this->_M_impl._M_start); } |
| 1010 | |
| 1011 | |
| 1012 | |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1017 | iterator |
| 1018 | end() _GLIBCXX_NOEXCEPT |
| 1019 | { return iterator(this->_M_impl._M_finish); } |
| 1020 | |
| 1021 | |
| 1022 | |
| 1023 | |
| 1024 | |
| 1025 | |
| 1026 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1027 | const_iterator |
| 1028 | end() const _GLIBCXX_NOEXCEPT |
| 1029 | { return const_iterator(this->_M_impl._M_finish); } |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1037 | reverse_iterator |
| 1038 | rbegin() _GLIBCXX_NOEXCEPT |
| 1039 | { return reverse_iterator(end()); } |
| 1040 | |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | |
| 1045 | |
| 1046 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1047 | const_reverse_iterator |
| 1048 | rbegin() const _GLIBCXX_NOEXCEPT |
| 1049 | { return const_reverse_iterator(end()); } |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | |
| 1056 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1057 | reverse_iterator |
| 1058 | rend() _GLIBCXX_NOEXCEPT |
| 1059 | { return reverse_iterator(begin()); } |
| 1060 | |
| 1061 | |
| 1062 | |
| 1063 | |
| 1064 | |
| 1065 | |
| 1066 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1067 | const_reverse_iterator |
| 1068 | rend() const _GLIBCXX_NOEXCEPT |
| 1069 | { return const_reverse_iterator(begin()); } |
| 1070 | |
| 1071 | #if __cplusplus >= 201103L |
| 1072 | |
| 1073 | |
| 1074 | |
| 1075 | |
| 1076 | |
| 1077 | [[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1078 | const_iterator |
| 1079 | cbegin() const noexcept |
| 1080 | { return const_iterator(this->_M_impl._M_start); } |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | [[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1088 | const_iterator |
| 1089 | cend() const noexcept |
| 1090 | { return const_iterator(this->_M_impl._M_finish); } |
| 1091 | |
| 1092 | |
| 1093 | |
| 1094 | |
| 1095 | |
| 1096 | |
| 1097 | [[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1098 | const_reverse_iterator |
| 1099 | crbegin() const noexcept |
| 1100 | { return const_reverse_iterator(end()); } |
| 1101 | |
| 1102 | |
| 1103 | |
| 1104 | |
| 1105 | |
| 1106 | |
| 1107 | [[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1108 | const_reverse_iterator |
| 1109 | crend() const noexcept |
| 1110 | { return const_reverse_iterator(begin()); } |
| 1111 | #endif |
| 1112 | |
| 1113 | |
| 1114 | |
| 1115 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1116 | size_type |
| 1117 | size() const _GLIBCXX_NOEXCEPT |
| 1118 | { |
| 1119 | ptrdiff_t __dif = this->_M_impl._M_finish - this->_M_impl._M_start; |
| 1120 | if (__dif < 0) |
| 1121 | __builtin_unreachable (); |
| 1122 | return size_type(__dif); |
| 1123 | } |
| 1124 | |
| 1125 | |
| 1126 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1127 | size_type |
| 1128 | max_size() const _GLIBCXX_NOEXCEPT |
| 1129 | { return _S_max_size(_M_get_Tp_allocator()); } |
| 1130 | |
| 1131 | #if __cplusplus >= 201103L |
| 1132 | |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | _GLIBCXX20_CONSTEXPR |
| 1142 | void |
| 1143 | resize(size_type __new_size) |
| 1144 | { |
| 1145 | if (__new_size > size()) |
| 1146 | _M_default_append(__new_size - size()); |
| 1147 | else if (__new_size < size()) |
| 1148 | _M_erase_at_end(this->_M_impl._M_start + __new_size); |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | _GLIBCXX20_CONSTEXPR |
| 1163 | void |
| 1164 | resize(size_type __new_size, const value_type& __x) |
| 1165 | { |
| 1166 | if (__new_size > size()) |
| 1167 | _M_fill_insert(end(), __new_size - size(), __x); |
| 1168 | else if (__new_size < size()) |
| 1169 | _M_erase_at_end(this->_M_impl._M_start + __new_size); |
| 1170 | } |
| 1171 | #else |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | |
| 1182 | |
| 1183 | _GLIBCXX20_CONSTEXPR |
| 1184 | void |
| 1185 | resize(size_type __new_size, value_type __x = value_type()) |
| 1186 | { |
| 1187 | if (__new_size > size()) |
| 1188 | _M_fill_insert(end(), __new_size - size(), __x); |
| 1189 | else if (__new_size < size()) |
| 1190 | _M_erase_at_end(this->_M_impl._M_start + __new_size); |
| 1191 | } |
| 1192 | #endif |
| 1193 | |
| 1194 | #if __cplusplus >= 201103L |
| 1195 | |
| 1196 | _GLIBCXX20_CONSTEXPR |
| 1197 | void |
| 1198 | shrink_to_fit() |
| 1199 | { _M_shrink_to_fit(); } |
| 1200 | #endif |
| 1201 | |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1207 | size_type |
| 1208 | capacity() const _GLIBCXX_NOEXCEPT |
| 1209 | { |
| 1210 | ptrdiff_t __dif = this->_M_impl._M_end_of_storage |
| 1211 | - this->_M_impl._M_start; |
| 1212 | if (__dif < 0) |
| 1213 | __builtin_unreachable (); |
| 1214 | return size_type(__dif); |
| 1215 | } |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1222 | bool |
| 1223 | empty() const _GLIBCXX_NOEXCEPT |
| 1224 | { return begin() == end(); } |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | _GLIBCXX20_CONSTEXPR |
| 1244 | void |
| 1245 | reserve(size_type __n); |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1260 | reference |
| 1261 | operator[](size_type __n) _GLIBCXX_NOEXCEPT |
| 1262 | { |
| 1263 | __glibcxx_requires_subscript(__n); |
| 1264 | return *(this->_M_impl._M_start + __n); |
| 1265 | } |
| 1266 | |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1279 | const_reference |
| 1280 | operator[](size_type __n) const _GLIBCXX_NOEXCEPT |
| 1281 | { |
| 1282 | __glibcxx_requires_subscript(__n); |
| 1283 | return *(this->_M_impl._M_start + __n); |
| 1284 | } |
| 1285 | |
| 1286 | protected: |
| 1287 | |
| 1288 | _GLIBCXX20_CONSTEXPR |
| 1289 | void |
| 1290 | _M_range_check(size_type __n) const |
| 1291 | { |
| 1292 | if (__n >= this->size()) |
| 1293 | __throw_out_of_range_fmt(__N("vector::_M_range_check: __n " |
| 1294 | "(which is %zu) >= this->size() " |
| 1295 | "(which is %zu)"), |
| 1296 | __n, this->size()); |
| 1297 | } |
| 1298 | |
| 1299 | public: |
| 1300 | |
| 1301 | |
| 1302 | |
| 1303 | |
| 1304 | |
| 1305 | |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1312 | reference |
| 1313 | at(size_type __n) |
| 1314 | { |
| 1315 | _M_range_check(__n); |
| 1316 | return (*this)[__n]; |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | |
| 1328 | |
| 1329 | |
| 1330 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1331 | const_reference |
| 1332 | at(size_type __n) const |
| 1333 | { |
| 1334 | _M_range_check(__n); |
| 1335 | return (*this)[__n]; |
| 1336 | } |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1343 | reference |
| 1344 | front() _GLIBCXX_NOEXCEPT |
| 1345 | { |
| 1346 | __glibcxx_requires_nonempty(); |
| 1347 | return *begin(); |
| 1348 | } |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1355 | const_reference |
| 1356 | front() const _GLIBCXX_NOEXCEPT |
| 1357 | { |
| 1358 | __glibcxx_requires_nonempty(); |
| 1359 | return *begin(); |
| 1360 | } |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | |
| 1366 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1367 | reference |
| 1368 | back() _GLIBCXX_NOEXCEPT |
| 1369 | { |
| 1370 | __glibcxx_requires_nonempty(); |
| 1371 | return *(end() - 1); |
| 1372 | } |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1379 | const_reference |
| 1380 | back() const _GLIBCXX_NOEXCEPT |
| 1381 | { |
| 1382 | __glibcxx_requires_nonempty(); |
| 1383 | return *(end() - 1); |
| 1384 | } |
| 1385 | |
| 1386 | |
| 1387 | |
| 1388 | |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | |
| 1393 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1394 | _Tp* |
| 1395 | data() _GLIBCXX_NOEXCEPT |
| 1396 | { return _M_data_ptr(this->_M_impl._M_start); } |
| 1397 | |
| 1398 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1399 | const _Tp* |
| 1400 | data() const _GLIBCXX_NOEXCEPT |
| 1401 | { return _M_data_ptr(this->_M_impl._M_start); } |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | |
| 1411 | |
| 1412 | |
| 1413 | |
| 1414 | _GLIBCXX20_CONSTEXPR |
| 1415 | void |
| 1416 | push_back(const value_type& __x) |
| 1417 | { |
| 1418 | if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) |
| 1419 | { |
| 1420 | _GLIBCXX_ASAN_ANNOTATE_GROW(1); |
| 1421 | _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, |
| 1422 | __x); |
| 1423 | ++this->_M_impl._M_finish; |
| 1424 | _GLIBCXX_ASAN_ANNOTATE_GREW(1); |
| 1425 | } |
| 1426 | else |
| 1427 | _M_realloc_append(__x); |
| 1428 | } |
| 1429 | |
| 1430 | #if __cplusplus >= 201103L |
| 1431 | _GLIBCXX20_CONSTEXPR |
| 1432 | void |
| 1433 | push_back(value_type&& __x) |
| 1434 | { emplace_back(std::move(__x)); } |
| 1435 | |
| 1436 | template<typename... _Args> |
| 1437 | #if __cplusplus > 201402L |
| 1438 | _GLIBCXX20_CONSTEXPR |
| 1439 | reference |
| 1440 | #else |
| 1441 | void |
| 1442 | #endif |
| 1443 | emplace_back(_Args&&... __args); |
| 1444 | #endif |
| 1445 | |
| 1446 | |
| 1447 | |
| 1448 | |
| 1449 | |
| 1450 | |
| 1451 | |
| 1452 | |
| 1453 | |
| 1454 | |
| 1455 | _GLIBCXX20_CONSTEXPR |
| 1456 | void |
| 1457 | pop_back() _GLIBCXX_NOEXCEPT |
| 1458 | { |
| 1459 | __glibcxx_requires_nonempty(); |
| 1460 | --this->_M_impl._M_finish; |
| 1461 | _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish); |
| 1462 | _GLIBCXX_ASAN_ANNOTATE_SHRINK(1); |
| 1463 | } |
| 1464 | |
| 1465 | #if __cplusplus >= 201103L |
| 1466 | |
| 1467 | |
| 1468 | |
| 1469 | |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | |
| 1474 | |
| 1475 | |
| 1476 | |
| 1477 | |
| 1478 | template<typename... _Args> |
| 1479 | _GLIBCXX20_CONSTEXPR |
| 1480 | iterator |
| 1481 | emplace(const_iterator __position, _Args&&... __args) |
| 1482 | { return _M_emplace_aux(__position, std::forward<_Args>(__args)...); } |
| 1483 | |
| 1484 | |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | _GLIBCXX20_CONSTEXPR |
| 1496 | iterator |
| 1497 | insert(const_iterator __position, const value_type& __x); |
| 1498 | #else |
| 1499 | |
| 1500 | |
| 1501 | |
| 1502 | |
| 1503 | |
| 1504 | |
| 1505 | |
| 1506 | |
| 1507 | |
| 1508 | |
| 1509 | |
| 1510 | iterator |
| 1511 | insert(iterator __position, const value_type& __x); |
| 1512 | #endif |
| 1513 | |
| 1514 | #if __cplusplus >= 201103L |
| 1515 | |
| 1516 | |
| 1517 | |
| 1518 | |
| 1519 | |
| 1520 | |
| 1521 | |
| 1522 | |
| 1523 | |
| 1524 | |
| 1525 | |
| 1526 | _GLIBCXX20_CONSTEXPR |
| 1527 | iterator |
| 1528 | insert(const_iterator __position, value_type&& __x) |
| 1529 | { return _M_insert_rval(__position, std::move(__x)); } |
| 1530 | |
| 1531 | |
| 1532 | |
| 1533 | |
| 1534 | |
| 1535 | |
| 1536 | |
| 1537 | |
| 1538 | |
| 1539 | |
| 1540 | |
| 1541 | |
| 1542 | |
| 1543 | |
| 1544 | _GLIBCXX20_CONSTEXPR |
| 1545 | iterator |
| 1546 | insert(const_iterator __position, initializer_list<value_type> __l) |
| 1547 | { |
| 1548 | auto __offset = __position - cbegin(); |
| 1549 | _M_range_insert(begin() + __offset, __l.begin(), __l.end(), |
| 1550 | std::random_access_iterator_tag()); |
| 1551 | return begin() + __offset; |
| 1552 | } |
| 1553 | #endif |
| 1554 | |
| 1555 | #if __cplusplus >= 201103L |
| 1556 | |
| 1557 | |
| 1558 | |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | |
| 1563 | |
| 1564 | |
| 1565 | |
| 1566 | |
| 1567 | |
| 1568 | |
| 1569 | |
| 1570 | _GLIBCXX20_CONSTEXPR |
| 1571 | iterator |
| 1572 | insert(const_iterator __position, size_type __n, const value_type& __x) |
| 1573 | { |
| 1574 | difference_type __offset = __position - cbegin(); |
| 1575 | _M_fill_insert(begin() + __offset, __n, __x); |
| 1576 | return begin() + __offset; |
| 1577 | } |
| 1578 | #else |
| 1579 | |
| 1580 | |
| 1581 | |
| 1582 | |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | |
| 1587 | |
| 1588 | |
| 1589 | |
| 1590 | |
| 1591 | |
| 1592 | void |
| 1593 | insert(iterator __position, size_type __n, const value_type& __x) |
| 1594 | { _M_fill_insert(__position, __n, __x); } |
| 1595 | #endif |
| 1596 | |
| 1597 | #if __cplusplus >= 201103L |
| 1598 | |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | |
| 1603 | |
| 1604 | |
| 1605 | |
| 1606 | |
| 1607 | |
| 1608 | |
| 1609 | |
| 1610 | |
| 1611 | |
| 1612 | |
| 1613 | template<typename _InputIterator, |
| 1614 | typename = std::_RequireInputIter<_InputIterator>> |
| 1615 | _GLIBCXX20_CONSTEXPR |
| 1616 | iterator |
| 1617 | insert(const_iterator __position, _InputIterator __first, |
| 1618 | _InputIterator __last) |
| 1619 | { |
| 1620 | difference_type __offset = __position - cbegin(); |
| 1621 | _M_range_insert(begin() + __offset, __first, __last, |
| 1622 | std::__iterator_category(__first)); |
| 1623 | return begin() + __offset; |
| 1624 | } |
| 1625 | #else |
| 1626 | |
| 1627 | |
| 1628 | |
| 1629 | |
| 1630 | |
| 1631 | |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | |
| 1637 | |
| 1638 | |
| 1639 | |
| 1640 | template<typename _InputIterator> |
| 1641 | void |
| 1642 | insert(iterator __position, _InputIterator __first, |
| 1643 | _InputIterator __last) |
| 1644 | { |
| 1645 | |
| 1646 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
| 1647 | _M_insert_dispatch(__position, __first, __last, _Integral()); |
| 1648 | } |
| 1649 | #endif |
| 1650 | |
| 1651 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 1652 | |
| 1653 | |
| 1654 | |
| 1655 | |
| 1656 | |
| 1657 | |
| 1658 | |
| 1659 | |
| 1660 | template<__detail::__container_compatible_range<_Tp> _Rg> |
| 1661 | constexpr iterator |
| 1662 | insert_range(const_iterator __pos, _Rg&& __rg); |
| 1663 | |
| 1664 | |
| 1665 | |
| 1666 | |
| 1667 | |
| 1668 | |
| 1669 | template<__detail::__container_compatible_range<_Tp> _Rg> |
| 1670 | constexpr void |
| 1671 | append_range(_Rg&& __rg) |
| 1672 | { |
| 1673 | |
| 1674 | |
| 1675 | |
| 1676 | if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>) |
| 1677 | { |
| 1678 | const auto __n = size_type(ranges::distance(__rg)); |
| 1679 | |
| 1680 | |
| 1681 | |
| 1682 | if (capacity() == 0) |
| 1683 | reserve(__n); |
| 1684 | |
| 1685 | const auto __sz = size(); |
| 1686 | const auto __capacity = capacity(); |
| 1687 | if ((__capacity - __sz) >= __n) |
| 1688 | { |
| 1689 | _GLIBCXX_ASAN_ANNOTATE_GROW(__n); |
| 1690 | _Base::_M_append_range(__rg); |
| 1691 | _GLIBCXX_ASAN_ANNOTATE_GREW(__n); |
| 1692 | return; |
| 1693 | } |
| 1694 | |
| 1695 | const size_type __len = _M_check_len(__n, "vector::append_range"); |
| 1696 | |
| 1697 | pointer __old_start = this->_M_impl._M_start; |
| 1698 | pointer __old_finish = this->_M_impl._M_finish; |
| 1699 | |
| 1700 | allocator_type& __a = _M_get_Tp_allocator(); |
| 1701 | const pointer __start = this->_M_allocate(__len); |
| 1702 | const pointer __mid = __start + __sz; |
| 1703 | const pointer __back = __mid + __n; |
| 1704 | _Guard_alloc __guard(__start, __len, *this); |
| 1705 | std::__uninitialized_copy_a(ranges::begin(__rg), |
| 1706 | ranges::end(__rg), |
| 1707 | __mid, __a); |
| 1708 | |
| 1709 | if constexpr (_S_use_relocate()) |
| 1710 | _S_relocate(__old_start, __old_finish, __start, __a); |
| 1711 | else |
| 1712 | { |
| 1713 | |
| 1714 | struct _Guard_elts |
| 1715 | { |
| 1716 | pointer _M_first, _M_last; |
| 1717 | _Tp_alloc_type& _M_alloc; |
| 1718 | |
| 1719 | constexpr |
| 1720 | _Guard_elts(pointer __f, pointer __l, _Tp_alloc_type& __a) |
| 1721 | : _M_first(__f), _M_last(__l), _M_alloc(__a) |
| 1722 | { } |
| 1723 | |
| 1724 | constexpr |
| 1725 | ~_Guard_elts() |
| 1726 | { std::_Destroy(_M_first, _M_last, _M_alloc); } |
| 1727 | |
| 1728 | _Guard_elts(_Guard_elts&&) = delete; |
| 1729 | }; |
| 1730 | _Guard_elts __guard_elts{__mid, __back, __a}; |
| 1731 | |
| 1732 | std::__uninitialized_move_a(__old_start, __old_finish, |
| 1733 | __start, __a); |
| 1734 | |
| 1735 | |
| 1736 | __guard_elts._M_first = __old_start; |
| 1737 | __guard_elts._M_last = __old_finish; |
| 1738 | } |
| 1739 | |
| 1740 | |
| 1741 | __guard._M_storage = __old_start; |
| 1742 | __guard._M_len = __capacity; |
| 1743 | |
| 1744 | this->_M_impl._M_start = __start; |
| 1745 | this->_M_impl._M_finish = __back; |
| 1746 | this->_M_impl._M_end_of_storage = __start + __len; |
| 1747 | } |
| 1748 | else |
| 1749 | { |
| 1750 | auto __first = ranges::begin(__rg); |
| 1751 | const auto __last = ranges::end(__rg); |
| 1752 | |
| 1753 | |
| 1754 | for (auto __free = capacity() - size(); |
| 1755 | __first != __last && __free > 0; |
| 1756 | ++__first, (void) --__free) |
| 1757 | emplace_back(*__first); |
| 1758 | |
| 1759 | if (__first == __last) |
| 1760 | return; |
| 1761 | |
| 1762 | |
| 1763 | vector __tmp(_M_get_Tp_allocator()); |
| 1764 | for (; __first != __last; ++__first) |
| 1765 | __tmp.emplace_back(*__first); |
| 1766 | reserve(_M_check_len(__tmp.size(), "vector::append_range")); |
| 1767 | ranges::subrange __r(std::make_move_iterator(__tmp.begin()), |
| 1768 | std::make_move_iterator(__tmp.end())); |
| 1769 | append_range(__r); |
| 1770 | } |
| 1771 | } |
| 1772 | #endif // containers_ranges |
| 1773 | |
| 1774 | |
| 1775 | |
| 1776 | |
| 1777 | |
| 1778 | |
| 1779 | |
| 1780 | |
| 1781 | |
| 1782 | |
| 1783 | |
| 1784 | |
| 1785 | |
| 1786 | |
| 1787 | |
| 1788 | |
| 1789 | _GLIBCXX20_CONSTEXPR |
| 1790 | iterator |
| 1791 | #if __cplusplus >= 201103L |
| 1792 | erase(const_iterator __position) |
| 1793 | { return _M_erase(begin() + (__position - cbegin())); } |
| 1794 | #else |
| 1795 | erase(iterator __position) |
| 1796 | { return _M_erase(__position); } |
| 1797 | #endif |
| 1798 | |
| 1799 | |
| 1800 | |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | |
| 1808 | |
| 1809 | |
| 1810 | |
| 1811 | |
| 1812 | |
| 1813 | |
| 1814 | |
| 1815 | |
| 1816 | |
| 1817 | _GLIBCXX20_CONSTEXPR |
| 1818 | iterator |
| 1819 | #if __cplusplus >= 201103L |
| 1820 | erase(const_iterator __first, const_iterator __last) |
| 1821 | { |
| 1822 | const auto __beg = begin(); |
| 1823 | const auto __cbeg = cbegin(); |
| 1824 | return _M_erase(__beg + (__first - __cbeg), __beg + (__last - __cbeg)); |
| 1825 | } |
| 1826 | #else |
| 1827 | erase(iterator __first, iterator __last) |
| 1828 | { return _M_erase(__first, __last); } |
| 1829 | #endif |
| 1830 | |
| 1831 | |
| 1832 | |
| 1833 | |
| 1834 | |
| 1835 | |
| 1836 | |
| 1837 | |
| 1838 | |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | _GLIBCXX20_CONSTEXPR |
| 1843 | void |
| 1844 | swap(vector& __x) _GLIBCXX_NOEXCEPT |
| 1845 | { |
| 1846 | #if __cplusplus >= 201103L |
| 1847 | __glibcxx_assert(_Alloc_traits::propagate_on_container_swap::value |
| 1848 | || _M_get_Tp_allocator() == __x._M_get_Tp_allocator()); |
| 1849 | #endif |
| 1850 | this->_M_impl._M_swap_data(__x._M_impl); |
| 1851 | _Alloc_traits::_S_on_swap(_M_get_Tp_allocator(), |
| 1852 | __x._M_get_Tp_allocator()); |
| 1853 | } |
| 1854 | |
| 1855 | |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | _GLIBCXX20_CONSTEXPR |
| 1862 | void |
| 1863 | clear() _GLIBCXX_NOEXCEPT |
| 1864 | { _M_erase_at_end(this->_M_impl._M_start); } |
| 1865 | |
| 1866 | private: |
| 1867 | |
| 1868 | struct _Guard_alloc |
| 1869 | { |
| 1870 | pointer _M_storage; |
| 1871 | size_type _M_len; |
| 1872 | _Base& _M_vect; |
| 1873 | |
| 1874 | _GLIBCXX20_CONSTEXPR |
| 1875 | _Guard_alloc(pointer __s, size_type __l, _Base& __vect) |
| 1876 | : _M_storage(__s), _M_len(__l), _M_vect(__vect) |
| 1877 | { } |
| 1878 | |
| 1879 | _GLIBCXX20_CONSTEXPR |
| 1880 | ~_Guard_alloc() |
| 1881 | { |
| 1882 | if (_M_storage) |
| 1883 | _M_vect._M_deallocate(_M_storage, _M_len); |
| 1884 | } |
| 1885 | |
| 1886 | _GLIBCXX20_CONSTEXPR |
| 1887 | pointer |
| 1888 | _M_release() |
| 1889 | { |
| 1890 | pointer __res = _M_storage; |
| 1891 | _M_storage = pointer(); |
| 1892 | return __res; |
| 1893 | } |
| 1894 | |
| 1895 | private: |
| 1896 | _Guard_alloc(const _Guard_alloc&); |
| 1897 | }; |
| 1898 | |
| 1899 | protected: |
| 1900 | |
| 1901 | |
| 1902 | |
| 1903 | |
| 1904 | template<typename _ForwardIterator> |
| 1905 | _GLIBCXX20_CONSTEXPR |
| 1906 | pointer |
| 1907 | _M_allocate_and_copy(size_type __n, |
| 1908 | _ForwardIterator __first, _ForwardIterator __last) |
| 1909 | { |
| 1910 | _Guard_alloc __guard(this->_M_allocate(__n), __n, *this); |
| 1911 | std::__uninitialized_copy_a |
| 1912 | (__first, __last, __guard._M_storage, _M_get_Tp_allocator()); |
| 1913 | return __guard._M_release(); |
| 1914 | } |
| 1915 | |
| 1916 | |
| 1917 | |
| 1918 | |
| 1919 | |
| 1920 | |
| 1921 | #if __cplusplus < 201103L |
| 1922 | |
| 1923 | |
| 1924 | template<typename _Integer> |
| 1925 | void |
| 1926 | _M_initialize_dispatch(_Integer __int_n, _Integer __value, __true_type) |
| 1927 | { |
| 1928 | const size_type __n = static_cast<size_type>(__int_n); |
| 1929 | pointer __start = |
| 1930 | _M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator())); |
| 1931 | this->_M_impl._M_start = __start; |
| 1932 | this->_M_impl._M_end_of_storage = __start + __n; |
| 1933 | _M_fill_initialize(__n, __value); |
| 1934 | } |
| 1935 | |
| 1936 | |
| 1937 | template<typename _InputIterator> |
| 1938 | void |
| 1939 | _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, |
| 1940 | __false_type) |
| 1941 | { |
| 1942 | _M_range_initialize(__first, __last, |
| 1943 | std::__iterator_category(__first)); |
| 1944 | } |
| 1945 | #endif |
| 1946 | |
| 1947 | |
| 1948 | template<typename _InputIterator> |
| 1949 | _GLIBCXX20_CONSTEXPR |
| 1950 | void |
| 1951 | _M_range_initialize(_InputIterator __first, _InputIterator __last, |
| 1952 | std::input_iterator_tag) |
| 1953 | { |
| 1954 | __try { |
| 1955 | for (; __first != __last; ++__first) |
| 1956 | #if __cplusplus >= 201103L |
| 1957 | emplace_back(*__first); |
| 1958 | #else |
| 1959 | push_back(*__first); |
| 1960 | #endif |
| 1961 | } __catch(...) { |
| 1962 | clear(); |
| 1963 | __throw_exception_again; |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | |
| 1968 | template<typename _ForwardIterator> |
| 1969 | _GLIBCXX20_CONSTEXPR |
| 1970 | void |
| 1971 | _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last, |
| 1972 | std::forward_iterator_tag) |
| 1973 | { |
| 1974 | _M_range_initialize_n(__first, __last, |
| 1975 | std::distance(__first, __last)); |
| 1976 | } |
| 1977 | |
| 1978 | template<typename _Iterator, typename _Sentinel> |
| 1979 | _GLIBCXX20_CONSTEXPR |
| 1980 | void |
| 1981 | _M_range_initialize_n(_Iterator __first, _Sentinel __last, |
| 1982 | size_type __n) |
| 1983 | { |
| 1984 | pointer __start = |
| 1985 | this->_M_allocate(_S_check_init_len(__n, _M_get_Tp_allocator())); |
| 1986 | this->_M_impl._M_start = this->_M_impl._M_finish = __start; |
| 1987 | this->_M_impl._M_end_of_storage = __start + __n; |
| 1988 | this->_M_impl._M_finish |
| 1989 | = std::__uninitialized_copy_a(_GLIBCXX_MOVE(__first), __last, |
| 1990 | __start, _M_get_Tp_allocator()); |
| 1991 | } |
| 1992 | |
| 1993 | |
| 1994 | |
| 1995 | _GLIBCXX20_CONSTEXPR |
| 1996 | void |
| 1997 | _M_fill_initialize(size_type __n, const value_type& __value) |
| 1998 | { |
| 1999 | this->_M_impl._M_finish = |
| 2000 | std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value, |
| 2001 | _M_get_Tp_allocator()); |
| 2002 | } |
| 2003 | |
| 2004 | #if __cplusplus >= 201103L |
| 2005 | |
| 2006 | _GLIBCXX20_CONSTEXPR |
| 2007 | void |
| 2008 | _M_default_initialize(size_type __n) |
| 2009 | { |
| 2010 | this->_M_impl._M_finish = |
| 2011 | std::__uninitialized_default_n_a(this->_M_impl._M_start, __n, |
| 2012 | _M_get_Tp_allocator()); |
| 2013 | } |
| 2014 | #endif |
| 2015 | |
| 2016 | |
| 2017 | |
| 2018 | |
| 2019 | |
| 2020 | |
| 2021 | |
| 2022 | |
| 2023 | template<typename _Integer> |
| 2024 | _GLIBCXX20_CONSTEXPR |
| 2025 | void |
| 2026 | _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) |
| 2027 | { _M_fill_assign(__n, __val); } |
| 2028 | |
| 2029 | |
| 2030 | template<typename _InputIterator> |
| 2031 | _GLIBCXX20_CONSTEXPR |
| 2032 | void |
| 2033 | _M_assign_dispatch(_InputIterator __first, _InputIterator __last, |
| 2034 | __false_type) |
| 2035 | { _M_assign_aux(__first, __last, std::__iterator_category(__first)); } |
| 2036 | |
| 2037 | |
| 2038 | template<typename _InputIterator> |
| 2039 | _GLIBCXX20_CONSTEXPR |
| 2040 | void |
| 2041 | _M_assign_aux(_InputIterator __first, _InputIterator __last, |
| 2042 | std::input_iterator_tag); |
| 2043 | |
| 2044 | |
| 2045 | template<typename _ForwardIterator> |
| 2046 | _GLIBCXX20_CONSTEXPR |
| 2047 | void |
| 2048 | _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, |
| 2049 | std::forward_iterator_tag); |
| 2050 | |
| 2051 | |
| 2052 | |
| 2053 | _GLIBCXX20_CONSTEXPR |
| 2054 | void |
| 2055 | _M_fill_assign(size_type __n, const value_type& __val); |
| 2056 | |
| 2057 | |
| 2058 | |
| 2059 | |
| 2060 | |
| 2061 | |
| 2062 | |
| 2063 | template<typename _Integer> |
| 2064 | _GLIBCXX20_CONSTEXPR |
| 2065 | void |
| 2066 | _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val, |
| 2067 | __true_type) |
| 2068 | { _M_fill_insert(__pos, __n, __val); } |
| 2069 | |
| 2070 | |
| 2071 | template<typename _InputIterator> |
| 2072 | _GLIBCXX20_CONSTEXPR |
| 2073 | void |
| 2074 | _M_insert_dispatch(iterator __pos, _InputIterator __first, |
| 2075 | _InputIterator __last, __false_type) |
| 2076 | { |
| 2077 | _M_range_insert(__pos, __first, __last, |
| 2078 | std::__iterator_category(__first)); |
| 2079 | } |
| 2080 | |
| 2081 | |
| 2082 | template<typename _InputIterator> |
| 2083 | _GLIBCXX20_CONSTEXPR |
| 2084 | void |
| 2085 | _M_range_insert(iterator __pos, _InputIterator __first, |
| 2086 | _InputIterator __last, std::input_iterator_tag); |
| 2087 | |
| 2088 | |
| 2089 | template<typename _ForwardIterator> |
| 2090 | _GLIBCXX20_CONSTEXPR |
| 2091 | void |
| 2092 | _M_range_insert(iterator __pos, _ForwardIterator __first, |
| 2093 | _ForwardIterator __last, std::forward_iterator_tag); |
| 2094 | |
| 2095 | |
| 2096 | |
| 2097 | _GLIBCXX20_CONSTEXPR |
| 2098 | void |
| 2099 | _M_fill_insert(iterator __pos, size_type __n, const value_type& __x); |
| 2100 | |
| 2101 | #if __cplusplus >= 201103L |
| 2102 | |
| 2103 | _GLIBCXX20_CONSTEXPR |
| 2104 | void |
| 2105 | _M_default_append(size_type __n); |
| 2106 | |
| 2107 | _GLIBCXX20_CONSTEXPR |
| 2108 | bool |
| 2109 | _M_shrink_to_fit(); |
| 2110 | #endif |
| 2111 | |
| 2112 | #if __cplusplus < 201103L |
| 2113 | |
| 2114 | void |
| 2115 | _M_insert_aux(iterator __position, const value_type& __x); |
| 2116 | |
| 2117 | void |
| 2118 | _M_realloc_insert(iterator __position, const value_type& __x); |
| 2119 | |
| 2120 | void |
| 2121 | _M_realloc_append(const value_type& __x); |
| 2122 | #else |
| 2123 | |
| 2124 | |
| 2125 | struct _Temporary_value |
| 2126 | { |
| 2127 | template<typename... _Args> |
| 2128 | _GLIBCXX20_CONSTEXPR explicit |
| 2129 | _Temporary_value(vector* __vec, _Args&&... __args) : _M_this(__vec) |
| 2130 | { |
| 2131 | _Alloc_traits::construct(_M_this->_M_impl, _M_ptr(), |
| 2132 | std::forward<_Args>(__args)...); |
| 2133 | } |
| 2134 | |
| 2135 | _GLIBCXX20_CONSTEXPR |
| 2136 | ~_Temporary_value() |
| 2137 | { _Alloc_traits::destroy(_M_this->_M_impl, _M_ptr()); } |
| 2138 | |
| 2139 | _GLIBCXX20_CONSTEXPR value_type& |
| 2140 | _M_val() noexcept { return _M_storage._M_val; } |
| 2141 | |
| 2142 | private: |
| 2143 | _GLIBCXX20_CONSTEXPR _Tp* |
| 2144 | _M_ptr() noexcept { return std::__addressof(_M_storage._M_val); } |
| 2145 | |
| 2146 | union _Storage |
| 2147 | { |
| 2148 | constexpr _Storage() : _M_byte() { } |
| 2149 | _GLIBCXX20_CONSTEXPR ~_Storage() { } |
| 2150 | _Storage& operator=(const _Storage&) = delete; |
| 2151 | unsigned char _M_byte; |
| 2152 | _Tp _M_val; |
| 2153 | }; |
| 2154 | |
| 2155 | vector* _M_this; |
| 2156 | _Storage _M_storage; |
| 2157 | }; |
| 2158 | |
| 2159 | |
| 2160 | |
| 2161 | template<typename _Arg> |
| 2162 | _GLIBCXX20_CONSTEXPR |
| 2163 | void |
| 2164 | _M_insert_aux(iterator __position, _Arg&& __arg); |
| 2165 | |
| 2166 | template<typename... _Args> |
| 2167 | _GLIBCXX20_CONSTEXPR |
| 2168 | void |
| 2169 | _M_realloc_insert(iterator __position, _Args&&... __args); |
| 2170 | |
| 2171 | template<typename... _Args> |
| 2172 | _GLIBCXX20_CONSTEXPR |
| 2173 | void |
| 2174 | _M_realloc_append(_Args&&... __args); |
| 2175 | |
| 2176 | |
| 2177 | _GLIBCXX20_CONSTEXPR |
| 2178 | iterator |
| 2179 | _M_insert_rval(const_iterator __position, value_type&& __v); |
| 2180 | |
| 2181 | |
| 2182 | template<typename... _Args> |
| 2183 | _GLIBCXX20_CONSTEXPR |
| 2184 | iterator |
| 2185 | _M_emplace_aux(const_iterator __position, _Args&&... __args); |
| 2186 | |
| 2187 | |
| 2188 | _GLIBCXX20_CONSTEXPR |
| 2189 | iterator |
| 2190 | _M_emplace_aux(const_iterator __position, value_type&& __v) |
| 2191 | { return _M_insert_rval(__position, std::move(__v)); } |
| 2192 | #endif |
| 2193 | |
| 2194 | |
| 2195 | _GLIBCXX20_CONSTEXPR |
| 2196 | size_type |
| 2197 | _M_check_len(size_type __n, const char* __s) const |
| 2198 | { |
| 2199 | if (max_size() - size() < __n) |
| 2200 | __throw_length_error(__N(__s)); |
| 2201 | |
| 2202 | const size_type __len = size() + (std::max)(size(), __n); |
| 2203 | return (__len < size() || __len > max_size()) ? max_size() : __len; |
| 2204 | } |
| 2205 | |
| 2206 | |
| 2207 | static _GLIBCXX20_CONSTEXPR size_type |
| 2208 | _S_check_init_len(size_type __n, const allocator_type& __a) |
| 2209 | { |
| 2210 | if (__n > _S_max_size(_Tp_alloc_type(__a))) |
| 2211 | __throw_length_error( |
| 2212 | __N("cannot create std::vector larger than max_size()")); |
| 2213 | return __n; |
| 2214 | } |
| 2215 | |
| 2216 | static _GLIBCXX20_CONSTEXPR size_type |
| 2217 | _S_max_size(const _Tp_alloc_type& __a) _GLIBCXX_NOEXCEPT |
| 2218 | { |
| 2219 | |
| 2220 | |
| 2221 | |
| 2222 | const size_t __diffmax |
| 2223 | = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max / sizeof(_Tp); |
| 2224 | const size_t __allocmax = _Alloc_traits::max_size(__a); |
| 2225 | return (std::min)(__diffmax, __allocmax); |
| 2226 | } |
| 2227 | |
| 2228 | |
| 2229 | |
| 2230 | |
| 2231 | |
| 2232 | _GLIBCXX20_CONSTEXPR |
| 2233 | void |
| 2234 | _M_erase_at_end(pointer __pos) _GLIBCXX_NOEXCEPT |
| 2235 | { |
| 2236 | if (size_type __n = this->_M_impl._M_finish - __pos) |
| 2237 | { |
| 2238 | std::_Destroy(__pos, this->_M_impl._M_finish, |
| 2239 | _M_get_Tp_allocator()); |
| 2240 | this->_M_impl._M_finish = __pos; |
| 2241 | _GLIBCXX_ASAN_ANNOTATE_SHRINK(__n); |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | _GLIBCXX20_CONSTEXPR |
| 2246 | iterator |
| 2247 | _M_erase(iterator __position); |
| 2248 | |
| 2249 | _GLIBCXX20_CONSTEXPR |
| 2250 | iterator |
| 2251 | _M_erase(iterator __first, iterator __last); |
| 2252 | |
| 2253 | #if __cplusplus >= 201103L |
| 2254 | private: |
| 2255 | |
| 2256 | |
| 2257 | |
| 2258 | _GLIBCXX20_CONSTEXPR |
| 2259 | void |
| 2260 | _M_move_assign(vector&& __x, true_type) noexcept |
| 2261 | { |
| 2262 | vector __tmp(get_allocator()); |
| 2263 | this->_M_impl._M_swap_data(__x._M_impl); |
| 2264 | __tmp._M_impl._M_swap_data(__x._M_impl); |
| 2265 | std::__alloc_on_move(_M_get_Tp_allocator(), __x._M_get_Tp_allocator()); |
| 2266 | } |
| 2267 | |
| 2268 | |
| 2269 | |
| 2270 | _GLIBCXX20_CONSTEXPR |
| 2271 | void |
| 2272 | _M_move_assign(vector&& __x, false_type) |
| 2273 | { |
| 2274 | if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator()) |
| 2275 | _M_move_assign(std::move(__x), true_type()); |
| 2276 | else |
| 2277 | { |
| 2278 | |
| 2279 | |
| 2280 | this->_M_assign_aux(std::make_move_iterator(__x.begin()), |
| 2281 | std::make_move_iterator(__x.end()), |
| 2282 | std::random_access_iterator_tag()); |
| 2283 | __x.clear(); |
| 2284 | } |
| 2285 | } |
| 2286 | #endif |
| 2287 | |
| 2288 | template<typename _Up> |
| 2289 | _GLIBCXX20_CONSTEXPR |
| 2290 | _Up* |
| 2291 | _M_data_ptr(_Up* __ptr) const _GLIBCXX_NOEXCEPT |
| 2292 | { return __ptr; } |
| 2293 | |
| 2294 | #if __cplusplus >= 201103L |
| 2295 | template<typename _Ptr> |
| 2296 | _GLIBCXX20_CONSTEXPR |
| 2297 | typename std::pointer_traits<_Ptr>::element_type* |
| 2298 | _M_data_ptr(_Ptr __ptr) const |
| 2299 | { return empty() ? nullptr : std::__to_address(__ptr); } |
| 2300 | #else |
| 2301 | template<typename _Ptr> |
| 2302 | value_type* |
| 2303 | _M_data_ptr(_Ptr __ptr) const |
| 2304 | { return empty() ? (value_type*)0 : __ptr.operator->(); } |
| 2305 | #endif |
| 2306 | }; |
| 2307 | |
| 2308 | #if __cpp_deduction_guides >= 201606 |
| 2309 | template<typename _InputIterator, typename _ValT |
| 2310 | = typename iterator_traits<_InputIterator>::value_type, |
| 2311 | typename _Allocator = allocator<_ValT>, |
| 2312 | typename = _RequireInputIter<_InputIterator>, |
| 2313 | typename = _RequireAllocator<_Allocator>> |
| 2314 | vector(_InputIterator, _InputIterator, _Allocator = _Allocator()) |
| 2315 | -> vector<_ValT, _Allocator>; |
| 2316 | |
| 2317 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 2318 | template<ranges::input_range _Rg, |
| 2319 | typename _Alloc = allocator<ranges::range_value_t<_Rg>>> |
| 2320 | vector(from_range_t, _Rg&&, _Alloc = _Alloc()) |
| 2321 | -> vector<ranges::range_value_t<_Rg>, _Alloc>; |
| 2322 | #endif |
| 2323 | #endif |
| 2324 | |
| 2325 | |
| 2326 | |
| 2327 | |
| 2328 | |
| 2329 | |
| 2330 | |
| 2331 | |
| 2332 | |
| 2333 | |
| 2334 | |
| 2335 | template<typename _Tp, typename _Alloc> |
| 2336 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 2337 | inline bool |
| 2338 | operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) |
| 2339 | { return (__x.size() == __y.size() |
| 2340 | && std::equal(__x.begin(), __x.end(), __y.begin())); } |
| 2341 | |
| 2342 | #if __cpp_lib_three_way_comparison // >= C++20 |
| 2343 | |
| 2344 | |
| 2345 | |
| 2346 | |
| 2347 | |
| 2348 | |
| 2349 | |
| 2350 | |
| 2351 | |
| 2352 | |
| 2353 | |
| 2354 | template<typename _Tp, typename _Alloc> |
| 2355 | [[nodiscard]] |
| 2356 | constexpr __detail::__synth3way_t<_Tp> |
| 2357 | operator<=>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) |
| 2358 | { |
| 2359 | return std::lexicographical_compare_three_way(__x.begin(), __x.end(), |
| 2360 | __y.begin(), __y.end(), |
| 2361 | __detail::__synth3way); |
| 2362 | } |
| 2363 | #else |
| 2364 | |
| 2365 | |
| 2366 | |
| 2367 | |
| 2368 | |
| 2369 | |
| 2370 | |
| 2371 | |
| 2372 | |
| 2373 | |
| 2374 | |
| 2375 | template<typename _Tp, typename _Alloc> |
| 2376 | _GLIBCXX_NODISCARD inline bool |
| 2377 | operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) |
| 2378 | { return std::lexicographical_compare(__x.begin(), __x.end(), |
| 2379 | __y.begin(), __y.end()); } |
| 2380 | |
| 2381 | |
| 2382 | template<typename _Tp, typename _Alloc> |
| 2383 | _GLIBCXX_NODISCARD inline bool |
| 2384 | operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) |
| 2385 | { return !(__x == __y); } |
| 2386 | |
| 2387 | |
| 2388 | template<typename _Tp, typename _Alloc> |
| 2389 | _GLIBCXX_NODISCARD inline bool |
| 2390 | operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) |
| 2391 | { return __y < __x; } |
| 2392 | |
| 2393 | |
| 2394 | template<typename _Tp, typename _Alloc> |
| 2395 | _GLIBCXX_NODISCARD inline bool |
| 2396 | operator<=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) |
| 2397 | { return !(__y < __x); } |
| 2398 | |
| 2399 | |
| 2400 | template<typename _Tp, typename _Alloc> |
| 2401 | _GLIBCXX_NODISCARD inline bool |
| 2402 | operator>=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) |
| 2403 | { return !(__x < __y); } |
| 2404 | #endif // three-way comparison |
| 2405 | |
| 2406 | |
| 2407 | template<typename _Tp, typename _Alloc> |
| 2408 | _GLIBCXX20_CONSTEXPR |
| 2409 | inline void |
| 2410 | swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y) |
| 2411 | _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y))) |
| 2412 | { __x.swap(__y); } |
| 2413 | |
| 2414 | _GLIBCXX_END_NAMESPACE_CONTAINER |
| 2415 | |
| 2416 | #if __cplusplus >= 201703L |
| 2417 | namespace __detail::__variant |
| 2418 | { |
| 2419 | template<typename> struct _Never_valueless_alt; |
| 2420 | |
| 2421 | |
| 2422 | |
| 2423 | template<typename _Tp, typename _Alloc> |
| 2424 | struct _Never_valueless_alt<_GLIBCXX_STD_C::vector<_Tp, _Alloc>> |
| 2425 | : std::is_nothrow_move_assignable<_GLIBCXX_STD_C::vector<_Tp, _Alloc>> |
| 2426 | { }; |
| 2427 | } |
| 2428 | #endif // C++17 |
| 2429 | |
| 2430 | _GLIBCXX_END_NAMESPACE_VERSION |
| 2431 | } |
| 2432 | |
| 2433 | #endif /* _STL_VECTOR_H */ |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | #ifndef _BASIC_STRING_H |
| 35 | #define _BASIC_STRING_H 1 |
| 36 | |
| 37 | #ifdef _GLIBCXX_SYSHDR |
| 38 | #pragma GCC system_header |
| 39 | #endif |
| 40 | |
| 41 | #include <ext/alloc_traits.h> |
| 42 | #include <debug/debug.h> |
| 43 | |
| 44 | #if __cplusplus >= 201103L |
| 45 | #include <initializer_list> |
| 46 | #endif |
| 47 | |
| 48 | #include <bits/version.h> |
| 49 | |
| 50 | #ifdef __glibcxx_string_view // >= C++17 |
| 51 | # include <string_view> |
| 52 | #endif |
| 53 | |
| 54 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 55 | # include <bits/ranges_algobase.h> // ranges::copy |
| 56 | # include <bits/ranges_util.h> // ranges::subrange |
| 57 | #endif |
| 58 | |
| 59 | #if __cplusplus > 202302L |
| 60 | # include <charconv> |
| 61 | #endif |
| 62 | |
| 63 | |
| 64 | #if ! _GLIBCXX_USE_CXX11_ABI |
| 65 | # include "cow_string.h" |
| 66 | #else |
| 67 | |
| 68 | namespace std _GLIBCXX_VISIBILITY(default) |
| 69 | { |
| 70 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 71 | _GLIBCXX_BEGIN_NAMESPACE_CXX11 |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 94 | class basic_string |
| 95 | { |
| 96 | #if __cplusplus >= 202002L |
| 97 | static_assert(is_trivially_copyable_v<_CharT> |
| 98 | && is_trivially_default_constructible_v<_CharT> |
| 99 | && is_standard_layout_v<_CharT>); |
| 100 | static_assert(is_same_v<_CharT, typename _Traits::char_type>); |
| 101 | static_assert(is_same_v<_CharT, typename _Alloc::value_type>); |
| 102 | using _Char_alloc_type = _Alloc; |
| 103 | #else |
| 104 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
| 105 | rebind<_CharT>::other _Char_alloc_type; |
| 106 | #endif |
| 107 | |
| 108 | typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits; |
| 109 | |
| 110 | |
| 111 | public: |
| 112 | typedef _Traits traits_type; |
| 113 | typedef typename _Traits::char_type value_type; |
| 114 | typedef _Char_alloc_type allocator_type; |
| 115 | typedef typename _Alloc_traits::size_type size_type; |
| 116 | typedef typename _Alloc_traits::difference_type difference_type; |
| 117 | typedef typename _Alloc_traits::reference reference; |
| 118 | typedef typename _Alloc_traits::const_reference const_reference; |
| 119 | typedef typename _Alloc_traits::pointer pointer; |
| 120 | typedef typename _Alloc_traits::const_pointer const_pointer; |
| 121 | typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; |
| 122 | typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> |
| 123 | const_iterator; |
| 124 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 125 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 126 | |
| 127 | |
| 128 | static const size_type npos = static_cast<size_type>(-1); |
| 129 | |
| 130 | protected: |
| 131 | |
| 132 | #if __cplusplus < 201103L |
| 133 | typedef iterator __const_iterator; |
| 134 | #else |
| 135 | typedef const_iterator __const_iterator; |
| 136 | #endif |
| 137 | |
| 138 | private: |
| 139 | static _GLIBCXX20_CONSTEXPR pointer |
| 140 | _S_allocate(_Char_alloc_type& __a, size_type __n) |
| 141 | { |
| 142 | pointer __p = _Alloc_traits::allocate(__a, __n); |
| 143 | #if __glibcxx_constexpr_string >= 201907L |
| 144 | |
| 145 | |
| 146 | if constexpr (!is_same_v<_Traits, char_traits<_CharT>>) |
| 147 | if (std::__is_constant_evaluated()) |
| 148 | |
| 149 | for (size_type __i = 0; __i < __n; ++__i) |
| 150 | std::construct_at(__builtin_addressof(__p[__i])); |
| 151 | #endif |
| 152 | return __p; |
| 153 | } |
| 154 | |
| 155 | #ifdef __glibcxx_string_view // >= C++17 |
| 156 | |
| 157 | typedef basic_string_view<_CharT, _Traits> __sv_type; |
| 158 | |
| 159 | template<typename _Tp, typename _Res> |
| 160 | using _If_sv = enable_if_t< |
| 161 | __and_<is_convertible<const _Tp&, __sv_type>, |
| 162 | __not_<is_convertible<const _Tp*, const basic_string*>>, |
| 163 | __not_<is_convertible<const _Tp&, const _CharT*>>>::value, |
| 164 | _Res>; |
| 165 | |
| 166 | |
| 167 | _GLIBCXX20_CONSTEXPR |
| 168 | static __sv_type |
| 169 | _S_to_string_view(__sv_type __svt) noexcept |
| 170 | { return __svt; } |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | struct __sv_wrapper |
| 177 | { |
| 178 | _GLIBCXX20_CONSTEXPR explicit |
| 179 | __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { } |
| 180 | |
| 181 | __sv_type _M_sv; |
| 182 | }; |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | _GLIBCXX20_CONSTEXPR |
| 191 | explicit |
| 192 | basic_string(__sv_wrapper __svw, const _Alloc& __a) |
| 193 | : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { } |
| 194 | #endif |
| 195 | |
| 196 | |
| 197 | struct _Alloc_hider : allocator_type |
| 198 | { |
| 199 | #if __cplusplus < 201103L |
| 200 | _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc()) |
| 201 | : allocator_type(__a), _M_p(__dat) { } |
| 202 | #else |
| 203 | _GLIBCXX20_CONSTEXPR |
| 204 | _Alloc_hider(pointer __dat, const _Alloc& __a) |
| 205 | : allocator_type(__a), _M_p(__dat) { } |
| 206 | |
| 207 | _GLIBCXX20_CONSTEXPR |
| 208 | _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc()) |
| 209 | : allocator_type(std::move(__a)), _M_p(__dat) { } |
| 210 | #endif |
| 211 | |
| 212 | pointer _M_p; |
| 213 | }; |
| 214 | |
| 215 | _Alloc_hider _M_dataplus; |
| 216 | size_type _M_string_length; |
| 217 | |
| 218 | enum { _S_local_capacity = 15 / sizeof(_CharT) }; |
| 219 | |
| 220 | union |
| 221 | { |
| 222 | _CharT _M_local_buf[_S_local_capacity + 1]; |
| 223 | size_type _M_allocated_capacity; |
| 224 | }; |
| 225 | |
| 226 | _GLIBCXX20_CONSTEXPR |
| 227 | void |
| 228 | _M_data(pointer __p) |
| 229 | { _M_dataplus._M_p = __p; } |
| 230 | |
| 231 | _GLIBCXX20_CONSTEXPR |
| 232 | void |
| 233 | _M_length(size_type __length) |
| 234 | { _M_string_length = __length; } |
| 235 | |
| 236 | _GLIBCXX20_CONSTEXPR |
| 237 | pointer |
| 238 | _M_data() const |
| 239 | { return _M_dataplus._M_p; } |
| 240 | |
| 241 | _GLIBCXX20_CONSTEXPR |
| 242 | pointer |
| 243 | _M_local_data() |
| 244 | { |
| 245 | #if __cplusplus >= 201103L |
| 246 | return std::pointer_traits<pointer>::pointer_to(*_M_local_buf); |
| 247 | #else |
| 248 | return pointer(_M_local_buf); |
| 249 | #endif |
| 250 | } |
| 251 | |
| 252 | _GLIBCXX20_CONSTEXPR |
| 253 | const_pointer |
| 254 | _M_local_data() const |
| 255 | { |
| 256 | #if __cplusplus >= 201103L |
| 257 | return std::pointer_traits<const_pointer>::pointer_to(*_M_local_buf); |
| 258 | #else |
| 259 | return const_pointer(_M_local_buf); |
| 260 | #endif |
| 261 | } |
| 262 | |
| 263 | _GLIBCXX20_CONSTEXPR |
| 264 | void |
| 265 | _M_capacity(size_type __capacity) |
| 266 | { _M_allocated_capacity = __capacity; } |
| 267 | |
| 268 | _GLIBCXX20_CONSTEXPR |
| 269 | void |
| 270 | _M_set_length(size_type __n) |
| 271 | { |
| 272 | _M_length(__n); |
| 273 | traits_type::assign(_M_data()[__n], _CharT()); |
| 274 | } |
| 275 | |
| 276 | _GLIBCXX20_CONSTEXPR |
| 277 | bool |
| 278 | _M_is_local() const |
| 279 | { |
| 280 | if (_M_data() == _M_local_data()) |
| 281 | { |
| 282 | if (_M_string_length > _S_local_capacity) |
| 283 | __builtin_unreachable(); |
| 284 | return true; |
| 285 | } |
| 286 | return false; |
| 287 | } |
| 288 | |
| 289 | |
| 290 | _GLIBCXX20_CONSTEXPR |
| 291 | pointer |
| 292 | _M_create(size_type&, size_type); |
| 293 | |
| 294 | _GLIBCXX20_CONSTEXPR |
| 295 | void |
| 296 | _M_dispose() |
| 297 | { |
| 298 | if (!_M_is_local()) |
| 299 | _M_destroy(_M_allocated_capacity); |
| 300 | } |
| 301 | |
| 302 | _GLIBCXX20_CONSTEXPR |
| 303 | void |
| 304 | _M_destroy(size_type __size) throw() |
| 305 | { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); } |
| 306 | |
| 307 | #if __cplusplus < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 308 | |
| 309 | |
| 310 | template<typename _InIterator> |
| 311 | void |
| 312 | _M_construct_aux(_InIterator __beg, _InIterator __end, |
| 313 | std::__false_type) |
| 314 | { |
| 315 | typedef typename iterator_traits<_InIterator>::iterator_category _Tag; |
| 316 | _M_construct(__beg, __end, _Tag()); |
| 317 | } |
| 318 | |
| 319 | |
| 320 | |
| 321 | template<typename _Integer> |
| 322 | void |
| 323 | _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type) |
| 324 | { _M_construct_aux_2(static_cast<size_type>(__beg), __end); } |
| 325 | |
| 326 | void |
| 327 | _M_construct_aux_2(size_type __req, _CharT __c) |
| 328 | { _M_construct(__req, __c); } |
| 329 | #endif |
| 330 | |
| 331 | |
| 332 | template<typename _InIterator> |
| 333 | _GLIBCXX20_CONSTEXPR |
| 334 | void |
| 335 | _M_construct(_InIterator __beg, _InIterator __end, |
| 336 | std::input_iterator_tag); |
| 337 | |
| 338 | |
| 339 | |
| 340 | template<typename _FwdIterator> |
| 341 | _GLIBCXX20_CONSTEXPR |
| 342 | void |
| 343 | _M_construct(_FwdIterator __beg, _FwdIterator __end, |
| 344 | std::forward_iterator_tag); |
| 345 | |
| 346 | _GLIBCXX20_CONSTEXPR |
| 347 | void |
| 348 | _M_construct(size_type __req, _CharT __c); |
| 349 | |
| 350 | |
| 351 | |
| 352 | template<bool _Terminated> |
| 353 | _GLIBCXX20_CONSTEXPR |
| 354 | void |
| 355 | _M_construct(const _CharT *__c, size_type __n); |
| 356 | |
| 357 | _GLIBCXX20_CONSTEXPR |
| 358 | allocator_type& |
| 359 | _M_get_allocator() |
| 360 | { return _M_dataplus; } |
| 361 | |
| 362 | _GLIBCXX20_CONSTEXPR |
| 363 | const allocator_type& |
| 364 | _M_get_allocator() const |
| 365 | { return _M_dataplus; } |
| 366 | |
| 367 | |
| 368 | __attribute__((__always_inline__)) |
| 369 | _GLIBCXX14_CONSTEXPR |
| 370 | void |
| 371 | _M_init_local_buf() _GLIBCXX_NOEXCEPT |
| 372 | { |
| 373 | #if __glibcxx_is_constant_evaluated |
| 374 | if (std::is_constant_evaluated()) |
| 375 | for (size_type __i = 0; __i <= _S_local_capacity; ++__i) |
| 376 | _M_local_buf[__i] = _CharT(); |
| 377 | #endif |
| 378 | } |
| 379 | |
| 380 | __attribute__((__always_inline__)) |
| 381 | _GLIBCXX14_CONSTEXPR |
| 382 | pointer |
| 383 | _M_use_local_data() _GLIBCXX_NOEXCEPT |
| 384 | { |
| 385 | #if __cpp_lib_is_constant_evaluated |
| 386 | _M_init_local_buf(); |
| 387 | #endif |
| 388 | return _M_local_data(); |
| 389 | } |
| 390 | |
| 391 | private: |
| 392 | |
| 393 | #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST |
| 394 | |
| 395 | |
| 396 | template<typename _Tp, bool _Requires = |
| 397 | !__are_same<_Tp, _CharT*>::__value |
| 398 | && !__are_same<_Tp, const _CharT*>::__value |
| 399 | && !__are_same<_Tp, iterator>::__value |
| 400 | && !__are_same<_Tp, const_iterator>::__value> |
| 401 | struct __enable_if_not_native_iterator |
| 402 | { typedef basic_string& __type; }; |
| 403 | template<typename _Tp> |
| 404 | struct __enable_if_not_native_iterator<_Tp, false> { }; |
| 405 | #endif |
| 406 | |
| 407 | _GLIBCXX20_CONSTEXPR |
| 408 | size_type |
| 409 | _M_check(size_type __pos, const char* __s) const |
| 410 | { |
| 411 | if (__pos > this->size()) |
| 412 | __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " |
| 413 | "this->size() (which is %zu)"), |
| 414 | __s, __pos, this->size()); |
| 415 | return __pos; |
| 416 | } |
| 417 | |
| 418 | _GLIBCXX20_CONSTEXPR |
| 419 | void |
| 420 | _M_check_length(size_type __n1, size_type __n2, const char* __s) const |
| 421 | { |
| 422 | if (this->max_size() - (this->size() - __n1) < __n2) |
| 423 | __throw_length_error(__N(__s)); |
| 424 | } |
| 425 | |
| 426 | |
| 427 | |
| 428 | _GLIBCXX20_CONSTEXPR |
| 429 | size_type |
| 430 | _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT |
| 431 | { |
| 432 | const bool __testoff = __off < this->size() - __pos; |
| 433 | return __testoff ? __off : this->size() - __pos; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | bool |
| 438 | _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT |
| 439 | { |
| 440 | return (less<const _CharT*>()(__s, _M_data()) |
| 441 | || less<const _CharT*>()(_M_data() + this->size(), __s)); |
| 442 | } |
| 443 | |
| 444 | |
| 445 | |
| 446 | _GLIBCXX20_CONSTEXPR |
| 447 | static void |
| 448 | _S_copy(_CharT* __d, const _CharT* __s, size_type __n) |
| 449 | { |
| 450 | if (__n == 1) |
| 451 | traits_type::assign(*__d, *__s); |
| 452 | else |
| 453 | traits_type::copy(__d, __s, __n); |
| 454 | } |
| 455 | |
| 456 | _GLIBCXX20_CONSTEXPR |
| 457 | static void |
| 458 | _S_move(_CharT* __d, const _CharT* __s, size_type __n) |
| 459 | { |
| 460 | if (__n == 1) |
| 461 | traits_type::assign(*__d, *__s); |
| 462 | else |
| 463 | traits_type::move(__d, __s, __n); |
| 464 | } |
| 465 | |
| 466 | _GLIBCXX20_CONSTEXPR |
| 467 | static void |
| 468 | _S_assign(_CharT* __d, size_type __n, _CharT __c) |
| 469 | { |
| 470 | if (__n == 1) |
| 471 | traits_type::assign(*__d, __c); |
| 472 | else |
| 473 | traits_type::assign(__d, __n, __c); |
| 474 | } |
| 475 | |
| 476 | #pragma GCC diagnostic push |
| 477 | #pragma GCC diagnostic ignored "-Wc++17-extensions" |
| 478 | |
| 479 | |
| 480 | template<class _Iterator> |
| 481 | _GLIBCXX20_CONSTEXPR |
| 482 | static void |
| 483 | _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) |
| 484 | { |
| 485 | #if __cplusplus >= 201103L |
| 486 | using _IterBase = decltype(std::__niter_base(__k1)); |
| 487 | if constexpr (__or_<is_same<_IterBase, _CharT*>, |
| 488 | is_same<_IterBase, const _CharT*>>::value) |
| 489 | _S_copy(__p, std::__niter_base(__k1), __k2 - __k1); |
| 490 | #if __cpp_lib_concepts |
| 491 | else if constexpr (requires { |
| 492 | requires contiguous_iterator<_Iterator>; |
| 493 | { std::to_address(__k1) } |
| 494 | -> convertible_to<const _CharT*>; |
| 495 | }) |
| 496 | { |
| 497 | const auto __d = __k2 - __k1; |
| 498 | (void) (__k1 + __d); |
| 499 | _S_copy(__p, std::to_address(__k1), static_cast<size_type>(__d)); |
| 500 | } |
| 501 | #endif |
| 502 | else |
| 503 | #endif |
| 504 | for (; __k1 != __k2; ++__k1, (void)++__p) |
| 505 | traits_type::assign(*__p, static_cast<_CharT>(*__k1)); |
| 506 | } |
| 507 | #pragma GCC diagnostic pop |
| 508 | |
| 509 | #if __cplusplus < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 510 | static void |
| 511 | _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) |
| 512 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
| 513 | |
| 514 | static void |
| 515 | _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) |
| 516 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
| 517 | |
| 518 | static void |
| 519 | _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) |
| 520 | { _S_copy(__p, __k1, __k2 - __k1); } |
| 521 | |
| 522 | static void |
| 523 | _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) |
| 524 | { _S_copy(__p, __k1, __k2 - __k1); } |
| 525 | #endif |
| 526 | |
| 527 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 528 | |
| 529 | template<typename _Rg> |
| 530 | static constexpr void |
| 531 | _S_copy_range(pointer __p, _Rg&& __rg, size_type __n) |
| 532 | { |
| 533 | if constexpr (requires { |
| 534 | requires ranges::contiguous_range<_Rg>; |
| 535 | { ranges::data(std::forward<_Rg>(__rg)) } |
| 536 | -> convertible_to<const _CharT*>; |
| 537 | }) |
| 538 | _S_copy(__p, ranges::data(std::forward<_Rg>(__rg)), __n); |
| 539 | else |
| 540 | { |
| 541 | auto __first = ranges::begin(__rg); |
| 542 | const auto __last = ranges::end(__rg); |
| 543 | for (; __first != __last; ++__first) |
| 544 | traits_type::assign(*__p++, static_cast<_CharT>(*__first)); |
| 545 | } |
| 546 | } |
| 547 | #endif |
| 548 | |
| 549 | _GLIBCXX20_CONSTEXPR |
| 550 | static int |
| 551 | _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT |
| 552 | { |
| 553 | const difference_type __d = difference_type(__n1 - __n2); |
| 554 | |
| 555 | if (__d > __gnu_cxx::__numeric_traits<int>::__max) |
| 556 | return __gnu_cxx::__numeric_traits<int>::__max; |
| 557 | else if (__d < __gnu_cxx::__numeric_traits<int>::__min) |
| 558 | return __gnu_cxx::__numeric_traits<int>::__min; |
| 559 | else |
| 560 | return int(__d); |
| 561 | } |
| 562 | |
| 563 | _GLIBCXX20_CONSTEXPR |
| 564 | void |
| 565 | _M_assign(const basic_string&); |
| 566 | |
| 567 | _GLIBCXX20_CONSTEXPR |
| 568 | void |
| 569 | _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, |
| 570 | size_type __len2); |
| 571 | |
| 572 | _GLIBCXX20_CONSTEXPR |
| 573 | void |
| 574 | _M_erase(size_type __pos, size_type __n); |
| 575 | |
| 576 | public: |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | _GLIBCXX20_CONSTEXPR |
| 585 | basic_string() |
| 586 | _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value) |
| 587 | #if __cpp_concepts && __glibcxx_type_trait_variable_templates |
| 588 | requires is_default_constructible_v<_Alloc> |
| 589 | #endif |
| 590 | : _M_dataplus(_M_local_data()) |
| 591 | { |
| 592 | _M_init_local_buf(); |
| 593 | _M_set_length(0); |
| 594 | } |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | _GLIBCXX20_CONSTEXPR |
| 600 | explicit |
| 601 | basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT |
| 602 | : _M_dataplus(_M_local_data(), __a) |
| 603 | { |
| 604 | _M_init_local_buf(); |
| 605 | _M_set_length(0); |
| 606 | } |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | _GLIBCXX20_CONSTEXPR |
| 613 | basic_string(const basic_string& __str) |
| 614 | : _M_dataplus(_M_local_data(), |
| 615 | _Alloc_traits::_S_select_on_copy(__str._M_get_allocator())) |
| 616 | { |
| 617 | _M_construct<true>(__str._M_data(), __str.length()); |
| 618 | } |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | _GLIBCXX20_CONSTEXPR |
| 629 | basic_string(const basic_string& __str, size_type __pos, |
| 630 | const _Alloc& __a = _Alloc()) |
| 631 | : _M_dataplus(_M_local_data(), __a) |
| 632 | { |
| 633 | const _CharT* __start = __str._M_data() |
| 634 | + __str._M_check(__pos, "basic_string::basic_string"); |
| 635 | _M_construct(__start, __start + __str._M_limit(__pos, npos), |
| 636 | std::forward_iterator_tag()); |
| 637 | } |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | _GLIBCXX20_CONSTEXPR |
| 646 | basic_string(const basic_string& __str, size_type __pos, |
| 647 | size_type __n) |
| 648 | : _M_dataplus(_M_local_data()) |
| 649 | { |
| 650 | const _CharT* __start = __str._M_data() |
| 651 | + __str._M_check(__pos, "basic_string::basic_string"); |
| 652 | _M_construct(__start, __start + __str._M_limit(__pos, __n), |
| 653 | std::forward_iterator_tag()); |
| 654 | } |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | _GLIBCXX20_CONSTEXPR |
| 664 | basic_string(const basic_string& __str, size_type __pos, |
| 665 | size_type __n, const _Alloc& __a) |
| 666 | : _M_dataplus(_M_local_data(), __a) |
| 667 | { |
| 668 | const _CharT* __start |
| 669 | = __str._M_data() + __str._M_check(__pos, "string::string"); |
| 670 | _M_construct(__start, __start + __str._M_limit(__pos, __n), |
| 671 | std::forward_iterator_tag()); |
| 672 | } |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | _GLIBCXX20_CONSTEXPR |
| 684 | basic_string(const _CharT* __s, size_type __n, |
| 685 | const _Alloc& __a = _Alloc()) |
| 686 | : _M_dataplus(_M_local_data(), __a) |
| 687 | { |
| 688 | |
| 689 | if (__s == 0 && __n > 0) |
| 690 | std::__throw_logic_error(__N("basic_string: " |
| 691 | "construction from null is not valid")); |
| 692 | _M_construct(__s, __s + __n, std::forward_iterator_tag()); |
| 693 | } |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | #if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 701 | |
| 702 | |
| 703 | template<typename = _RequireAllocator<_Alloc>> |
| 704 | #endif |
| 705 | _GLIBCXX20_CONSTEXPR |
| 706 | basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) |
| 707 | : _M_dataplus(_M_local_data(), __a) |
| 708 | { |
| 709 | |
| 710 | if (__s == 0) |
| 711 | std::__throw_logic_error(__N("basic_string: " |
| 712 | "construction from null is not valid")); |
| 713 | const _CharT* __end = __s + traits_type::length(__s); |
| 714 | _M_construct(__s, __end, forward_iterator_tag()); |
| 715 | } |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | #if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 724 | |
| 725 | |
| 726 | template<typename = _RequireAllocator<_Alloc>> |
| 727 | #endif |
| 728 | _GLIBCXX20_CONSTEXPR |
| 729 | basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) |
| 730 | : _M_dataplus(_M_local_data(), __a) |
| 731 | { _M_construct(__n, __c); } |
| 732 | |
| 733 | #if __cplusplus >= 201103L |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | _GLIBCXX20_CONSTEXPR |
| 742 | basic_string(basic_string&& __str) noexcept |
| 743 | : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator())) |
| 744 | { |
| 745 | if (__str._M_is_local()) |
| 746 | { |
| 747 | _M_init_local_buf(); |
| 748 | traits_type::copy(_M_local_buf, __str._M_local_buf, |
| 749 | __str.length() + 1); |
| 750 | } |
| 751 | else |
| 752 | { |
| 753 | _M_data(__str._M_data()); |
| 754 | _M_capacity(__str._M_allocated_capacity); |
| 755 | } |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | _M_length(__str.length()); |
| 761 | __str._M_data(__str._M_use_local_data()); |
| 762 | __str._M_set_length(0); |
| 763 | } |
| 764 | |
| 765 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | template<__detail::__container_compatible_range<_CharT> _Rg> |
| 771 | constexpr |
| 772 | basic_string(from_range_t, _Rg&& __rg, const _Alloc& __a = _Alloc()) |
| 773 | : basic_string(__a) |
| 774 | { |
| 775 | if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>) |
| 776 | { |
| 777 | const auto __n = static_cast<size_type>(ranges::distance(__rg)); |
| 778 | reserve(__n); |
| 779 | _S_copy_range(_M_data(), std::forward<_Rg>(__rg), __n); |
| 780 | _M_set_length(__n); |
| 781 | } |
| 782 | else |
| 783 | { |
| 784 | auto __first = ranges::begin(__rg); |
| 785 | const auto __last = ranges::end(__rg); |
| 786 | for (; __first != __last; ++__first) |
| 787 | push_back(*__first); |
| 788 | } |
| 789 | } |
| 790 | #endif |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | _GLIBCXX20_CONSTEXPR |
| 798 | basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()) |
| 799 | : _M_dataplus(_M_local_data(), __a) |
| 800 | { _M_construct(__l.begin(), __l.end(), std::forward_iterator_tag()); } |
| 801 | |
| 802 | _GLIBCXX20_CONSTEXPR |
| 803 | basic_string(const basic_string& __str, const _Alloc& __a) |
| 804 | : _M_dataplus(_M_local_data(), __a) |
| 805 | { _M_construct(__str.begin(), __str.end(), std::forward_iterator_tag()); } |
| 806 | |
| 807 | _GLIBCXX20_CONSTEXPR |
| 808 | basic_string(basic_string&& __str, const _Alloc& __a) |
| 809 | noexcept(_Alloc_traits::_S_always_equal()) |
| 810 | : _M_dataplus(_M_local_data(), __a) |
| 811 | { |
| 812 | if (__str._M_is_local()) |
| 813 | { |
| 814 | _M_init_local_buf(); |
| 815 | traits_type::copy(_M_local_buf, __str._M_local_buf, |
| 816 | __str.length() + 1); |
| 817 | _M_length(__str.length()); |
| 818 | __str._M_set_length(0); |
| 819 | } |
| 820 | else if (_Alloc_traits::_S_always_equal() |
| 821 | || __str.get_allocator() == __a) |
| 822 | { |
| 823 | _M_data(__str._M_data()); |
| 824 | _M_length(__str.length()); |
| 825 | _M_capacity(__str._M_allocated_capacity); |
| 826 | __str._M_data(__str._M_use_local_data()); |
| 827 | __str._M_set_length(0); |
| 828 | } |
| 829 | else |
| 830 | _M_construct(__str.begin(), __str.end(), std::forward_iterator_tag()); |
| 831 | } |
| 832 | #endif // C++11 |
| 833 | |
| 834 | #if __cplusplus >= 202100L |
| 835 | basic_string(nullptr_t) = delete; |
| 836 | basic_string& operator=(nullptr_t) = delete; |
| 837 | #endif // C++23 |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | #if __cplusplus >= 201103L |
| 846 | template<typename _InputIterator, |
| 847 | typename = std::_RequireInputIter<_InputIterator>> |
| 848 | #else |
| 849 | template<typename _InputIterator> |
| 850 | #endif |
| 851 | _GLIBCXX20_CONSTEXPR |
| 852 | basic_string(_InputIterator __beg, _InputIterator __end, |
| 853 | const _Alloc& __a = _Alloc()) |
| 854 | : _M_dataplus(_M_local_data(), __a), _M_string_length(0) |
| 855 | { |
| 856 | #if __cplusplus >= 201103L |
| 857 | _M_construct(__beg, __end, std::__iterator_category(__beg)); |
| 858 | #else |
| 859 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
| 860 | _M_construct_aux(__beg, __end, _Integral()); |
| 861 | #endif |
| 862 | } |
| 863 | |
| 864 | #ifdef __glibcxx_string_view // >= C++17 |
| 865 | |
| 866 | |
| 867 | |
| 868 | |
| 869 | |
| 870 | |
| 871 | |
| 872 | template<typename _Tp, |
| 873 | typename = enable_if_t<is_convertible_v<const _Tp&, __sv_type>>> |
| 874 | _GLIBCXX20_CONSTEXPR |
| 875 | basic_string(const _Tp& __t, size_type __pos, size_type __n, |
| 876 | const _Alloc& __a = _Alloc()) |
| 877 | : basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { } |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | template<typename _Tp, typename = _If_sv<_Tp, void>> |
| 885 | _GLIBCXX20_CONSTEXPR |
| 886 | explicit |
| 887 | basic_string(const _Tp& __t, const _Alloc& __a = _Alloc()) |
| 888 | : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { } |
| 889 | #endif // C++17 |
| 890 | |
| 891 | |
| 892 | |
| 893 | |
| 894 | _GLIBCXX20_CONSTEXPR |
| 895 | ~basic_string() |
| 896 | { _M_dispose(); } |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | _GLIBCXX20_CONSTEXPR |
| 903 | basic_string& |
| 904 | operator=(const basic_string& __str) |
| 905 | { |
| 906 | return this->assign(__str); |
| 907 | } |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | _GLIBCXX20_CONSTEXPR |
| 914 | basic_string& |
| 915 | operator=(const _CharT* __s) |
| 916 | { return this->assign(__s); } |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | _GLIBCXX20_CONSTEXPR |
| 926 | basic_string& |
| 927 | operator=(_CharT __c) |
| 928 | { |
| 929 | this->assign(1, __c); |
| 930 | return *this; |
| 931 | } |
| 932 | |
| 933 | #if __cplusplus >= 201103L |
| 934 | |
| 935 | |
| 936 | |
| 937 | |
| 938 | |
| 939 | |
| 940 | |
| 941 | |
| 942 | |
| 943 | _GLIBCXX20_CONSTEXPR |
| 944 | basic_string& |
| 945 | operator=(basic_string&& __str) |
| 946 | noexcept(_Alloc_traits::_S_nothrow_move()) |
| 947 | { |
| 948 | const bool __equal_allocs = _Alloc_traits::_S_always_equal() |
| 949 | || _M_get_allocator() == __str._M_get_allocator(); |
| 950 | if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign() |
| 951 | && !__equal_allocs) |
| 952 | { |
| 953 | |
| 954 | _M_destroy(_M_allocated_capacity); |
| 955 | _M_data(_M_local_data()); |
| 956 | _M_set_length(0); |
| 957 | } |
| 958 | |
| 959 | std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator()); |
| 960 | |
| 961 | if (__str._M_is_local()) |
| 962 | { |
| 963 | |
| 964 | |
| 965 | |
| 966 | if (__builtin_expect(std::__addressof(__str) != this, true)) |
| 967 | { |
| 968 | if (__str.size()) |
| 969 | this->_S_copy(_M_data(), __str._M_data(), __str.size()); |
| 970 | _M_set_length(__str.size()); |
| 971 | } |
| 972 | } |
| 973 | else if (_Alloc_traits::_S_propagate_on_move_assign() || __equal_allocs) |
| 974 | { |
| 975 | |
| 976 | pointer __data = nullptr; |
| 977 | size_type __capacity; |
| 978 | if (!_M_is_local()) |
| 979 | { |
| 980 | if (__equal_allocs) |
| 981 | { |
| 982 | |
| 983 | __data = _M_data(); |
| 984 | __capacity = _M_allocated_capacity; |
| 985 | } |
| 986 | else |
| 987 | _M_destroy(_M_allocated_capacity); |
| 988 | } |
| 989 | |
| 990 | _M_data(__str._M_data()); |
| 991 | _M_length(__str.length()); |
| 992 | _M_capacity(__str._M_allocated_capacity); |
| 993 | if (__data) |
| 994 | { |
| 995 | __str._M_data(__data); |
| 996 | __str._M_capacity(__capacity); |
| 997 | } |
| 998 | else |
| 999 | __str._M_data(__str._M_use_local_data()); |
| 1000 | } |
| 1001 | else |
| 1002 | _M_assign(__str); |
| 1003 | __str.clear(); |
| 1004 | return *this; |
| 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | |
| 1009 | |
| 1010 | |
| 1011 | _GLIBCXX20_CONSTEXPR |
| 1012 | basic_string& |
| 1013 | operator=(initializer_list<_CharT> __l) |
| 1014 | { |
| 1015 | this->assign(__l.begin(), __l.size()); |
| 1016 | return *this; |
| 1017 | } |
| 1018 | #endif // C++11 |
| 1019 | |
| 1020 | #ifdef __glibcxx_string_view // >= C++17 |
| 1021 | |
| 1022 | |
| 1023 | |
| 1024 | |
| 1025 | template<typename _Tp> |
| 1026 | _GLIBCXX20_CONSTEXPR |
| 1027 | _If_sv<_Tp, basic_string&> |
| 1028 | operator=(const _Tp& __svt) |
| 1029 | { return this->assign(__svt); } |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | _GLIBCXX20_CONSTEXPR |
| 1036 | operator __sv_type() const noexcept |
| 1037 | { return __sv_type(data(), size()); } |
| 1038 | #endif // C++17 |
| 1039 | |
| 1040 | |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | |
| 1045 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1046 | iterator |
| 1047 | begin() _GLIBCXX_NOEXCEPT |
| 1048 | { return iterator(_M_data()); } |
| 1049 | |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1055 | const_iterator |
| 1056 | begin() const _GLIBCXX_NOEXCEPT |
| 1057 | { return const_iterator(_M_data()); } |
| 1058 | |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | |
| 1063 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1064 | iterator |
| 1065 | end() _GLIBCXX_NOEXCEPT |
| 1066 | { return iterator(_M_data() + this->size()); } |
| 1067 | |
| 1068 | |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1073 | const_iterator |
| 1074 | end() const _GLIBCXX_NOEXCEPT |
| 1075 | { return const_iterator(_M_data() + this->size()); } |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | |
| 1082 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1083 | reverse_iterator |
| 1084 | rbegin() _GLIBCXX_NOEXCEPT |
| 1085 | { return reverse_iterator(this->end()); } |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1093 | const_reverse_iterator |
| 1094 | rbegin() const _GLIBCXX_NOEXCEPT |
| 1095 | { return const_reverse_iterator(this->end()); } |
| 1096 | |
| 1097 | |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | |
| 1102 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1103 | reverse_iterator |
| 1104 | rend() _GLIBCXX_NOEXCEPT |
| 1105 | { return reverse_iterator(this->begin()); } |
| 1106 | |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1113 | const_reverse_iterator |
| 1114 | rend() const _GLIBCXX_NOEXCEPT |
| 1115 | { return const_reverse_iterator(this->begin()); } |
| 1116 | |
| 1117 | #if __cplusplus >= 201103L |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1123 | const_iterator |
| 1124 | cbegin() const noexcept |
| 1125 | { return const_iterator(this->_M_data()); } |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | |
| 1131 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1132 | const_iterator |
| 1133 | cend() const noexcept |
| 1134 | { return const_iterator(this->_M_data() + this->size()); } |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1142 | const_reverse_iterator |
| 1143 | crbegin() const noexcept |
| 1144 | { return const_reverse_iterator(this->end()); } |
| 1145 | |
| 1146 | |
| 1147 | |
| 1148 | |
| 1149 | |
| 1150 | |
| 1151 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1152 | const_reverse_iterator |
| 1153 | crend() const noexcept |
| 1154 | { return const_reverse_iterator(this->begin()); } |
| 1155 | #endif |
| 1156 | |
| 1157 | public: |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1162 | size_type |
| 1163 | size() const _GLIBCXX_NOEXCEPT |
| 1164 | { |
| 1165 | size_type __sz = _M_string_length; |
| 1166 | if (__sz > max_size ()) |
| 1167 | __builtin_unreachable (); |
| 1168 | return __sz; |
| 1169 | } |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1174 | size_type |
| 1175 | length() const _GLIBCXX_NOEXCEPT |
| 1176 | { return size(); } |
| 1177 | |
| 1178 | |
| 1179 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1180 | size_type |
| 1181 | max_size() const _GLIBCXX_NOEXCEPT |
| 1182 | { |
| 1183 | const size_t __diffmax |
| 1184 | = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max / sizeof(_CharT); |
| 1185 | const size_t __allocmax = _Alloc_traits::max_size(_M_get_allocator()); |
| 1186 | return (std::min)(__diffmax, __allocmax) - 1; |
| 1187 | } |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | _GLIBCXX20_CONSTEXPR |
| 1200 | void |
| 1201 | resize(size_type __n, _CharT __c); |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | |
| 1212 | |
| 1213 | _GLIBCXX20_CONSTEXPR |
| 1214 | void |
| 1215 | resize(size_type __n) |
| 1216 | { this->resize(__n, _CharT()); } |
| 1217 | |
| 1218 | #if __cplusplus >= 201103L |
| 1219 | #pragma GCC diagnostic push |
| 1220 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 1221 | |
| 1222 | _GLIBCXX20_CONSTEXPR |
| 1223 | void |
| 1224 | shrink_to_fit() noexcept |
| 1225 | { reserve(); } |
| 1226 | #pragma GCC diagnostic pop |
| 1227 | #endif |
| 1228 | |
| 1229 | #ifdef __glibcxx_string_resize_and_overwrite // C++ >= 23 |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | template<typename _Operation> |
| 1260 | constexpr void |
| 1261 | resize_and_overwrite(size_type __n, _Operation __op); |
| 1262 | #endif |
| 1263 | |
| 1264 | #if __cplusplus >= 201103L |
| 1265 | |
| 1266 | template<typename _Operation> |
| 1267 | _GLIBCXX20_CONSTEXPR void |
| 1268 | __resize_and_overwrite(size_type __n, _Operation __op); |
| 1269 | #endif |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1276 | size_type |
| 1277 | capacity() const _GLIBCXX_NOEXCEPT |
| 1278 | { |
| 1279 | size_t __sz = _M_is_local() ? size_type(_S_local_capacity) |
| 1280 | : _M_allocated_capacity; |
| 1281 | if (__sz < _S_local_capacity || __sz > max_size ()) |
| 1282 | __builtin_unreachable (); |
| 1283 | return __sz; |
| 1284 | } |
| 1285 | |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | |
| 1295 | |
| 1296 | |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | |
| 1302 | |
| 1303 | _GLIBCXX20_CONSTEXPR |
| 1304 | void |
| 1305 | reserve(size_type __res_arg); |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | #if __cplusplus > 201703L |
| 1311 | [[deprecated("use shrink_to_fit() instead")]] |
| 1312 | #endif |
| 1313 | _GLIBCXX20_CONSTEXPR |
| 1314 | void |
| 1315 | reserve(); |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | _GLIBCXX20_CONSTEXPR |
| 1321 | void |
| 1322 | clear() _GLIBCXX_NOEXCEPT |
| 1323 | { _M_set_length(0); } |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | |
| 1328 | |
| 1329 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1330 | bool |
| 1331 | empty() const _GLIBCXX_NOEXCEPT |
| 1332 | { return _M_string_length == 0; } |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1346 | const_reference |
| 1347 | operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT |
| 1348 | { |
| 1349 | __glibcxx_assert(__pos <= size()); |
| 1350 | return _M_data()[__pos]; |
| 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | |
| 1358 | |
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | |
| 1363 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1364 | reference |
| 1365 | operator[](size_type __pos) |
| 1366 | { |
| 1367 | |
| 1368 | |
| 1369 | __glibcxx_assert(__pos <= size()); |
| 1370 | |
| 1371 | _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size()); |
| 1372 | return _M_data()[__pos]; |
| 1373 | } |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1386 | const_reference |
| 1387 | at(size_type __n) const |
| 1388 | { |
| 1389 | if (__n >= this->size()) |
| 1390 | __throw_out_of_range_fmt(__N("basic_string::at: __n " |
| 1391 | "(which is %zu) >= this->size() " |
| 1392 | "(which is %zu)"), |
| 1393 | __n, this->size()); |
| 1394 | return _M_data()[__n]; |
| 1395 | } |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1408 | reference |
| 1409 | at(size_type __n) |
| 1410 | { |
| 1411 | if (__n >= size()) |
| 1412 | __throw_out_of_range_fmt(__N("basic_string::at: __n " |
| 1413 | "(which is %zu) >= this->size() " |
| 1414 | "(which is %zu)"), |
| 1415 | __n, this->size()); |
| 1416 | return _M_data()[__n]; |
| 1417 | } |
| 1418 | |
| 1419 | #if __cplusplus >= 201103L |
| 1420 | |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1425 | reference |
| 1426 | front() noexcept |
| 1427 | { |
| 1428 | __glibcxx_assert(!empty()); |
| 1429 | return operator[](0); |
| 1430 | } |
| 1431 | |
| 1432 | |
| 1433 | |
| 1434 | |
| 1435 | |
| 1436 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1437 | const_reference |
| 1438 | front() const noexcept |
| 1439 | { |
| 1440 | __glibcxx_assert(!empty()); |
| 1441 | return operator[](0); |
| 1442 | } |
| 1443 | |
| 1444 | |
| 1445 | |
| 1446 | |
| 1447 | |
| 1448 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1449 | reference |
| 1450 | back() noexcept |
| 1451 | { |
| 1452 | __glibcxx_assert(!empty()); |
| 1453 | return operator[](this->size() - 1); |
| 1454 | } |
| 1455 | |
| 1456 | |
| 1457 | |
| 1458 | |
| 1459 | |
| 1460 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 1461 | const_reference |
| 1462 | back() const noexcept |
| 1463 | { |
| 1464 | __glibcxx_assert(!empty()); |
| 1465 | return operator[](this->size() - 1); |
| 1466 | } |
| 1467 | #endif |
| 1468 | |
| 1469 | |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | |
| 1474 | |
| 1475 | _GLIBCXX20_CONSTEXPR |
| 1476 | basic_string& |
| 1477 | operator+=(const basic_string& __str) |
| 1478 | { return this->append(__str); } |
| 1479 | |
| 1480 | |
| 1481 | |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | _GLIBCXX20_CONSTEXPR |
| 1486 | basic_string& |
| 1487 | operator+=(const _CharT* __s) |
| 1488 | { return this->append(__s); } |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | _GLIBCXX20_CONSTEXPR |
| 1496 | basic_string& |
| 1497 | operator+=(_CharT __c) |
| 1498 | { |
| 1499 | this->push_back(__c); |
| 1500 | return *this; |
| 1501 | } |
| 1502 | |
| 1503 | #if __cplusplus >= 201103L |
| 1504 | |
| 1505 | |
| 1506 | |
| 1507 | |
| 1508 | |
| 1509 | _GLIBCXX20_CONSTEXPR |
| 1510 | basic_string& |
| 1511 | operator+=(initializer_list<_CharT> __l) |
| 1512 | { return this->append(__l.begin(), __l.size()); } |
| 1513 | #endif // C++11 |
| 1514 | |
| 1515 | #ifdef __glibcxx_string_view // >= C++17 |
| 1516 | |
| 1517 | |
| 1518 | |
| 1519 | |
| 1520 | |
| 1521 | template<typename _Tp> |
| 1522 | _GLIBCXX20_CONSTEXPR |
| 1523 | _If_sv<_Tp, basic_string&> |
| 1524 | operator+=(const _Tp& __svt) |
| 1525 | { return this->append(__svt); } |
| 1526 | #endif // C++17 |
| 1527 | |
| 1528 | |
| 1529 | |
| 1530 | |
| 1531 | |
| 1532 | |
| 1533 | _GLIBCXX20_CONSTEXPR |
| 1534 | basic_string& |
| 1535 | append(const basic_string& __str) |
| 1536 | { return this->append(__str._M_data(), __str.size()); } |
| 1537 | |
| 1538 | |
| 1539 | |
| 1540 | |
| 1541 | |
| 1542 | |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | |
| 1547 | |
| 1548 | |
| 1549 | |
| 1550 | |
| 1551 | _GLIBCXX20_CONSTEXPR |
| 1552 | basic_string& |
| 1553 | append(const basic_string& __str, size_type __pos, size_type __n = npos) |
| 1554 | { return this->append(__str._M_data() |
| 1555 | + __str._M_check(__pos, "basic_string::append"), |
| 1556 | __str._M_limit(__pos, __n)); } |
| 1557 | |
| 1558 | |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | |
| 1563 | |
| 1564 | _GLIBCXX20_CONSTEXPR |
| 1565 | basic_string& |
| 1566 | append(const _CharT* __s, size_type __n) |
| 1567 | { |
| 1568 | __glibcxx_requires_string_len(__s, __n); |
| 1569 | _M_check_length(size_type(0), __n, "basic_string::append"); |
| 1570 | return _M_append(__s, __n); |
| 1571 | } |
| 1572 | |
| 1573 | |
| 1574 | |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | _GLIBCXX20_CONSTEXPR |
| 1579 | basic_string& |
| 1580 | append(const _CharT* __s) |
| 1581 | { |
| 1582 | __glibcxx_requires_string(__s); |
| 1583 | const size_type __n = traits_type::length(__s); |
| 1584 | _M_check_length(size_type(0), __n, "basic_string::append"); |
| 1585 | return _M_append(__s, __n); |
| 1586 | } |
| 1587 | |
| 1588 | |
| 1589 | |
| 1590 | |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | _GLIBCXX20_CONSTEXPR |
| 1597 | basic_string& |
| 1598 | append(size_type __n, _CharT __c) |
| 1599 | { return _M_replace_aux(this->size(), size_type(0), __n, __c); } |
| 1600 | |
| 1601 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 1602 | |
| 1603 | |
| 1604 | |
| 1605 | |
| 1606 | |
| 1607 | |
| 1608 | |
| 1609 | template<__detail::__container_compatible_range<_CharT> _Rg> |
| 1610 | constexpr basic_string& |
| 1611 | append_range(_Rg&& __rg) |
| 1612 | { |
| 1613 | |
| 1614 | |
| 1615 | |
| 1616 | if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>) |
| 1617 | { |
| 1618 | const auto __len = size_type(ranges::distance(__rg)); |
| 1619 | |
| 1620 | |
| 1621 | const size_type __newlen = size() + __len; |
| 1622 | |
| 1623 | if ((capacity() - size()) >= __len) |
| 1624 | _S_copy_range(_M_data() + size(), std::forward<_Rg>(__rg), |
| 1625 | __len); |
| 1626 | else |
| 1627 | { |
| 1628 | _M_check_length(0, __len, "basic_string::append_range"); |
| 1629 | basic_string __s(_M_get_allocator()); |
| 1630 | __s.reserve(__newlen); |
| 1631 | _S_copy_range(__s._M_data() + size(), std::forward<_Rg>(__rg), |
| 1632 | __len); |
| 1633 | _S_copy(__s._M_data(), _M_data(), size()); |
| 1634 | if (!_M_is_local()) |
| 1635 | _M_destroy(_M_allocated_capacity); |
| 1636 | _M_data(__s._M_data()); |
| 1637 | _M_capacity(__s._M_allocated_capacity); |
| 1638 | __s._M_data(__s._M_local_data()); |
| 1639 | __s._M_length(0); |
| 1640 | } |
| 1641 | _M_set_length(__newlen); |
| 1642 | } |
| 1643 | else |
| 1644 | { |
| 1645 | basic_string __s(from_range, std::forward<_Rg>(__rg), |
| 1646 | _M_get_allocator()); |
| 1647 | append(__s); |
| 1648 | } |
| 1649 | return *this; |
| 1650 | } |
| 1651 | #endif |
| 1652 | |
| 1653 | #if __cplusplus >= 201103L |
| 1654 | |
| 1655 | |
| 1656 | |
| 1657 | |
| 1658 | |
| 1659 | _GLIBCXX20_CONSTEXPR |
| 1660 | basic_string& |
| 1661 | append(initializer_list<_CharT> __l) |
| 1662 | { return this->append(__l.begin(), __l.size()); } |
| 1663 | #endif // C++11 |
| 1664 | |
| 1665 | |
| 1666 | |
| 1667 | |
| 1668 | |
| 1669 | |
| 1670 | |
| 1671 | |
| 1672 | |
| 1673 | #if __cplusplus >= 201103L |
| 1674 | template<class _InputIterator, |
| 1675 | typename = std::_RequireInputIter<_InputIterator>> |
| 1676 | _GLIBCXX20_CONSTEXPR |
| 1677 | #else |
| 1678 | template<class _InputIterator> |
| 1679 | #endif |
| 1680 | basic_string& |
| 1681 | append(_InputIterator __first, _InputIterator __last) |
| 1682 | { return this->replace(end(), end(), __first, __last); } |
| 1683 | |
| 1684 | #ifdef __glibcxx_string_view |
| 1685 | |
| 1686 | |
| 1687 | |
| 1688 | |
| 1689 | |
| 1690 | template<typename _Tp> |
| 1691 | _GLIBCXX20_CONSTEXPR |
| 1692 | _If_sv<_Tp, basic_string&> |
| 1693 | append(const _Tp& __svt) |
| 1694 | { |
| 1695 | __sv_type __sv = __svt; |
| 1696 | return this->append(__sv.data(), __sv.size()); |
| 1697 | } |
| 1698 | |
| 1699 | |
| 1700 | |
| 1701 | |
| 1702 | |
| 1703 | |
| 1704 | |
| 1705 | |
| 1706 | template<typename _Tp> |
| 1707 | _GLIBCXX20_CONSTEXPR |
| 1708 | _If_sv<_Tp, basic_string&> |
| 1709 | append(const _Tp& __svt, size_type __pos, size_type __n = npos) |
| 1710 | { |
| 1711 | __sv_type __sv = __svt; |
| 1712 | return _M_append(__sv.data() |
| 1713 | + std::__sv_check(__sv.size(), __pos, "basic_string::append"), |
| 1714 | std::__sv_limit(__sv.size(), __pos, __n)); |
| 1715 | } |
| 1716 | #endif // C++17 |
| 1717 | |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | _GLIBCXX20_CONSTEXPR |
| 1723 | void |
| 1724 | push_back(_CharT __c) |
| 1725 | { |
| 1726 | const size_type __size = this->size(); |
| 1727 | if (__size + 1 > this->capacity()) |
| 1728 | this->_M_mutate(__size, size_type(0), 0, size_type(1)); |
| 1729 | traits_type::assign(this->_M_data()[__size], __c); |
| 1730 | this->_M_set_length(__size + 1); |
| 1731 | } |
| 1732 | |
| 1733 | |
| 1734 | |
| 1735 | |
| 1736 | |
| 1737 | |
| 1738 | _GLIBCXX20_CONSTEXPR |
| 1739 | basic_string& |
| 1740 | assign(const basic_string& __str) |
| 1741 | { |
| 1742 | #if __cplusplus >= 201103L |
| 1743 | if (_Alloc_traits::_S_propagate_on_copy_assign()) |
| 1744 | { |
| 1745 | if (!_Alloc_traits::_S_always_equal() && !_M_is_local() |
| 1746 | && _M_get_allocator() != __str._M_get_allocator()) |
| 1747 | { |
| 1748 | |
| 1749 | |
| 1750 | if (__str.size() <= _S_local_capacity) |
| 1751 | { |
| 1752 | _M_destroy(_M_allocated_capacity); |
| 1753 | _M_data(_M_use_local_data()); |
| 1754 | _M_set_length(0); |
| 1755 | } |
| 1756 | else |
| 1757 | { |
| 1758 | const auto __len = __str.size(); |
| 1759 | auto __alloc = __str._M_get_allocator(); |
| 1760 | |
| 1761 | auto __ptr = _S_allocate(__alloc, __len + 1); |
| 1762 | _M_destroy(_M_allocated_capacity); |
| 1763 | _M_data(__ptr); |
| 1764 | _M_capacity(__len); |
| 1765 | _M_set_length(__len); |
| 1766 | } |
| 1767 | } |
| 1768 | std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator()); |
| 1769 | } |
| 1770 | #endif |
| 1771 | this->_M_assign(__str); |
| 1772 | return *this; |
| 1773 | } |
| 1774 | |
| 1775 | #if __cplusplus >= 201103L |
| 1776 | |
| 1777 | |
| 1778 | |
| 1779 | |
| 1780 | |
| 1781 | |
| 1782 | |
| 1783 | |
| 1784 | _GLIBCXX20_CONSTEXPR |
| 1785 | basic_string& |
| 1786 | assign(basic_string&& __str) |
| 1787 | noexcept(_Alloc_traits::_S_nothrow_move()) |
| 1788 | { |
| 1789 | |
| 1790 | |
| 1791 | return *this = std::move(__str); |
| 1792 | } |
| 1793 | #endif // C++11 |
| 1794 | |
| 1795 | |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | |
| 1808 | _GLIBCXX20_CONSTEXPR |
| 1809 | basic_string& |
| 1810 | assign(const basic_string& __str, size_type __pos, size_type __n = npos) |
| 1811 | { return _M_replace(size_type(0), this->size(), __str._M_data() |
| 1812 | + __str._M_check(__pos, "basic_string::assign"), |
| 1813 | __str._M_limit(__pos, __n)); } |
| 1814 | |
| 1815 | |
| 1816 | |
| 1817 | |
| 1818 | |
| 1819 | |
| 1820 | |
| 1821 | |
| 1822 | |
| 1823 | |
| 1824 | |
| 1825 | _GLIBCXX20_CONSTEXPR |
| 1826 | basic_string& |
| 1827 | assign(const _CharT* __s, size_type __n) |
| 1828 | { |
| 1829 | __glibcxx_requires_string_len(__s, __n); |
| 1830 | return _M_replace(size_type(0), this->size(), __s, __n); |
| 1831 | } |
| 1832 | |
| 1833 | |
| 1834 | |
| 1835 | |
| 1836 | |
| 1837 | |
| 1838 | |
| 1839 | |
| 1840 | |
| 1841 | |
| 1842 | _GLIBCXX20_CONSTEXPR |
| 1843 | basic_string& |
| 1844 | assign(const _CharT* __s) |
| 1845 | { |
| 1846 | __glibcxx_requires_string(__s); |
| 1847 | return _M_replace(size_type(0), this->size(), __s, |
| 1848 | traits_type::length(__s)); |
| 1849 | } |
| 1850 | |
| 1851 | |
| 1852 | |
| 1853 | |
| 1854 | |
| 1855 | |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | _GLIBCXX20_CONSTEXPR |
| 1861 | basic_string& |
| 1862 | assign(size_type __n, _CharT __c) |
| 1863 | { return _M_replace_aux(size_type(0), this->size(), __n, __c); } |
| 1864 | |
| 1865 | |
| 1866 | |
| 1867 | |
| 1868 | |
| 1869 | |
| 1870 | |
| 1871 | |
| 1872 | |
| 1873 | #if __cplusplus >= 201103L |
| 1874 | #pragma GCC diagnostic push |
| 1875 | #pragma GCC diagnostic ignored "-Wc++17-extensions" |
| 1876 | template<class _InputIterator, |
| 1877 | typename = std::_RequireInputIter<_InputIterator>> |
| 1878 | _GLIBCXX20_CONSTEXPR |
| 1879 | basic_string& |
| 1880 | assign(_InputIterator __first, _InputIterator __last) |
| 1881 | { |
| 1882 | using _IterTraits = iterator_traits<_InputIterator>; |
| 1883 | if constexpr (is_pointer<decltype(std::__niter_base(__first))>::value |
| 1884 | && is_same<typename _IterTraits::value_type, |
| 1885 | _CharT>::value) |
| 1886 | { |
| 1887 | __glibcxx_requires_valid_range(__first, __last); |
| 1888 | return _M_replace(size_type(0), size(), |
| 1889 | std::__niter_base(__first), __last - __first); |
| 1890 | } |
| 1891 | #if __cplusplus >= 202002L |
| 1892 | else if constexpr (contiguous_iterator<_InputIterator> |
| 1893 | && is_same_v<iter_value_t<_InputIterator>, |
| 1894 | _CharT>) |
| 1895 | { |
| 1896 | __glibcxx_requires_valid_range(__first, __last); |
| 1897 | return _M_replace(size_type(0), size(), |
| 1898 | std::to_address(__first), __last - __first); |
| 1899 | } |
| 1900 | #endif |
| 1901 | else |
| 1902 | return *this = basic_string(__first, __last, get_allocator()); |
| 1903 | } |
| 1904 | #pragma GCC diagnostic pop |
| 1905 | #else |
| 1906 | template<class _InputIterator> |
| 1907 | basic_string& |
| 1908 | assign(_InputIterator __first, _InputIterator __last) |
| 1909 | { return this->replace(begin(), end(), __first, __last); } |
| 1910 | #endif |
| 1911 | |
| 1912 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | |
| 1917 | |
| 1918 | |
| 1919 | |
| 1920 | template<__detail::__container_compatible_range<_CharT> _Rg> |
| 1921 | constexpr basic_string& |
| 1922 | assign_range(_Rg&& __rg) |
| 1923 | { |
| 1924 | basic_string __s(from_range, std::forward<_Rg>(__rg), |
| 1925 | _M_get_allocator()); |
| 1926 | assign(std::move(__s)); |
| 1927 | return *this; |
| 1928 | } |
| 1929 | #endif |
| 1930 | |
| 1931 | #if __cplusplus >= 201103L |
| 1932 | |
| 1933 | |
| 1934 | |
| 1935 | |
| 1936 | |
| 1937 | _GLIBCXX20_CONSTEXPR |
| 1938 | basic_string& |
| 1939 | assign(initializer_list<_CharT> __l) |
| 1940 | { |
| 1941 | |
| 1942 | |
| 1943 | const size_type __n = __l.size(); |
| 1944 | if (__n > capacity()) |
| 1945 | *this = basic_string(__l.begin(), __l.end(), get_allocator()); |
| 1946 | else |
| 1947 | { |
| 1948 | if (__n) |
| 1949 | _S_copy(_M_data(), __l.begin(), __n); |
| 1950 | _M_set_length(__n); |
| 1951 | } |
| 1952 | return *this; |
| 1953 | } |
| 1954 | #endif // C++11 |
| 1955 | |
| 1956 | #ifdef __glibcxx_string_view // >= C++17 |
| 1957 | |
| 1958 | |
| 1959 | |
| 1960 | |
| 1961 | |
| 1962 | template<typename _Tp> |
| 1963 | _GLIBCXX20_CONSTEXPR |
| 1964 | _If_sv<_Tp, basic_string&> |
| 1965 | assign(const _Tp& __svt) |
| 1966 | { |
| 1967 | __sv_type __sv = __svt; |
| 1968 | return this->assign(__sv.data(), __sv.size()); |
| 1969 | } |
| 1970 | |
| 1971 | |
| 1972 | |
| 1973 | |
| 1974 | |
| 1975 | |
| 1976 | |
| 1977 | |
| 1978 | template<typename _Tp> |
| 1979 | _GLIBCXX20_CONSTEXPR |
| 1980 | _If_sv<_Tp, basic_string&> |
| 1981 | assign(const _Tp& __svt, size_type __pos, size_type __n = npos) |
| 1982 | { |
| 1983 | __sv_type __sv = __svt; |
| 1984 | return _M_replace(size_type(0), this->size(), |
| 1985 | __sv.data() |
| 1986 | + std::__sv_check(__sv.size(), __pos, "basic_string::assign"), |
| 1987 | std::__sv_limit(__sv.size(), __pos, __n)); |
| 1988 | } |
| 1989 | #endif // C++17 |
| 1990 | |
| 1991 | #if __cplusplus >= 201103L |
| 1992 | |
| 1993 | |
| 1994 | |
| 1995 | |
| 1996 | |
| 1997 | |
| 1998 | |
| 1999 | |
| 2000 | |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | |
| 2005 | |
| 2006 | |
| 2007 | _GLIBCXX20_CONSTEXPR |
| 2008 | iterator |
| 2009 | insert(const_iterator __p, size_type __n, _CharT __c) |
| 2010 | { |
| 2011 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
| 2012 | const size_type __pos = __p - begin(); |
| 2013 | this->replace(__p, __p, __n, __c); |
| 2014 | return iterator(this->_M_data() + __pos); |
| 2015 | } |
| 2016 | #else |
| 2017 | |
| 2018 | |
| 2019 | |
| 2020 | |
| 2021 | |
| 2022 | |
| 2023 | |
| 2024 | |
| 2025 | |
| 2026 | |
| 2027 | |
| 2028 | |
| 2029 | |
| 2030 | void |
| 2031 | insert(iterator __p, size_type __n, _CharT __c) |
| 2032 | { this->replace(__p, __p, __n, __c); } |
| 2033 | #endif |
| 2034 | |
| 2035 | #if __cplusplus >= 201103L |
| 2036 | |
| 2037 | |
| 2038 | |
| 2039 | |
| 2040 | |
| 2041 | |
| 2042 | |
| 2043 | |
| 2044 | |
| 2045 | |
| 2046 | |
| 2047 | |
| 2048 | |
| 2049 | |
| 2050 | template<class _InputIterator, |
| 2051 | typename = std::_RequireInputIter<_InputIterator>> |
| 2052 | _GLIBCXX20_CONSTEXPR |
| 2053 | iterator |
| 2054 | insert(const_iterator __p, _InputIterator __beg, _InputIterator __end) |
| 2055 | { |
| 2056 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
| 2057 | const size_type __pos = __p - begin(); |
| 2058 | this->replace(__p, __p, __beg, __end); |
| 2059 | return iterator(this->_M_data() + __pos); |
| 2060 | } |
| 2061 | #else |
| 2062 | |
| 2063 | |
| 2064 | |
| 2065 | |
| 2066 | |
| 2067 | |
| 2068 | |
| 2069 | |
| 2070 | |
| 2071 | |
| 2072 | |
| 2073 | |
| 2074 | template<class _InputIterator> |
| 2075 | void |
| 2076 | insert(iterator __p, _InputIterator __beg, _InputIterator __end) |
| 2077 | { this->replace(__p, __p, __beg, __end); } |
| 2078 | #endif |
| 2079 | |
| 2080 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 2081 | |
| 2082 | |
| 2083 | |
| 2084 | |
| 2085 | |
| 2086 | |
| 2087 | |
| 2088 | template<__detail::__container_compatible_range<_CharT> _Rg> |
| 2089 | constexpr iterator |
| 2090 | insert_range(const_iterator __p, _Rg&& __rg) |
| 2091 | { |
| 2092 | auto __pos = __p - cbegin(); |
| 2093 | |
| 2094 | if constexpr (ranges::forward_range<_Rg>) |
| 2095 | if (ranges::empty(__rg)) |
| 2096 | return begin() + __pos; |
| 2097 | |
| 2098 | |
| 2099 | if (__p == cend()) |
| 2100 | append_range(std::forward<_Rg>(__rg)); |
| 2101 | else |
| 2102 | { |
| 2103 | basic_string __s(from_range, std::forward<_Rg>(__rg), |
| 2104 | _M_get_allocator()); |
| 2105 | insert(__pos, __s); |
| 2106 | } |
| 2107 | return begin() + __pos; |
| 2108 | } |
| 2109 | #endif |
| 2110 | |
| 2111 | #if __cplusplus >= 201103L |
| 2112 | |
| 2113 | |
| 2114 | |
| 2115 | |
| 2116 | |
| 2117 | |
| 2118 | _GLIBCXX20_CONSTEXPR |
| 2119 | iterator |
| 2120 | insert(const_iterator __p, initializer_list<_CharT> __l) |
| 2121 | { return this->insert(__p, __l.begin(), __l.end()); } |
| 2122 | |
| 2123 | #ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 2124 | |
| 2125 | void |
| 2126 | insert(iterator __p, initializer_list<_CharT> __l) |
| 2127 | { |
| 2128 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
| 2129 | this->insert(__p - begin(), __l.begin(), __l.size()); |
| 2130 | } |
| 2131 | #endif |
| 2132 | #endif // C++11 |
| 2133 | |
| 2134 | |
| 2135 | |
| 2136 | |
| 2137 | |
| 2138 | |
| 2139 | |
| 2140 | |
| 2141 | |
| 2142 | |
| 2143 | |
| 2144 | |
| 2145 | |
| 2146 | _GLIBCXX20_CONSTEXPR |
| 2147 | basic_string& |
| 2148 | insert(size_type __pos1, const basic_string& __str) |
| 2149 | { return this->replace(__pos1, size_type(0), |
| 2150 | __str._M_data(), __str.size()); } |
| 2151 | |
| 2152 | |
| 2153 | |
| 2154 | |
| 2155 | |
| 2156 | |
| 2157 | |
| 2158 | |
| 2159 | |
| 2160 | |
| 2161 | |
| 2162 | |
| 2163 | |
| 2164 | |
| 2165 | |
| 2166 | |
| 2167 | |
| 2168 | |
| 2169 | |
| 2170 | _GLIBCXX20_CONSTEXPR |
| 2171 | basic_string& |
| 2172 | insert(size_type __pos1, const basic_string& __str, |
| 2173 | size_type __pos2, size_type __n = npos) |
| 2174 | { return this->replace(__pos1, size_type(0), __str._M_data() |
| 2175 | + __str._M_check(__pos2, "basic_string::insert"), |
| 2176 | __str._M_limit(__pos2, __n)); } |
| 2177 | |
| 2178 | |
| 2179 | |
| 2180 | |
| 2181 | |
| 2182 | |
| 2183 | |
| 2184 | |
| 2185 | |
| 2186 | |
| 2187 | |
| 2188 | |
| 2189 | |
| 2190 | |
| 2191 | |
| 2192 | |
| 2193 | |
| 2194 | _GLIBCXX20_CONSTEXPR |
| 2195 | basic_string& |
| 2196 | insert(size_type __pos, const _CharT* __s, size_type __n) |
| 2197 | { return this->replace(__pos, size_type(0), __s, __n); } |
| 2198 | |
| 2199 | |
| 2200 | |
| 2201 | |
| 2202 | |
| 2203 | |
| 2204 | |
| 2205 | |
| 2206 | |
| 2207 | |
| 2208 | |
| 2209 | |
| 2210 | |
| 2211 | |
| 2212 | |
| 2213 | |
| 2214 | _GLIBCXX20_CONSTEXPR |
| 2215 | basic_string& |
| 2216 | insert(size_type __pos, const _CharT* __s) |
| 2217 | { |
| 2218 | __glibcxx_requires_string(__s); |
| 2219 | return this->replace(__pos, size_type(0), __s, |
| 2220 | traits_type::length(__s)); |
| 2221 | } |
| 2222 | |
| 2223 | |
| 2224 | |
| 2225 | |
| 2226 | |
| 2227 | |
| 2228 | |
| 2229 | |
| 2230 | |
| 2231 | |
| 2232 | |
| 2233 | |
| 2234 | |
| 2235 | |
| 2236 | |
| 2237 | |
| 2238 | |
| 2239 | _GLIBCXX20_CONSTEXPR |
| 2240 | basic_string& |
| 2241 | insert(size_type __pos, size_type __n, _CharT __c) |
| 2242 | { return _M_replace_aux(_M_check(__pos, "basic_string::insert"), |
| 2243 | size_type(0), __n, __c); } |
| 2244 | |
| 2245 | |
| 2246 | |
| 2247 | |
| 2248 | |
| 2249 | |
| 2250 | |
| 2251 | |
| 2252 | |
| 2253 | |
| 2254 | |
| 2255 | |
| 2256 | |
| 2257 | |
| 2258 | _GLIBCXX20_CONSTEXPR |
| 2259 | iterator |
| 2260 | insert(__const_iterator __p, _CharT __c) |
| 2261 | { |
| 2262 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
| 2263 | const size_type __pos = __p - begin(); |
| 2264 | _M_replace_aux(__pos, size_type(0), size_type(1), __c); |
| 2265 | return iterator(_M_data() + __pos); |
| 2266 | } |
| 2267 | |
| 2268 | #ifdef __glibcxx_string_view // >= C++17 |
| 2269 | |
| 2270 | |
| 2271 | |
| 2272 | |
| 2273 | |
| 2274 | |
| 2275 | template<typename _Tp> |
| 2276 | _GLIBCXX20_CONSTEXPR |
| 2277 | _If_sv<_Tp, basic_string&> |
| 2278 | insert(size_type __pos, const _Tp& __svt) |
| 2279 | { |
| 2280 | __sv_type __sv = __svt; |
| 2281 | return this->insert(__pos, __sv.data(), __sv.size()); |
| 2282 | } |
| 2283 | |
| 2284 | |
| 2285 | |
| 2286 | |
| 2287 | |
| 2288 | |
| 2289 | |
| 2290 | |
| 2291 | |
| 2292 | template<typename _Tp> |
| 2293 | _GLIBCXX20_CONSTEXPR |
| 2294 | _If_sv<_Tp, basic_string&> |
| 2295 | insert(size_type __pos1, const _Tp& __svt, |
| 2296 | size_type __pos2, size_type __n = npos) |
| 2297 | { |
| 2298 | __sv_type __sv = __svt; |
| 2299 | return this->replace(__pos1, size_type(0), |
| 2300 | __sv.data() |
| 2301 | + std::__sv_check(__sv.size(), __pos2, "basic_string::insert"), |
| 2302 | std::__sv_limit(__sv.size(), __pos2, __n)); |
| 2303 | } |
| 2304 | #endif // C++17 |
| 2305 | |
| 2306 | |
| 2307 | |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | |
| 2312 | |
| 2313 | |
| 2314 | |
| 2315 | |
| 2316 | |
| 2317 | |
| 2318 | |
| 2319 | |
| 2320 | |
| 2321 | _GLIBCXX20_CONSTEXPR |
| 2322 | basic_string& |
| 2323 | erase(size_type __pos = 0, size_type __n = npos) |
| 2324 | { |
| 2325 | _M_check(__pos, "basic_string::erase"); |
| 2326 | if (__n == npos) |
| 2327 | this->_M_set_length(__pos); |
| 2328 | else if (__n != 0) |
| 2329 | this->_M_erase(__pos, _M_limit(__pos, __n)); |
| 2330 | return *this; |
| 2331 | } |
| 2332 | |
| 2333 | |
| 2334 | |
| 2335 | |
| 2336 | |
| 2337 | |
| 2338 | |
| 2339 | |
| 2340 | |
| 2341 | _GLIBCXX20_CONSTEXPR |
| 2342 | iterator |
| 2343 | erase(__const_iterator __position) |
| 2344 | { |
| 2345 | _GLIBCXX_DEBUG_PEDASSERT(__position >= begin() |
| 2346 | && __position < end()); |
| 2347 | const size_type __pos = __position - begin(); |
| 2348 | this->_M_erase(__pos, size_type(1)); |
| 2349 | return iterator(_M_data() + __pos); |
| 2350 | } |
| 2351 | |
| 2352 | |
| 2353 | |
| 2354 | |
| 2355 | |
| 2356 | |
| 2357 | |
| 2358 | |
| 2359 | |
| 2360 | |
| 2361 | _GLIBCXX20_CONSTEXPR |
| 2362 | iterator |
| 2363 | erase(__const_iterator __first, __const_iterator __last) |
| 2364 | { |
| 2365 | _GLIBCXX_DEBUG_PEDASSERT(__first >= begin() && __first <= __last |
| 2366 | && __last <= end()); |
| 2367 | const size_type __pos = __first - begin(); |
| 2368 | if (__last == end()) |
| 2369 | this->_M_set_length(__pos); |
| 2370 | else |
| 2371 | this->_M_erase(__pos, __last - __first); |
| 2372 | return iterator(this->_M_data() + __pos); |
| 2373 | } |
| 2374 | |
| 2375 | #if __cplusplus >= 201103L |
| 2376 | |
| 2377 | |
| 2378 | |
| 2379 | |
| 2380 | |
| 2381 | _GLIBCXX20_CONSTEXPR |
| 2382 | void |
| 2383 | pop_back() noexcept |
| 2384 | { |
| 2385 | __glibcxx_assert(!empty()); |
| 2386 | _M_erase(size() - 1, 1); |
| 2387 | } |
| 2388 | #endif // C++11 |
| 2389 | |
| 2390 | |
| 2391 | |
| 2392 | |
| 2393 | |
| 2394 | |
| 2395 | |
| 2396 | |
| 2397 | |
| 2398 | |
| 2399 | |
| 2400 | |
| 2401 | |
| 2402 | |
| 2403 | |
| 2404 | |
| 2405 | |
| 2406 | |
| 2407 | _GLIBCXX20_CONSTEXPR |
| 2408 | basic_string& |
| 2409 | replace(size_type __pos, size_type __n, const basic_string& __str) |
| 2410 | { return this->replace(__pos, __n, __str._M_data(), __str.size()); } |
| 2411 | |
| 2412 | |
| 2413 | |
| 2414 | |
| 2415 | |
| 2416 | |
| 2417 | |
| 2418 | |
| 2419 | |
| 2420 | |
| 2421 | |
| 2422 | |
| 2423 | |
| 2424 | |
| 2425 | |
| 2426 | |
| 2427 | |
| 2428 | |
| 2429 | |
| 2430 | _GLIBCXX20_CONSTEXPR |
| 2431 | basic_string& |
| 2432 | replace(size_type __pos1, size_type __n1, const basic_string& __str, |
| 2433 | size_type __pos2, size_type __n2 = npos) |
| 2434 | { return this->replace(__pos1, __n1, __str._M_data() |
| 2435 | + __str._M_check(__pos2, "basic_string::replace"), |
| 2436 | __str._M_limit(__pos2, __n2)); } |
| 2437 | |
| 2438 | |
| 2439 | |
| 2440 | |
| 2441 | |
| 2442 | |
| 2443 | |
| 2444 | |
| 2445 | |
| 2446 | |
| 2447 | |
| 2448 | |
| 2449 | |
| 2450 | |
| 2451 | |
| 2452 | |
| 2453 | |
| 2454 | |
| 2455 | |
| 2456 | _GLIBCXX20_CONSTEXPR |
| 2457 | basic_string& |
| 2458 | replace(size_type __pos, size_type __n1, const _CharT* __s, |
| 2459 | size_type __n2) |
| 2460 | { |
| 2461 | __glibcxx_requires_string_len(__s, __n2); |
| 2462 | return _M_replace(_M_check(__pos, "basic_string::replace"), |
| 2463 | _M_limit(__pos, __n1), __s, __n2); |
| 2464 | } |
| 2465 | |
| 2466 | |
| 2467 | |
| 2468 | |
| 2469 | |
| 2470 | |
| 2471 | |
| 2472 | |
| 2473 | |
| 2474 | |
| 2475 | |
| 2476 | |
| 2477 | |
| 2478 | |
| 2479 | |
| 2480 | |
| 2481 | |
| 2482 | _GLIBCXX20_CONSTEXPR |
| 2483 | basic_string& |
| 2484 | replace(size_type __pos, size_type __n1, const _CharT* __s) |
| 2485 | { |
| 2486 | __glibcxx_requires_string(__s); |
| 2487 | return this->replace(__pos, __n1, __s, traits_type::length(__s)); |
| 2488 | } |
| 2489 | |
| 2490 | |
| 2491 | |
| 2492 | |
| 2493 | |
| 2494 | |
| 2495 | |
| 2496 | |
| 2497 | |
| 2498 | |
| 2499 | |
| 2500 | |
| 2501 | |
| 2502 | |
| 2503 | |
| 2504 | |
| 2505 | |
| 2506 | |
| 2507 | _GLIBCXX20_CONSTEXPR |
| 2508 | basic_string& |
| 2509 | replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) |
| 2510 | { return _M_replace_aux(_M_check(__pos, "basic_string::replace"), |
| 2511 | _M_limit(__pos, __n1), __n2, __c); } |
| 2512 | |
| 2513 | |
| 2514 | |
| 2515 | |
| 2516 | |
| 2517 | |
| 2518 | |
| 2519 | |
| 2520 | |
| 2521 | |
| 2522 | |
| 2523 | |
| 2524 | |
| 2525 | |
| 2526 | _GLIBCXX20_CONSTEXPR |
| 2527 | basic_string& |
| 2528 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2529 | const basic_string& __str) |
| 2530 | { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } |
| 2531 | |
| 2532 | |
| 2533 | |
| 2534 | |
| 2535 | |
| 2536 | |
| 2537 | |
| 2538 | |
| 2539 | |
| 2540 | |
| 2541 | |
| 2542 | |
| 2543 | |
| 2544 | |
| 2545 | |
| 2546 | |
| 2547 | _GLIBCXX20_CONSTEXPR |
| 2548 | basic_string& |
| 2549 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2550 | const _CharT* __s, size_type __n) |
| 2551 | { |
| 2552 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2553 | && __i2 <= end()); |
| 2554 | return this->replace(__i1 - begin(), __i2 - __i1, __s, __n); |
| 2555 | } |
| 2556 | |
| 2557 | |
| 2558 | |
| 2559 | |
| 2560 | |
| 2561 | |
| 2562 | |
| 2563 | |
| 2564 | |
| 2565 | |
| 2566 | |
| 2567 | |
| 2568 | |
| 2569 | |
| 2570 | _GLIBCXX20_CONSTEXPR |
| 2571 | basic_string& |
| 2572 | replace(__const_iterator __i1, __const_iterator __i2, const _CharT* __s) |
| 2573 | { |
| 2574 | __glibcxx_requires_string(__s); |
| 2575 | return this->replace(__i1, __i2, __s, traits_type::length(__s)); |
| 2576 | } |
| 2577 | |
| 2578 | |
| 2579 | |
| 2580 | |
| 2581 | |
| 2582 | |
| 2583 | |
| 2584 | |
| 2585 | |
| 2586 | |
| 2587 | |
| 2588 | |
| 2589 | |
| 2590 | |
| 2591 | |
| 2592 | _GLIBCXX20_CONSTEXPR |
| 2593 | basic_string& |
| 2594 | replace(__const_iterator __i1, __const_iterator __i2, size_type __n, |
| 2595 | _CharT __c) |
| 2596 | { |
| 2597 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2598 | && __i2 <= end()); |
| 2599 | return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __c); |
| 2600 | } |
| 2601 | |
| 2602 | |
| 2603 | |
| 2604 | |
| 2605 | |
| 2606 | |
| 2607 | |
| 2608 | |
| 2609 | |
| 2610 | |
| 2611 | |
| 2612 | |
| 2613 | |
| 2614 | |
| 2615 | |
| 2616 | |
| 2617 | #if __cplusplus >= 201103L |
| 2618 | template<class _InputIterator, |
| 2619 | typename = std::_RequireInputIter<_InputIterator>> |
| 2620 | _GLIBCXX20_CONSTEXPR |
| 2621 | basic_string& |
| 2622 | replace(const_iterator __i1, const_iterator __i2, |
| 2623 | _InputIterator __k1, _InputIterator __k2) |
| 2624 | { |
| 2625 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2626 | && __i2 <= end()); |
| 2627 | __glibcxx_requires_valid_range(__k1, __k2); |
| 2628 | return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, |
| 2629 | std::__false_type()); |
| 2630 | } |
| 2631 | #else |
| 2632 | template<class _InputIterator> |
| 2633 | #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST |
| 2634 | typename __enable_if_not_native_iterator<_InputIterator>::__type |
| 2635 | #else |
| 2636 | basic_string& |
| 2637 | #endif |
| 2638 | replace(iterator __i1, iterator __i2, |
| 2639 | _InputIterator __k1, _InputIterator __k2) |
| 2640 | { |
| 2641 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2642 | && __i2 <= end()); |
| 2643 | __glibcxx_requires_valid_range(__k1, __k2); |
| 2644 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
| 2645 | return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); |
| 2646 | } |
| 2647 | #endif |
| 2648 | |
| 2649 | |
| 2650 | |
| 2651 | _GLIBCXX20_CONSTEXPR |
| 2652 | basic_string& |
| 2653 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2654 | _CharT* __k1, _CharT* __k2) |
| 2655 | { |
| 2656 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2657 | && __i2 <= end()); |
| 2658 | __glibcxx_requires_valid_range(__k1, __k2); |
| 2659 | return this->replace(__i1 - begin(), __i2 - __i1, |
| 2660 | __k1, __k2 - __k1); |
| 2661 | } |
| 2662 | |
| 2663 | _GLIBCXX20_CONSTEXPR |
| 2664 | basic_string& |
| 2665 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2666 | const _CharT* __k1, const _CharT* __k2) |
| 2667 | { |
| 2668 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2669 | && __i2 <= end()); |
| 2670 | __glibcxx_requires_valid_range(__k1, __k2); |
| 2671 | return this->replace(__i1 - begin(), __i2 - __i1, |
| 2672 | __k1, __k2 - __k1); |
| 2673 | } |
| 2674 | |
| 2675 | _GLIBCXX20_CONSTEXPR |
| 2676 | basic_string& |
| 2677 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2678 | iterator __k1, iterator __k2) |
| 2679 | { |
| 2680 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2681 | && __i2 <= end()); |
| 2682 | __glibcxx_requires_valid_range(__k1, __k2); |
| 2683 | return this->replace(__i1 - begin(), __i2 - __i1, |
| 2684 | __k1.base(), __k2 - __k1); |
| 2685 | } |
| 2686 | |
| 2687 | _GLIBCXX20_CONSTEXPR |
| 2688 | basic_string& |
| 2689 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2690 | const_iterator __k1, const_iterator __k2) |
| 2691 | { |
| 2692 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2693 | && __i2 <= end()); |
| 2694 | __glibcxx_requires_valid_range(__k1, __k2); |
| 2695 | return this->replace(__i1 - begin(), __i2 - __i1, |
| 2696 | __k1.base(), __k2 - __k1); |
| 2697 | } |
| 2698 | |
| 2699 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 2700 | |
| 2701 | |
| 2702 | |
| 2703 | |
| 2704 | |
| 2705 | |
| 2706 | |
| 2707 | template<__detail::__container_compatible_range<_CharT> _Rg> |
| 2708 | constexpr basic_string& |
| 2709 | replace_with_range(const_iterator __i1, const_iterator __i2, _Rg&& __rg) |
| 2710 | { |
| 2711 | if (__i1 == cend()) |
| 2712 | append_range(std::forward<_Rg>(__rg)); |
| 2713 | else |
| 2714 | { |
| 2715 | basic_string __s(from_range, std::forward<_Rg>(__rg), |
| 2716 | _M_get_allocator()); |
| 2717 | replace(__i1, __i2, __s); |
| 2718 | } |
| 2719 | return *this; |
| 2720 | } |
| 2721 | #endif |
| 2722 | |
| 2723 | #if __cplusplus >= 201103L |
| 2724 | |
| 2725 | |
| 2726 | |
| 2727 | |
| 2728 | |
| 2729 | |
| 2730 | |
| 2731 | |
| 2732 | |
| 2733 | |
| 2734 | |
| 2735 | |
| 2736 | |
| 2737 | |
| 2738 | _GLIBCXX20_CONSTEXPR |
| 2739 | basic_string& replace(const_iterator __i1, const_iterator __i2, |
| 2740 | initializer_list<_CharT> __l) |
| 2741 | { return this->replace(__i1, __i2, __l.begin(), __l.size()); } |
| 2742 | #endif // C++11 |
| 2743 | |
| 2744 | #ifdef __glibcxx_string_view // >= C++17 |
| 2745 | |
| 2746 | |
| 2747 | |
| 2748 | |
| 2749 | |
| 2750 | |
| 2751 | |
| 2752 | template<typename _Tp> |
| 2753 | _GLIBCXX20_CONSTEXPR |
| 2754 | _If_sv<_Tp, basic_string&> |
| 2755 | replace(size_type __pos, size_type __n, const _Tp& __svt) |
| 2756 | { |
| 2757 | __sv_type __sv = __svt; |
| 2758 | return this->replace(__pos, __n, __sv.data(), __sv.size()); |
| 2759 | } |
| 2760 | |
| 2761 | |
| 2762 | |
| 2763 | |
| 2764 | |
| 2765 | |
| 2766 | |
| 2767 | |
| 2768 | |
| 2769 | |
| 2770 | template<typename _Tp> |
| 2771 | _GLIBCXX20_CONSTEXPR |
| 2772 | _If_sv<_Tp, basic_string&> |
| 2773 | replace(size_type __pos1, size_type __n1, const _Tp& __svt, |
| 2774 | size_type __pos2, size_type __n2 = npos) |
| 2775 | { |
| 2776 | __sv_type __sv = __svt; |
| 2777 | return this->replace(__pos1, __n1, |
| 2778 | __sv.data() |
| 2779 | + std::__sv_check(__sv.size(), __pos2, "basic_string::replace"), |
| 2780 | std::__sv_limit(__sv.size(), __pos2, __n2)); |
| 2781 | } |
| 2782 | |
| 2783 | |
| 2784 | |
| 2785 | |
| 2786 | |
| 2787 | |
| 2788 | |
| 2789 | |
| 2790 | |
| 2791 | |
| 2792 | template<typename _Tp> |
| 2793 | _GLIBCXX20_CONSTEXPR |
| 2794 | _If_sv<_Tp, basic_string&> |
| 2795 | replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt) |
| 2796 | { |
| 2797 | __sv_type __sv = __svt; |
| 2798 | return this->replace(__i1 - begin(), __i2 - __i1, __sv); |
| 2799 | } |
| 2800 | #endif // C++17 |
| 2801 | |
| 2802 | private: |
| 2803 | template<class _Integer> |
| 2804 | _GLIBCXX20_CONSTEXPR |
| 2805 | basic_string& |
| 2806 | _M_replace_dispatch(const_iterator __i1, const_iterator __i2, |
| 2807 | _Integer __n, _Integer __val, __true_type) |
| 2808 | { return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __val); } |
| 2809 | |
| 2810 | template<class _InputIterator> |
| 2811 | _GLIBCXX20_CONSTEXPR |
| 2812 | basic_string& |
| 2813 | _M_replace_dispatch(const_iterator __i1, const_iterator __i2, |
| 2814 | _InputIterator __k1, _InputIterator __k2, |
| 2815 | __false_type); |
| 2816 | |
| 2817 | _GLIBCXX20_CONSTEXPR |
| 2818 | basic_string& |
| 2819 | _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, |
| 2820 | _CharT __c); |
| 2821 | |
| 2822 | __attribute__((__noinline__, __noclone__, __cold__)) void |
| 2823 | _M_replace_cold(pointer __p, size_type __len1, const _CharT* __s, |
| 2824 | const size_type __len2, const size_type __how_much); |
| 2825 | |
| 2826 | _GLIBCXX20_CONSTEXPR |
| 2827 | basic_string& |
| 2828 | _M_replace(size_type __pos, size_type __len1, const _CharT* __s, |
| 2829 | const size_type __len2); |
| 2830 | |
| 2831 | _GLIBCXX20_CONSTEXPR |
| 2832 | basic_string& |
| 2833 | _M_append(const _CharT* __s, size_type __n); |
| 2834 | |
| 2835 | public: |
| 2836 | |
| 2837 | |
| 2838 | |
| 2839 | |
| 2840 | |
| 2841 | |
| 2842 | |
| 2843 | |
| 2844 | |
| 2845 | |
| 2846 | |
| 2847 | |
| 2848 | |
| 2849 | _GLIBCXX20_CONSTEXPR |
| 2850 | size_type |
| 2851 | copy(_CharT* __s, size_type __n, size_type __pos = 0) const; |
| 2852 | |
| 2853 | |
| 2854 | |
| 2855 | |
| 2856 | |
| 2857 | |
| 2858 | |
| 2859 | |
| 2860 | _GLIBCXX20_CONSTEXPR |
| 2861 | void |
| 2862 | swap(basic_string& __s) _GLIBCXX_NOEXCEPT; |
| 2863 | |
| 2864 | |
| 2865 | |
| 2866 | |
| 2867 | |
| 2868 | |
| 2869 | |
| 2870 | |
| 2871 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 2872 | const _CharT* |
| 2873 | c_str() const _GLIBCXX_NOEXCEPT |
| 2874 | { return _M_data(); } |
| 2875 | |
| 2876 | |
| 2877 | |
| 2878 | |
| 2879 | |
| 2880 | |
| 2881 | |
| 2882 | |
| 2883 | |
| 2884 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 2885 | const _CharT* |
| 2886 | data() const _GLIBCXX_NOEXCEPT |
| 2887 | { return _M_data(); } |
| 2888 | |
| 2889 | #if __cplusplus >= 201703L |
| 2890 | |
| 2891 | |
| 2892 | |
| 2893 | |
| 2894 | |
| 2895 | |
| 2896 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 2897 | _CharT* |
| 2898 | data() noexcept |
| 2899 | { return _M_data(); } |
| 2900 | #endif |
| 2901 | |
| 2902 | |
| 2903 | |
| 2904 | |
| 2905 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 2906 | allocator_type |
| 2907 | get_allocator() const _GLIBCXX_NOEXCEPT |
| 2908 | { return _M_get_allocator(); } |
| 2909 | |
| 2910 | |
| 2911 | |
| 2912 | |
| 2913 | |
| 2914 | |
| 2915 | |
| 2916 | |
| 2917 | |
| 2918 | |
| 2919 | |
| 2920 | |
| 2921 | |
| 2922 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 2923 | size_type |
| 2924 | find(const _CharT* __s, size_type __pos, size_type __n) const |
| 2925 | _GLIBCXX_NOEXCEPT; |
| 2926 | |
| 2927 | |
| 2928 | |
| 2929 | |
| 2930 | |
| 2931 | |
| 2932 | |
| 2933 | |
| 2934 | |
| 2935 | |
| 2936 | |
| 2937 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 2938 | size_type |
| 2939 | find(const basic_string& __str, size_type __pos = 0) const |
| 2940 | _GLIBCXX_NOEXCEPT |
| 2941 | { return this->find(__str.data(), __pos, __str.size()); } |
| 2942 | |
| 2943 | #ifdef __glibcxx_string_view // >= C++17 |
| 2944 | |
| 2945 | |
| 2946 | |
| 2947 | |
| 2948 | |
| 2949 | |
| 2950 | template<typename _Tp> |
| 2951 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 2952 | _If_sv<_Tp, size_type> |
| 2953 | find(const _Tp& __svt, size_type __pos = 0) const |
| 2954 | noexcept(is_same<_Tp, __sv_type>::value) |
| 2955 | { |
| 2956 | __sv_type __sv = __svt; |
| 2957 | return this->find(__sv.data(), __pos, __sv.size()); |
| 2958 | } |
| 2959 | #endif // C++17 |
| 2960 | |
| 2961 | |
| 2962 | |
| 2963 | |
| 2964 | |
| 2965 | |
| 2966 | |
| 2967 | |
| 2968 | |
| 2969 | |
| 2970 | |
| 2971 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 2972 | size_type |
| 2973 | find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT |
| 2974 | { |
| 2975 | __glibcxx_requires_string(__s); |
| 2976 | return this->find(__s, __pos, traits_type::length(__s)); |
| 2977 | } |
| 2978 | |
| 2979 | |
| 2980 | |
| 2981 | |
| 2982 | |
| 2983 | |
| 2984 | |
| 2985 | |
| 2986 | |
| 2987 | |
| 2988 | |
| 2989 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 2990 | size_type |
| 2991 | find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; |
| 2992 | |
| 2993 | |
| 2994 | |
| 2995 | |
| 2996 | |
| 2997 | |
| 2998 | |
| 2999 | |
| 3000 | |
| 3001 | |
| 3002 | |
| 3003 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3004 | size_type |
| 3005 | rfind(const basic_string& __str, size_type __pos = npos) const |
| 3006 | _GLIBCXX_NOEXCEPT |
| 3007 | { return this->rfind(__str.data(), __pos, __str.size()); } |
| 3008 | |
| 3009 | #ifdef __glibcxx_string_view // >= C++17 |
| 3010 | |
| 3011 | |
| 3012 | |
| 3013 | |
| 3014 | |
| 3015 | |
| 3016 | template<typename _Tp> |
| 3017 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3018 | _If_sv<_Tp, size_type> |
| 3019 | rfind(const _Tp& __svt, size_type __pos = npos) const |
| 3020 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3021 | { |
| 3022 | __sv_type __sv = __svt; |
| 3023 | return this->rfind(__sv.data(), __pos, __sv.size()); |
| 3024 | } |
| 3025 | #endif // C++17 |
| 3026 | |
| 3027 | |
| 3028 | |
| 3029 | |
| 3030 | |
| 3031 | |
| 3032 | |
| 3033 | |
| 3034 | |
| 3035 | |
| 3036 | |
| 3037 | |
| 3038 | |
| 3039 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3040 | size_type |
| 3041 | rfind(const _CharT* __s, size_type __pos, size_type __n) const |
| 3042 | _GLIBCXX_NOEXCEPT; |
| 3043 | |
| 3044 | |
| 3045 | |
| 3046 | |
| 3047 | |
| 3048 | |
| 3049 | |
| 3050 | |
| 3051 | |
| 3052 | |
| 3053 | |
| 3054 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3055 | size_type |
| 3056 | rfind(const _CharT* __s, size_type __pos = npos) const |
| 3057 | { |
| 3058 | __glibcxx_requires_string(__s); |
| 3059 | return this->rfind(__s, __pos, traits_type::length(__s)); |
| 3060 | } |
| 3061 | |
| 3062 | |
| 3063 | |
| 3064 | |
| 3065 | |
| 3066 | |
| 3067 | |
| 3068 | |
| 3069 | |
| 3070 | |
| 3071 | |
| 3072 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3073 | size_type |
| 3074 | rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; |
| 3075 | |
| 3076 | |
| 3077 | |
| 3078 | |
| 3079 | |
| 3080 | |
| 3081 | |
| 3082 | |
| 3083 | |
| 3084 | |
| 3085 | |
| 3086 | |
| 3087 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3088 | size_type |
| 3089 | find_first_of(const basic_string& __str, size_type __pos = 0) const |
| 3090 | _GLIBCXX_NOEXCEPT |
| 3091 | { return this->find_first_of(__str.data(), __pos, __str.size()); } |
| 3092 | |
| 3093 | #ifdef __glibcxx_string_view // >= C++17 |
| 3094 | |
| 3095 | |
| 3096 | |
| 3097 | |
| 3098 | |
| 3099 | |
| 3100 | |
| 3101 | template<typename _Tp> |
| 3102 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3103 | _If_sv<_Tp, size_type> |
| 3104 | find_first_of(const _Tp& __svt, size_type __pos = 0) const |
| 3105 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3106 | { |
| 3107 | __sv_type __sv = __svt; |
| 3108 | return this->find_first_of(__sv.data(), __pos, __sv.size()); |
| 3109 | } |
| 3110 | #endif // C++17 |
| 3111 | |
| 3112 | |
| 3113 | |
| 3114 | |
| 3115 | |
| 3116 | |
| 3117 | |
| 3118 | |
| 3119 | |
| 3120 | |
| 3121 | |
| 3122 | |
| 3123 | |
| 3124 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3125 | size_type |
| 3126 | find_first_of(const _CharT* __s, size_type __pos, size_type __n) const |
| 3127 | _GLIBCXX_NOEXCEPT; |
| 3128 | |
| 3129 | |
| 3130 | |
| 3131 | |
| 3132 | |
| 3133 | |
| 3134 | |
| 3135 | |
| 3136 | |
| 3137 | |
| 3138 | |
| 3139 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3140 | size_type |
| 3141 | find_first_of(const _CharT* __s, size_type __pos = 0) const |
| 3142 | _GLIBCXX_NOEXCEPT |
| 3143 | { |
| 3144 | __glibcxx_requires_string(__s); |
| 3145 | return this->find_first_of(__s, __pos, traits_type::length(__s)); |
| 3146 | } |
| 3147 | |
| 3148 | |
| 3149 | |
| 3150 | |
| 3151 | |
| 3152 | |
| 3153 | |
| 3154 | |
| 3155 | |
| 3156 | |
| 3157 | |
| 3158 | |
| 3159 | |
| 3160 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3161 | size_type |
| 3162 | find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT |
| 3163 | { return this->find(__c, __pos); } |
| 3164 | |
| 3165 | |
| 3166 | |
| 3167 | |
| 3168 | |
| 3169 | |
| 3170 | |
| 3171 | |
| 3172 | |
| 3173 | |
| 3174 | |
| 3175 | |
| 3176 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3177 | size_type |
| 3178 | find_last_of(const basic_string& __str, size_type __pos = npos) const |
| 3179 | _GLIBCXX_NOEXCEPT |
| 3180 | { return this->find_last_of(__str.data(), __pos, __str.size()); } |
| 3181 | |
| 3182 | #ifdef __glibcxx_string_view // >= C++17 |
| 3183 | |
| 3184 | |
| 3185 | |
| 3186 | |
| 3187 | |
| 3188 | |
| 3189 | |
| 3190 | template<typename _Tp> |
| 3191 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3192 | _If_sv<_Tp, size_type> |
| 3193 | find_last_of(const _Tp& __svt, size_type __pos = npos) const |
| 3194 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3195 | { |
| 3196 | __sv_type __sv = __svt; |
| 3197 | return this->find_last_of(__sv.data(), __pos, __sv.size()); |
| 3198 | } |
| 3199 | #endif // C++17 |
| 3200 | |
| 3201 | |
| 3202 | |
| 3203 | |
| 3204 | |
| 3205 | |
| 3206 | |
| 3207 | |
| 3208 | |
| 3209 | |
| 3210 | |
| 3211 | |
| 3212 | |
| 3213 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3214 | size_type |
| 3215 | find_last_of(const _CharT* __s, size_type __pos, size_type __n) const |
| 3216 | _GLIBCXX_NOEXCEPT; |
| 3217 | |
| 3218 | |
| 3219 | |
| 3220 | |
| 3221 | |
| 3222 | |
| 3223 | |
| 3224 | |
| 3225 | |
| 3226 | |
| 3227 | |
| 3228 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3229 | size_type |
| 3230 | find_last_of(const _CharT* __s, size_type __pos = npos) const |
| 3231 | _GLIBCXX_NOEXCEPT |
| 3232 | { |
| 3233 | __glibcxx_requires_string(__s); |
| 3234 | return this->find_last_of(__s, __pos, traits_type::length(__s)); |
| 3235 | } |
| 3236 | |
| 3237 | |
| 3238 | |
| 3239 | |
| 3240 | |
| 3241 | |
| 3242 | |
| 3243 | |
| 3244 | |
| 3245 | |
| 3246 | |
| 3247 | |
| 3248 | |
| 3249 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3250 | size_type |
| 3251 | find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT |
| 3252 | { return this->rfind(__c, __pos); } |
| 3253 | |
| 3254 | |
| 3255 | |
| 3256 | |
| 3257 | |
| 3258 | |
| 3259 | |
| 3260 | |
| 3261 | |
| 3262 | |
| 3263 | |
| 3264 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3265 | size_type |
| 3266 | find_first_not_of(const basic_string& __str, size_type __pos = 0) const |
| 3267 | _GLIBCXX_NOEXCEPT |
| 3268 | { return this->find_first_not_of(__str.data(), __pos, __str.size()); } |
| 3269 | |
| 3270 | #ifdef __glibcxx_string_view // >= C++17 |
| 3271 | |
| 3272 | |
| 3273 | |
| 3274 | |
| 3275 | |
| 3276 | |
| 3277 | |
| 3278 | template<typename _Tp> |
| 3279 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3280 | _If_sv<_Tp, size_type> |
| 3281 | find_first_not_of(const _Tp& __svt, size_type __pos = 0) const |
| 3282 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3283 | { |
| 3284 | __sv_type __sv = __svt; |
| 3285 | return this->find_first_not_of(__sv.data(), __pos, __sv.size()); |
| 3286 | } |
| 3287 | #endif // C++17 |
| 3288 | |
| 3289 | |
| 3290 | |
| 3291 | |
| 3292 | |
| 3293 | |
| 3294 | |
| 3295 | |
| 3296 | |
| 3297 | |
| 3298 | |
| 3299 | |
| 3300 | |
| 3301 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3302 | size_type |
| 3303 | find_first_not_of(const _CharT* __s, size_type __pos, |
| 3304 | size_type __n) const _GLIBCXX_NOEXCEPT; |
| 3305 | |
| 3306 | |
| 3307 | |
| 3308 | |
| 3309 | |
| 3310 | |
| 3311 | |
| 3312 | |
| 3313 | |
| 3314 | |
| 3315 | |
| 3316 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3317 | size_type |
| 3318 | find_first_not_of(const _CharT* __s, size_type __pos = 0) const |
| 3319 | _GLIBCXX_NOEXCEPT |
| 3320 | { |
| 3321 | __glibcxx_requires_string(__s); |
| 3322 | return this->find_first_not_of(__s, __pos, traits_type::length(__s)); |
| 3323 | } |
| 3324 | |
| 3325 | |
| 3326 | |
| 3327 | |
| 3328 | |
| 3329 | |
| 3330 | |
| 3331 | |
| 3332 | |
| 3333 | |
| 3334 | |
| 3335 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3336 | size_type |
| 3337 | find_first_not_of(_CharT __c, size_type __pos = 0) const |
| 3338 | _GLIBCXX_NOEXCEPT; |
| 3339 | |
| 3340 | |
| 3341 | |
| 3342 | |
| 3343 | |
| 3344 | |
| 3345 | |
| 3346 | |
| 3347 | |
| 3348 | |
| 3349 | |
| 3350 | |
| 3351 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3352 | size_type |
| 3353 | find_last_not_of(const basic_string& __str, size_type __pos = npos) const |
| 3354 | _GLIBCXX_NOEXCEPT |
| 3355 | { return this->find_last_not_of(__str.data(), __pos, __str.size()); } |
| 3356 | |
| 3357 | #ifdef __glibcxx_string_view // >= C++17 |
| 3358 | |
| 3359 | |
| 3360 | |
| 3361 | |
| 3362 | |
| 3363 | |
| 3364 | |
| 3365 | template<typename _Tp> |
| 3366 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3367 | _If_sv<_Tp, size_type> |
| 3368 | find_last_not_of(const _Tp& __svt, size_type __pos = npos) const |
| 3369 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3370 | { |
| 3371 | __sv_type __sv = __svt; |
| 3372 | return this->find_last_not_of(__sv.data(), __pos, __sv.size()); |
| 3373 | } |
| 3374 | #endif // C++17 |
| 3375 | |
| 3376 | |
| 3377 | |
| 3378 | |
| 3379 | |
| 3380 | |
| 3381 | |
| 3382 | |
| 3383 | |
| 3384 | |
| 3385 | |
| 3386 | |
| 3387 | |
| 3388 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3389 | size_type |
| 3390 | find_last_not_of(const _CharT* __s, size_type __pos, |
| 3391 | size_type __n) const _GLIBCXX_NOEXCEPT; |
| 3392 | |
| 3393 | |
| 3394 | |
| 3395 | |
| 3396 | |
| 3397 | |
| 3398 | |
| 3399 | |
| 3400 | |
| 3401 | |
| 3402 | |
| 3403 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3404 | size_type |
| 3405 | find_last_not_of(const _CharT* __s, size_type __pos = npos) const |
| 3406 | _GLIBCXX_NOEXCEPT |
| 3407 | { |
| 3408 | __glibcxx_requires_string(__s); |
| 3409 | return this->find_last_not_of(__s, __pos, traits_type::length(__s)); |
| 3410 | } |
| 3411 | |
| 3412 | |
| 3413 | |
| 3414 | |
| 3415 | |
| 3416 | |
| 3417 | |
| 3418 | |
| 3419 | |
| 3420 | |
| 3421 | |
| 3422 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3423 | size_type |
| 3424 | find_last_not_of(_CharT __c, size_type __pos = npos) const |
| 3425 | _GLIBCXX_NOEXCEPT; |
| 3426 | |
| 3427 | |
| 3428 | |
| 3429 | |
| 3430 | |
| 3431 | |
| 3432 | |
| 3433 | |
| 3434 | |
| 3435 | |
| 3436 | |
| 3437 | |
| 3438 | |
| 3439 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3440 | basic_string |
| 3441 | substr(size_type __pos = 0, size_type __n = npos) const |
| 3442 | { return basic_string(*this, |
| 3443 | _M_check(__pos, "basic_string::substr"), __n); } |
| 3444 | |
| 3445 | |
| 3446 | |
| 3447 | |
| 3448 | |
| 3449 | |
| 3450 | |
| 3451 | |
| 3452 | |
| 3453 | |
| 3454 | |
| 3455 | |
| 3456 | |
| 3457 | |
| 3458 | |
| 3459 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3460 | int |
| 3461 | compare(const basic_string& __str) const |
| 3462 | { |
| 3463 | const size_type __size = this->size(); |
| 3464 | const size_type __osize = __str.size(); |
| 3465 | const size_type __len = std::min(__size, __osize); |
| 3466 | |
| 3467 | int __r = traits_type::compare(_M_data(), __str.data(), __len); |
| 3468 | if (!__r) |
| 3469 | __r = _S_compare(__size, __osize); |
| 3470 | return __r; |
| 3471 | } |
| 3472 | |
| 3473 | #ifdef __glibcxx_string_view // >= C++17 |
| 3474 | |
| 3475 | |
| 3476 | |
| 3477 | |
| 3478 | |
| 3479 | template<typename _Tp> |
| 3480 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3481 | _If_sv<_Tp, int> |
| 3482 | compare(const _Tp& __svt) const |
| 3483 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3484 | { |
| 3485 | __sv_type __sv = __svt; |
| 3486 | const size_type __size = this->size(); |
| 3487 | const size_type __osize = __sv.size(); |
| 3488 | const size_type __len = std::min(__size, __osize); |
| 3489 | |
| 3490 | int __r = traits_type::compare(_M_data(), __sv.data(), __len); |
| 3491 | if (!__r) |
| 3492 | __r = _S_compare(__size, __osize); |
| 3493 | return __r; |
| 3494 | } |
| 3495 | |
| 3496 | |
| 3497 | |
| 3498 | |
| 3499 | |
| 3500 | |
| 3501 | |
| 3502 | |
| 3503 | |
| 3504 | template<typename _Tp> |
| 3505 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3506 | _If_sv<_Tp, int> |
| 3507 | compare(size_type __pos, size_type __n, const _Tp& __svt) const |
| 3508 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3509 | { |
| 3510 | __sv_type __sv = __svt; |
| 3511 | return __sv_type(*this).substr(__pos, __n).compare(__sv); |
| 3512 | } |
| 3513 | |
| 3514 | |
| 3515 | |
| 3516 | |
| 3517 | |
| 3518 | |
| 3519 | |
| 3520 | |
| 3521 | |
| 3522 | |
| 3523 | |
| 3524 | template<typename _Tp> |
| 3525 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3526 | _If_sv<_Tp, int> |
| 3527 | compare(size_type __pos1, size_type __n1, const _Tp& __svt, |
| 3528 | size_type __pos2, size_type __n2 = npos) const |
| 3529 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3530 | { |
| 3531 | __sv_type __sv = __svt; |
| 3532 | return __sv_type(*this) |
| 3533 | .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
| 3534 | } |
| 3535 | #endif // C++17 |
| 3536 | |
| 3537 | |
| 3538 | |
| 3539 | |
| 3540 | |
| 3541 | |
| 3542 | |
| 3543 | |
| 3544 | |
| 3545 | |
| 3546 | |
| 3547 | |
| 3548 | |
| 3549 | |
| 3550 | |
| 3551 | |
| 3552 | |
| 3553 | |
| 3554 | |
| 3555 | |
| 3556 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3557 | int |
| 3558 | compare(size_type __pos, size_type __n, const basic_string& __str) const |
| 3559 | { |
| 3560 | _M_check(__pos, "basic_string::compare"); |
| 3561 | __n = _M_limit(__pos, __n); |
| 3562 | const size_type __osize = __str.size(); |
| 3563 | const size_type __len = std::min(__n, __osize); |
| 3564 | int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len); |
| 3565 | if (!__r) |
| 3566 | __r = _S_compare(__n, __osize); |
| 3567 | return __r; |
| 3568 | } |
| 3569 | |
| 3570 | |
| 3571 | |
| 3572 | |
| 3573 | |
| 3574 | |
| 3575 | |
| 3576 | |
| 3577 | |
| 3578 | |
| 3579 | |
| 3580 | |
| 3581 | |
| 3582 | |
| 3583 | |
| 3584 | |
| 3585 | |
| 3586 | |
| 3587 | |
| 3588 | |
| 3589 | |
| 3590 | |
| 3591 | |
| 3592 | |
| 3593 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3594 | int |
| 3595 | compare(size_type __pos1, size_type __n1, const basic_string& __str, |
| 3596 | size_type __pos2, size_type __n2 = npos) const |
| 3597 | { |
| 3598 | _M_check(__pos1, "basic_string::compare"); |
| 3599 | __str._M_check(__pos2, "basic_string::compare"); |
| 3600 | __n1 = _M_limit(__pos1, __n1); |
| 3601 | __n2 = __str._M_limit(__pos2, __n2); |
| 3602 | const size_type __len = std::min(__n1, __n2); |
| 3603 | int __r = traits_type::compare(_M_data() + __pos1, |
| 3604 | __str.data() + __pos2, __len); |
| 3605 | if (!__r) |
| 3606 | __r = _S_compare(__n1, __n2); |
| 3607 | return __r; |
| 3608 | } |
| 3609 | |
| 3610 | |
| 3611 | |
| 3612 | |
| 3613 | |
| 3614 | |
| 3615 | |
| 3616 | |
| 3617 | |
| 3618 | |
| 3619 | |
| 3620 | |
| 3621 | |
| 3622 | |
| 3623 | |
| 3624 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3625 | int |
| 3626 | compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT |
| 3627 | { |
| 3628 | __glibcxx_requires_string(__s); |
| 3629 | const size_type __size = this->size(); |
| 3630 | const size_type __osize = traits_type::length(__s); |
| 3631 | const size_type __len = std::min(__size, __osize); |
| 3632 | int __r = traits_type::compare(_M_data(), __s, __len); |
| 3633 | if (!__r) |
| 3634 | __r = _S_compare(__size, __osize); |
| 3635 | return __r; |
| 3636 | } |
| 3637 | |
| 3638 | |
| 3639 | |
| 3640 | |
| 3641 | |
| 3642 | |
| 3643 | |
| 3644 | |
| 3645 | |
| 3646 | |
| 3647 | |
| 3648 | |
| 3649 | |
| 3650 | |
| 3651 | |
| 3652 | |
| 3653 | |
| 3654 | |
| 3655 | |
| 3656 | |
| 3657 | |
| 3658 | |
| 3659 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3660 | int |
| 3661 | compare(size_type __pos, size_type __n1, const _CharT* __s) const |
| 3662 | { |
| 3663 | __glibcxx_requires_string(__s); |
| 3664 | _M_check(__pos, "basic_string::compare"); |
| 3665 | __n1 = _M_limit(__pos, __n1); |
| 3666 | const size_type __osize = traits_type::length(__s); |
| 3667 | const size_type __len = std::min(__n1, __osize); |
| 3668 | int __r = traits_type::compare(_M_data() + __pos, __s, __len); |
| 3669 | if (!__r) |
| 3670 | __r = _S_compare(__n1, __osize); |
| 3671 | return __r; |
| 3672 | } |
| 3673 | |
| 3674 | |
| 3675 | |
| 3676 | |
| 3677 | |
| 3678 | |
| 3679 | |
| 3680 | |
| 3681 | |
| 3682 | |
| 3683 | |
| 3684 | |
| 3685 | |
| 3686 | |
| 3687 | |
| 3688 | |
| 3689 | |
| 3690 | |
| 3691 | |
| 3692 | |
| 3693 | |
| 3694 | |
| 3695 | |
| 3696 | |
| 3697 | |
| 3698 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3699 | int |
| 3700 | compare(size_type __pos, size_type __n1, const _CharT* __s, |
| 3701 | size_type __n2) const |
| 3702 | { |
| 3703 | __glibcxx_requires_string_len(__s, __n2); |
| 3704 | _M_check(__pos, "basic_string::compare"); |
| 3705 | __n1 = _M_limit(__pos, __n1); |
| 3706 | const size_type __len = std::min(__n1, __n2); |
| 3707 | int __r = traits_type::compare(_M_data() + __pos, __s, __len); |
| 3708 | if (!__r) |
| 3709 | __r = _S_compare(__n1, __n2); |
| 3710 | return __r; |
| 3711 | } |
| 3712 | |
| 3713 | #if __cplusplus >= 202002L |
| 3714 | [[nodiscard]] |
| 3715 | constexpr bool |
| 3716 | starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept |
| 3717 | { return __sv_type(this->data(), this->size()).starts_with(__x); } |
| 3718 | |
| 3719 | [[nodiscard]] |
| 3720 | constexpr bool |
| 3721 | starts_with(_CharT __x) const noexcept |
| 3722 | { return __sv_type(this->data(), this->size()).starts_with(__x); } |
| 3723 | |
| 3724 | [[nodiscard, __gnu__::__nonnull__]] |
| 3725 | constexpr bool |
| 3726 | starts_with(const _CharT* __x) const noexcept |
| 3727 | { return __sv_type(this->data(), this->size()).starts_with(__x); } |
| 3728 | |
| 3729 | [[nodiscard]] |
| 3730 | constexpr bool |
| 3731 | ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept |
| 3732 | { return __sv_type(this->data(), this->size()).ends_with(__x); } |
| 3733 | |
| 3734 | [[nodiscard]] |
| 3735 | constexpr bool |
| 3736 | ends_with(_CharT __x) const noexcept |
| 3737 | { return __sv_type(this->data(), this->size()).ends_with(__x); } |
| 3738 | |
| 3739 | [[nodiscard, __gnu__::__nonnull__]] |
| 3740 | constexpr bool |
| 3741 | ends_with(const _CharT* __x) const noexcept |
| 3742 | { return __sv_type(this->data(), this->size()).ends_with(__x); } |
| 3743 | #endif // C++20 |
| 3744 | |
| 3745 | #if __cplusplus > 202002L |
| 3746 | [[nodiscard]] |
| 3747 | constexpr bool |
| 3748 | contains(basic_string_view<_CharT, _Traits> __x) const noexcept |
| 3749 | { return __sv_type(this->data(), this->size()).contains(__x); } |
| 3750 | |
| 3751 | [[nodiscard]] |
| 3752 | constexpr bool |
| 3753 | contains(_CharT __x) const noexcept |
| 3754 | { return __sv_type(this->data(), this->size()).contains(__x); } |
| 3755 | |
| 3756 | [[nodiscard, __gnu__::__nonnull__]] |
| 3757 | constexpr bool |
| 3758 | contains(const _CharT* __x) const noexcept |
| 3759 | { return __sv_type(this->data(), this->size()).contains(__x); } |
| 3760 | #endif // C++23 |
| 3761 | |
| 3762 | |
| 3763 | template<typename, typename, typename> friend class basic_stringbuf; |
| 3764 | }; |
| 3765 | _GLIBCXX_END_NAMESPACE_CXX11 |
| 3766 | _GLIBCXX_END_NAMESPACE_VERSION |
| 3767 | } |
| 3768 | #endif // _GLIBCXX_USE_CXX11_ABI |
| 3769 | |
| 3770 | namespace std _GLIBCXX_VISIBILITY(default) |
| 3771 | { |
| 3772 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 3773 | |
| 3774 | #if __cpp_deduction_guides >= 201606 |
| 3775 | _GLIBCXX_BEGIN_NAMESPACE_CXX11 |
| 3776 | template<typename _InputIterator, typename _CharT |
| 3777 | = typename iterator_traits<_InputIterator>::value_type, |
| 3778 | typename _Allocator = allocator<_CharT>, |
| 3779 | typename = _RequireInputIter<_InputIterator>, |
| 3780 | typename = _RequireAllocator<_Allocator>> |
| 3781 | basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) |
| 3782 | -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; |
| 3783 | |
| 3784 | |
| 3785 | |
| 3786 | template<typename _CharT, typename _Traits, |
| 3787 | typename _Allocator = allocator<_CharT>, |
| 3788 | typename = _RequireAllocator<_Allocator>> |
| 3789 | basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) |
| 3790 | -> basic_string<_CharT, _Traits, _Allocator>; |
| 3791 | |
| 3792 | template<typename _CharT, typename _Traits, |
| 3793 | typename _Allocator = allocator<_CharT>, |
| 3794 | typename = _RequireAllocator<_Allocator>> |
| 3795 | basic_string(basic_string_view<_CharT, _Traits>, |
| 3796 | typename basic_string<_CharT, _Traits, _Allocator>::size_type, |
| 3797 | typename basic_string<_CharT, _Traits, _Allocator>::size_type, |
| 3798 | const _Allocator& = _Allocator()) |
| 3799 | -> basic_string<_CharT, _Traits, _Allocator>; |
| 3800 | |
| 3801 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 3802 | template<ranges::input_range _Rg, |
| 3803 | typename _Allocator = allocator<ranges::range_value_t<_Rg>>> |
| 3804 | basic_string(from_range_t, _Rg&&, _Allocator = _Allocator()) |
| 3805 | -> basic_string<ranges::range_value_t<_Rg>, |
| 3806 | char_traits<ranges::range_value_t<_Rg>>, |
| 3807 | _Allocator>; |
| 3808 | #endif |
| 3809 | _GLIBCXX_END_NAMESPACE_CXX11 |
| 3810 | #endif |
| 3811 | |
| 3812 | template<typename _Str> |
| 3813 | _GLIBCXX20_CONSTEXPR |
| 3814 | inline _Str |
| 3815 | __str_concat(typename _Str::value_type const* __lhs, |
| 3816 | typename _Str::size_type __lhs_len, |
| 3817 | typename _Str::value_type const* __rhs, |
| 3818 | typename _Str::size_type __rhs_len, |
| 3819 | typename _Str::allocator_type const& __a) |
| 3820 | { |
| 3821 | typedef typename _Str::allocator_type allocator_type; |
| 3822 | typedef __gnu_cxx::__alloc_traits<allocator_type> _Alloc_traits; |
| 3823 | _Str __str(_Alloc_traits::_S_select_on_copy(__a)); |
| 3824 | __str.reserve(__lhs_len + __rhs_len); |
| 3825 | __str.append(__lhs, __lhs_len); |
| 3826 | __str.append(__rhs, __rhs_len); |
| 3827 | return __str; |
| 3828 | } |
| 3829 | |
| 3830 | |
| 3831 | |
| 3832 | |
| 3833 | |
| 3834 | |
| 3835 | |
| 3836 | |
| 3837 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3838 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3839 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3840 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 3841 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 3842 | { |
| 3843 | typedef basic_string<_CharT, _Traits, _Alloc> _Str; |
| 3844 | return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(), |
| 3845 | __rhs.c_str(), __rhs.size(), |
| 3846 | __lhs.get_allocator()); |
| 3847 | } |
| 3848 | |
| 3849 | |
| 3850 | |
| 3851 | |
| 3852 | |
| 3853 | |
| 3854 | |
| 3855 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3856 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3857 | inline basic_string<_CharT,_Traits,_Alloc> |
| 3858 | operator+(const _CharT* __lhs, |
| 3859 | const basic_string<_CharT,_Traits,_Alloc>& __rhs) |
| 3860 | { |
| 3861 | __glibcxx_requires_string(__lhs); |
| 3862 | typedef basic_string<_CharT, _Traits, _Alloc> _Str; |
| 3863 | return std::__str_concat<_Str>(__lhs, _Traits::length(__lhs), |
| 3864 | __rhs.c_str(), __rhs.size(), |
| 3865 | __rhs.get_allocator()); |
| 3866 | } |
| 3867 | |
| 3868 | |
| 3869 | |
| 3870 | |
| 3871 | |
| 3872 | |
| 3873 | |
| 3874 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3875 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3876 | inline basic_string<_CharT,_Traits,_Alloc> |
| 3877 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs) |
| 3878 | { |
| 3879 | typedef basic_string<_CharT, _Traits, _Alloc> _Str; |
| 3880 | return std::__str_concat<_Str>(__builtin_addressof(__lhs), 1, |
| 3881 | __rhs.c_str(), __rhs.size(), |
| 3882 | __rhs.get_allocator()); |
| 3883 | } |
| 3884 | |
| 3885 | |
| 3886 | |
| 3887 | |
| 3888 | |
| 3889 | |
| 3890 | |
| 3891 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3892 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3893 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3894 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 3895 | const _CharT* __rhs) |
| 3896 | { |
| 3897 | __glibcxx_requires_string(__rhs); |
| 3898 | typedef basic_string<_CharT, _Traits, _Alloc> _Str; |
| 3899 | return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(), |
| 3900 | __rhs, _Traits::length(__rhs), |
| 3901 | __lhs.get_allocator()); |
| 3902 | } |
| 3903 | |
| 3904 | |
| 3905 | |
| 3906 | |
| 3907 | |
| 3908 | |
| 3909 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3910 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3911 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3912 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) |
| 3913 | { |
| 3914 | typedef basic_string<_CharT, _Traits, _Alloc> _Str; |
| 3915 | return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(), |
| 3916 | __builtin_addressof(__rhs), 1, |
| 3917 | __lhs.get_allocator()); |
| 3918 | } |
| 3919 | |
| 3920 | #if __cplusplus >= 201103L |
| 3921 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3922 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3923 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3924 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
| 3925 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 3926 | { return std::move(__lhs.append(__rhs)); } |
| 3927 | |
| 3928 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3929 | _GLIBCXX20_CONSTEXPR |
| 3930 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3931 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 3932 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
| 3933 | { return std::move(__rhs.insert(0, __lhs)); } |
| 3934 | |
| 3935 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3936 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3937 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3938 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
| 3939 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
| 3940 | { |
| 3941 | #if _GLIBCXX_USE_CXX11_ABI |
| 3942 | using _Alloc_traits = allocator_traits<_Alloc>; |
| 3943 | bool __use_rhs = false; |
| 3944 | if _GLIBCXX17_CONSTEXPR (typename _Alloc_traits::is_always_equal{}) |
| 3945 | __use_rhs = true; |
| 3946 | else if (__lhs.get_allocator() == __rhs.get_allocator()) |
| 3947 | __use_rhs = true; |
| 3948 | if (__use_rhs) |
| 3949 | #endif |
| 3950 | { |
| 3951 | const auto __size = __lhs.size() + __rhs.size(); |
| 3952 | if (__size > __lhs.capacity() && __size <= __rhs.capacity()) |
| 3953 | return std::move(__rhs.insert(0, __lhs)); |
| 3954 | } |
| 3955 | return std::move(__lhs.append(__rhs)); |
| 3956 | } |
| 3957 | |
| 3958 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3959 | _GLIBCXX_NODISCARD _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3960 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3961 | operator+(const _CharT* __lhs, |
| 3962 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
| 3963 | { return std::move(__rhs.insert(0, __lhs)); } |
| 3964 | |
| 3965 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3966 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3967 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3968 | operator+(_CharT __lhs, |
| 3969 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
| 3970 | { return std::move(__rhs.insert(0, 1, __lhs)); } |
| 3971 | |
| 3972 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3973 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3974 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3975 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
| 3976 | const _CharT* __rhs) |
| 3977 | { return std::move(__lhs.append(__rhs)); } |
| 3978 | |
| 3979 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3980 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 3981 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3982 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
| 3983 | _CharT __rhs) |
| 3984 | { return std::move(__lhs.append(1, __rhs)); } |
| 3985 | #endif |
| 3986 | |
| 3987 | #if __glibcxx_string_view >= 202403L |
| 3988 | |
| 3989 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3990 | [[nodiscard]] |
| 3991 | constexpr basic_string<_CharT, _Traits, _Alloc> |
| 3992 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 3993 | type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) |
| 3994 | { |
| 3995 | using _Str = basic_string<_CharT, _Traits, _Alloc>; |
| 3996 | return std::__str_concat<_Str>(__lhs.data(), __lhs.size(), |
| 3997 | __rhs.data(), __rhs.size(), |
| 3998 | __lhs.get_allocator()); |
| 3999 | } |
| 4000 | |
| 4001 | |
| 4002 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4003 | [[nodiscard]] |
| 4004 | constexpr basic_string<_CharT, _Traits, _Alloc> |
| 4005 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
| 4006 | type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) |
| 4007 | { |
| 4008 | return std::move(__lhs.append(__rhs)); |
| 4009 | } |
| 4010 | |
| 4011 | |
| 4012 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4013 | [[nodiscard]] |
| 4014 | constexpr basic_string<_CharT, _Traits, _Alloc> |
| 4015 | operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs, |
| 4016 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4017 | { |
| 4018 | using _Str = basic_string<_CharT, _Traits, _Alloc>; |
| 4019 | return std::__str_concat<_Str>(__lhs.data(), __lhs.size(), |
| 4020 | __rhs.data(), __rhs.size(), |
| 4021 | __rhs.get_allocator()); |
| 4022 | } |
| 4023 | |
| 4024 | |
| 4025 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4026 | [[nodiscard]] |
| 4027 | constexpr basic_string<_CharT, _Traits, _Alloc> |
| 4028 | operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs, |
| 4029 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
| 4030 | { |
| 4031 | return std::move(__rhs.insert(0, __lhs)); |
| 4032 | } |
| 4033 | #endif |
| 4034 | |
| 4035 | |
| 4036 | |
| 4037 | |
| 4038 | |
| 4039 | |
| 4040 | |
| 4041 | |
| 4042 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4043 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 4044 | inline bool |
| 4045 | operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4046 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4047 | _GLIBCXX_NOEXCEPT |
| 4048 | { |
| 4049 | return __lhs.size() == __rhs.size() |
| 4050 | && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size()); |
| 4051 | } |
| 4052 | |
| 4053 | |
| 4054 | |
| 4055 | |
| 4056 | |
| 4057 | |
| 4058 | |
| 4059 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4060 | _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR |
| 4061 | inline bool |
| 4062 | operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4063 | const _CharT* __rhs) |
| 4064 | { |
| 4065 | return __lhs.size() == _Traits::length(__rhs) |
| 4066 | && !_Traits::compare(__lhs.data(), __rhs, __lhs.size()); |
| 4067 | } |
| 4068 | |
| 4069 | #if __cpp_lib_three_way_comparison |
| 4070 | |
| 4071 | |
| 4072 | |
| 4073 | |
| 4074 | |
| 4075 | |
| 4076 | |
| 4077 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4078 | [[nodiscard]] |
| 4079 | constexpr auto |
| 4080 | operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4081 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) noexcept |
| 4082 | -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0)) |
| 4083 | { return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); } |
| 4084 | |
| 4085 | |
| 4086 | |
| 4087 | |
| 4088 | |
| 4089 | |
| 4090 | |
| 4091 | |
| 4092 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4093 | [[nodiscard]] |
| 4094 | constexpr auto |
| 4095 | operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4096 | const _CharT* __rhs) noexcept |
| 4097 | -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0)) |
| 4098 | { return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); } |
| 4099 | #else |
| 4100 | |
| 4101 | |
| 4102 | |
| 4103 | |
| 4104 | |
| 4105 | |
| 4106 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4107 | _GLIBCXX_NODISCARD |
| 4108 | inline bool |
| 4109 | operator==(const _CharT* __lhs, |
| 4110 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4111 | { return __rhs == __lhs; } |
| 4112 | |
| 4113 | |
| 4114 | |
| 4115 | |
| 4116 | |
| 4117 | |
| 4118 | |
| 4119 | |
| 4120 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4121 | _GLIBCXX_NODISCARD |
| 4122 | inline bool |
| 4123 | operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4124 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4125 | _GLIBCXX_NOEXCEPT |
| 4126 | { return !(__lhs == __rhs); } |
| 4127 | |
| 4128 | |
| 4129 | |
| 4130 | |
| 4131 | |
| 4132 | |
| 4133 | |
| 4134 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4135 | _GLIBCXX_NODISCARD |
| 4136 | inline bool |
| 4137 | operator!=(const _CharT* __lhs, |
| 4138 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4139 | { return !(__rhs == __lhs); } |
| 4140 | |
| 4141 | |
| 4142 | |
| 4143 | |
| 4144 | |
| 4145 | |
| 4146 | |
| 4147 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4148 | _GLIBCXX_NODISCARD |
| 4149 | inline bool |
| 4150 | operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4151 | const _CharT* __rhs) |
| 4152 | { return !(__lhs == __rhs); } |
| 4153 | |
| 4154 | |
| 4155 | |
| 4156 | |
| 4157 | |
| 4158 | |
| 4159 | |
| 4160 | |
| 4161 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4162 | _GLIBCXX_NODISCARD |
| 4163 | inline bool |
| 4164 | operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4165 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4166 | _GLIBCXX_NOEXCEPT |
| 4167 | { return __lhs.compare(__rhs) < 0; } |
| 4168 | |
| 4169 | |
| 4170 | |
| 4171 | |
| 4172 | |
| 4173 | |
| 4174 | |
| 4175 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4176 | _GLIBCXX_NODISCARD |
| 4177 | inline bool |
| 4178 | operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4179 | const _CharT* __rhs) |
| 4180 | { return __lhs.compare(__rhs) < 0; } |
| 4181 | |
| 4182 | |
| 4183 | |
| 4184 | |
| 4185 | |
| 4186 | |
| 4187 | |
| 4188 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4189 | _GLIBCXX_NODISCARD |
| 4190 | inline bool |
| 4191 | operator<(const _CharT* __lhs, |
| 4192 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4193 | { return __rhs.compare(__lhs) > 0; } |
| 4194 | |
| 4195 | |
| 4196 | |
| 4197 | |
| 4198 | |
| 4199 | |
| 4200 | |
| 4201 | |
| 4202 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4203 | _GLIBCXX_NODISCARD |
| 4204 | inline bool |
| 4205 | operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4206 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4207 | _GLIBCXX_NOEXCEPT |
| 4208 | { return __lhs.compare(__rhs) > 0; } |
| 4209 | |
| 4210 | |
| 4211 | |
| 4212 | |
| 4213 | |
| 4214 | |
| 4215 | |
| 4216 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4217 | _GLIBCXX_NODISCARD |
| 4218 | inline bool |
| 4219 | operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4220 | const _CharT* __rhs) |
| 4221 | { return __lhs.compare(__rhs) > 0; } |
| 4222 | |
| 4223 | |
| 4224 | |
| 4225 | |
| 4226 | |
| 4227 | |
| 4228 | |
| 4229 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4230 | _GLIBCXX_NODISCARD |
| 4231 | inline bool |
| 4232 | operator>(const _CharT* __lhs, |
| 4233 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4234 | { return __rhs.compare(__lhs) < 0; } |
| 4235 | |
| 4236 | |
| 4237 | |
| 4238 | |
| 4239 | |
| 4240 | |
| 4241 | |
| 4242 | |
| 4243 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4244 | _GLIBCXX_NODISCARD |
| 4245 | inline bool |
| 4246 | operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4247 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4248 | _GLIBCXX_NOEXCEPT |
| 4249 | { return __lhs.compare(__rhs) <= 0; } |
| 4250 | |
| 4251 | |
| 4252 | |
| 4253 | |
| 4254 | |
| 4255 | |
| 4256 | |
| 4257 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4258 | _GLIBCXX_NODISCARD |
| 4259 | inline bool |
| 4260 | operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4261 | const _CharT* __rhs) |
| 4262 | { return __lhs.compare(__rhs) <= 0; } |
| 4263 | |
| 4264 | |
| 4265 | |
| 4266 | |
| 4267 | |
| 4268 | |
| 4269 | |
| 4270 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4271 | _GLIBCXX_NODISCARD |
| 4272 | inline bool |
| 4273 | operator<=(const _CharT* __lhs, |
| 4274 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4275 | { return __rhs.compare(__lhs) >= 0; } |
| 4276 | |
| 4277 | |
| 4278 | |
| 4279 | |
| 4280 | |
| 4281 | |
| 4282 | |
| 4283 | |
| 4284 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4285 | _GLIBCXX_NODISCARD |
| 4286 | inline bool |
| 4287 | operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4288 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4289 | _GLIBCXX_NOEXCEPT |
| 4290 | { return __lhs.compare(__rhs) >= 0; } |
| 4291 | |
| 4292 | |
| 4293 | |
| 4294 | |
| 4295 | |
| 4296 | |
| 4297 | |
| 4298 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4299 | _GLIBCXX_NODISCARD |
| 4300 | inline bool |
| 4301 | operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4302 | const _CharT* __rhs) |
| 4303 | { return __lhs.compare(__rhs) >= 0; } |
| 4304 | |
| 4305 | |
| 4306 | |
| 4307 | |
| 4308 | |
| 4309 | |
| 4310 | |
| 4311 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4312 | _GLIBCXX_NODISCARD |
| 4313 | inline bool |
| 4314 | operator>=(const _CharT* __lhs, |
| 4315 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4316 | { return __rhs.compare(__lhs) <= 0; } |
| 4317 | #endif // three-way comparison |
| 4318 | |
| 4319 | |
| 4320 | |
| 4321 | |
| 4322 | |
| 4323 | |
| 4324 | |
| 4325 | |
| 4326 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4327 | _GLIBCXX20_CONSTEXPR |
| 4328 | inline void |
| 4329 | swap(basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4330 | basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4331 | _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs))) |
| 4332 | { __lhs.swap(__rhs); } |
| 4333 | |
| 4334 | |
| 4335 | |
| 4336 | |
| 4337 | |
| 4338 | |
| 4339 | |
| 4340 | |
| 4341 | |
| 4342 | |
| 4343 | |
| 4344 | |
| 4345 | |
| 4346 | |
| 4347 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4348 | basic_istream<_CharT, _Traits>& |
| 4349 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4350 | basic_string<_CharT, _Traits, _Alloc>& __str); |
| 4351 | |
| 4352 | template<> |
| 4353 | basic_istream<char>& |
| 4354 | operator>>(basic_istream<char>& __is, basic_string<char>& __str); |
| 4355 | |
| 4356 | |
| 4357 | |
| 4358 | |
| 4359 | |
| 4360 | |
| 4361 | |
| 4362 | |
| 4363 | |
| 4364 | |
| 4365 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4366 | inline basic_ostream<_CharT, _Traits>& |
| 4367 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4368 | const basic_string<_CharT, _Traits, _Alloc>& __str) |
| 4369 | { |
| 4370 | |
| 4371 | |
| 4372 | return __ostream_insert(__os, __str.data(), __str.size()); |
| 4373 | } |
| 4374 | |
| 4375 | |
| 4376 | |
| 4377 | |
| 4378 | |
| 4379 | |
| 4380 | |
| 4381 | |
| 4382 | |
| 4383 | |
| 4384 | |
| 4385 | |
| 4386 | |
| 4387 | |
| 4388 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4389 | basic_istream<_CharT, _Traits>& |
| 4390 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4391 | basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim); |
| 4392 | |
| 4393 | |
| 4394 | |
| 4395 | |
| 4396 | |
| 4397 | |
| 4398 | |
| 4399 | |
| 4400 | |
| 4401 | |
| 4402 | |
| 4403 | |
| 4404 | |
| 4405 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4406 | inline basic_istream<_CharT, _Traits>& |
| 4407 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4408 | basic_string<_CharT, _Traits, _Alloc>& __str) |
| 4409 | { return std::getline(__is, __str, __is.widen('\n')); } |
| 4410 | |
| 4411 | #if __cplusplus >= 201103L |
| 4412 | |
| 4413 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4414 | inline basic_istream<_CharT, _Traits>& |
| 4415 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4416 | basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim) |
| 4417 | { return std::getline(__is, __str, __delim); } |
| 4418 | |
| 4419 | |
| 4420 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4421 | inline basic_istream<_CharT, _Traits>& |
| 4422 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4423 | basic_string<_CharT, _Traits, _Alloc>& __str) |
| 4424 | { return std::getline(__is, __str); } |
| 4425 | #endif |
| 4426 | |
| 4427 | template<> |
| 4428 | basic_istream<char>& |
| 4429 | getline(basic_istream<char>& __in, basic_string<char>& __str, |
| 4430 | char __delim); |
| 4431 | |
| 4432 | #ifdef _GLIBCXX_USE_WCHAR_T |
| 4433 | template<> |
| 4434 | basic_istream<wchar_t>& |
| 4435 | getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str, |
| 4436 | wchar_t __delim); |
| 4437 | #endif |
| 4438 | |
| 4439 | _GLIBCXX_END_NAMESPACE_VERSION |
| 4440 | } |
| 4441 | |
| 4442 | #if __cplusplus >= 201103L |
| 4443 | |
| 4444 | #include <ext/string_conversions.h> |
| 4445 | #include <bits/charconv.h> |
| 4446 | |
| 4447 | namespace std _GLIBCXX_VISIBILITY(default) |
| 4448 | { |
| 4449 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 4450 | _GLIBCXX_BEGIN_NAMESPACE_CXX11 |
| 4451 | |
| 4452 | |
| 4453 | inline int |
| 4454 | stoi(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4455 | { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(), |
| 4456 | __idx, __base); } |
| 4457 | |
| 4458 | inline long |
| 4459 | stol(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4460 | { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), |
| 4461 | __idx, __base); } |
| 4462 | |
| 4463 | inline unsigned long |
| 4464 | stoul(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4465 | { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), |
| 4466 | __idx, __base); } |
| 4467 | |
| 4468 | #if _GLIBCXX_USE_C99_STDLIB |
| 4469 | inline long long |
| 4470 | stoll(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4471 | { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), |
| 4472 | __idx, __base); } |
| 4473 | |
| 4474 | inline unsigned long long |
| 4475 | stoull(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4476 | { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), |
| 4477 | __idx, __base); } |
| 4478 | #elif __LONG_WIDTH__ == __LONG_LONG_WIDTH__ |
| 4479 | inline long long |
| 4480 | stoll(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4481 | { return std::stol(__str, __idx, __base); } |
| 4482 | |
| 4483 | inline unsigned long long |
| 4484 | stoull(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4485 | { return std::stoul(__str, __idx, __base); } |
| 4486 | #endif |
| 4487 | |
| 4488 | inline double |
| 4489 | stod(const string& __str, size_t* __idx = 0) |
| 4490 | { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } |
| 4491 | |
| 4492 | #if _GLIBCXX_HAVE_STRTOF |
| 4493 | |
| 4494 | inline float |
| 4495 | stof(const string& __str, size_t* __idx = 0) |
| 4496 | { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } |
| 4497 | #else |
| 4498 | inline float |
| 4499 | stof(const string& __str, size_t* __idx = 0) |
| 4500 | { |
| 4501 | double __d = std::stod(__str, __idx); |
| 4502 | if (__builtin_isfinite(__d) && __d != 0.0) |
| 4503 | { |
| 4504 | double __abs_d = __builtin_fabs(__d); |
| 4505 | if (__abs_d < __FLT_MIN__ || __abs_d > __FLT_MAX__) |
| 4506 | { |
| 4507 | errno = ERANGE; |
| 4508 | std::__throw_out_of_range("stof"); |
| 4509 | } |
| 4510 | } |
| 4511 | return __d; |
| 4512 | } |
| 4513 | #endif |
| 4514 | |
| 4515 | #if _GLIBCXX_HAVE_STRTOLD && ! _GLIBCXX_HAVE_BROKEN_STRTOLD |
| 4516 | inline long double |
| 4517 | stold(const string& __str, size_t* __idx = 0) |
| 4518 | { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } |
| 4519 | #elif __DBL_MANT_DIG__ == __LDBL_MANT_DIG__ |
| 4520 | inline long double |
| 4521 | stold(const string& __str, size_t* __idx = 0) |
| 4522 | { return std::stod(__str, __idx); } |
| 4523 | #endif |
| 4524 | |
| 4525 | |
| 4526 | |
| 4527 | |
| 4528 | _GLIBCXX_NODISCARD |
| 4529 | inline string |
| 4530 | to_string(int __val) |
| 4531 | #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32 |
| 4532 | noexcept |
| 4533 | #endif |
| 4534 | { |
| 4535 | const bool __neg = __val < 0; |
| 4536 | const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val; |
| 4537 | const auto __len = __detail::__to_chars_len(__uval); |
| 4538 | string __str; |
| 4539 | __str.__resize_and_overwrite(__neg + __len, [=](char* __p, size_t __n) { |
| 4540 | __p[0] = '-'; |
| 4541 | __detail::__to_chars_10_impl(__p + (int)__neg, __len, __uval); |
| 4542 | return __n; |
| 4543 | }); |
| 4544 | return __str; |
| 4545 | } |
| 4546 | |
| 4547 | _GLIBCXX_NODISCARD |
| 4548 | inline string |
| 4549 | to_string(unsigned __val) |
| 4550 | #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_INT__) <= 32 |
| 4551 | noexcept |
| 4552 | #endif |
| 4553 | { |
| 4554 | const auto __len = __detail::__to_chars_len(__val); |
| 4555 | string __str; |
| 4556 | __str.__resize_and_overwrite(__len, [__val](char* __p, size_t __n) { |
| 4557 | __detail::__to_chars_10_impl(__p, __n, __val); |
| 4558 | return __n; |
| 4559 | }); |
| 4560 | return __str; |
| 4561 | } |
| 4562 | |
| 4563 | _GLIBCXX_NODISCARD |
| 4564 | inline string |
| 4565 | to_string(long __val) |
| 4566 | #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32 |
| 4567 | noexcept |
| 4568 | #endif |
| 4569 | { |
| 4570 | const bool __neg = __val < 0; |
| 4571 | const unsigned long __uval = __neg ? (unsigned long)~__val + 1ul : __val; |
| 4572 | const auto __len = __detail::__to_chars_len(__uval); |
| 4573 | string __str; |
| 4574 | __str.__resize_and_overwrite(__neg + __len, [=](char* __p, size_t __n) { |
| 4575 | __p[0] = '-'; |
| 4576 | __detail::__to_chars_10_impl(__p + (int)__neg, __len, __uval); |
| 4577 | return __n; |
| 4578 | }); |
| 4579 | return __str; |
| 4580 | } |
| 4581 | |
| 4582 | _GLIBCXX_NODISCARD |
| 4583 | inline string |
| 4584 | to_string(unsigned long __val) |
| 4585 | #if _GLIBCXX_USE_CXX11_ABI && (__CHAR_BIT__ * __SIZEOF_LONG__) <= 32 |
| 4586 | noexcept |
| 4587 | #endif |
| 4588 | { |
| 4589 | const auto __len = __detail::__to_chars_len(__val); |
| 4590 | string __str; |
| 4591 | __str.__resize_and_overwrite(__len, [__val](char* __p, size_t __n) { |
| 4592 | __detail::__to_chars_10_impl(__p, __n, __val); |
| 4593 | return __n; |
| 4594 | }); |
| 4595 | return __str; |
| 4596 | } |
| 4597 | |
| 4598 | _GLIBCXX_NODISCARD |
| 4599 | inline string |
| 4600 | to_string(long long __val) |
| 4601 | { |
| 4602 | const bool __neg = __val < 0; |
| 4603 | const unsigned long long __uval |
| 4604 | = __neg ? (unsigned long long)~__val + 1ull : __val; |
| 4605 | const auto __len = __detail::__to_chars_len(__uval); |
| 4606 | string __str; |
| 4607 | __str.__resize_and_overwrite(__neg + __len, [=](char* __p, size_t __n) { |
| 4608 | __p[0] = '-'; |
| 4609 | __detail::__to_chars_10_impl(__p + (int)__neg, __len, __uval); |
| 4610 | return __n; |
| 4611 | }); |
| 4612 | return __str; |
| 4613 | } |
| 4614 | |
| 4615 | _GLIBCXX_NODISCARD |
| 4616 | inline string |
| 4617 | to_string(unsigned long long __val) |
| 4618 | { |
| 4619 | const auto __len = __detail::__to_chars_len(__val); |
| 4620 | string __str; |
| 4621 | __str.__resize_and_overwrite(__len, [__val](char* __p, size_t __n) { |
| 4622 | __detail::__to_chars_10_impl(__p, __n, __val); |
| 4623 | return __n; |
| 4624 | }); |
| 4625 | return __str; |
| 4626 | } |
| 4627 | |
| 4628 | #if __glibcxx_to_string >= 202306L // C++ >= 26 |
| 4629 | |
| 4630 | [[nodiscard]] |
| 4631 | inline string |
| 4632 | to_string(float __val) |
| 4633 | { |
| 4634 | string __str; |
| 4635 | size_t __len = 15; |
| 4636 | do { |
| 4637 | __str.resize_and_overwrite(__len, |
| 4638 | [__val, &__len] (char* __p, size_t __n) { |
| 4639 | auto [__end, __err] = std::to_chars(__p, __p + __n, __val); |
| 4640 | if (__err == errc{}) [[likely]] |
| 4641 | return __end - __p; |
| 4642 | __len *= 2; |
| 4643 | return __p - __p;; |
| 4644 | }); |
| 4645 | } while (__str.empty()); |
| 4646 | return __str; |
| 4647 | } |
| 4648 | |
| 4649 | [[nodiscard]] |
| 4650 | inline string |
| 4651 | to_string(double __val) |
| 4652 | { |
| 4653 | string __str; |
| 4654 | size_t __len = 15; |
| 4655 | do { |
| 4656 | __str.resize_and_overwrite(__len, |
| 4657 | [__val, &__len] (char* __p, size_t __n) { |
| 4658 | auto [__end, __err] = std::to_chars(__p, __p + __n, __val); |
| 4659 | if (__err == errc{}) [[likely]] |
| 4660 | return __end - __p; |
| 4661 | __len *= 2; |
| 4662 | return __p - __p;; |
| 4663 | }); |
| 4664 | } while (__str.empty()); |
| 4665 | return __str; |
| 4666 | } |
| 4667 | |
| 4668 | [[nodiscard]] |
| 4669 | inline string |
| 4670 | to_string(long double __val) |
| 4671 | { |
| 4672 | string __str; |
| 4673 | size_t __len = 15; |
| 4674 | do { |
| 4675 | __str.resize_and_overwrite(__len, |
| 4676 | [__val, &__len] (char* __p, size_t __n) { |
| 4677 | auto [__end, __err] = std::to_chars(__p, __p + __n, __val); |
| 4678 | if (__err == errc{}) [[likely]] |
| 4679 | return __end - __p; |
| 4680 | __len *= 2; |
| 4681 | return __p - __p;; |
| 4682 | }); |
| 4683 | } while (__str.empty()); |
| 4684 | return __str; |
| 4685 | } |
| 4686 | #elif _GLIBCXX_USE_C99_STDIO |
| 4687 | #pragma GCC diagnostic push |
| 4688 | #pragma GCC diagnostic ignored "-Wsuggest-attribute=format" |
| 4689 | |
| 4690 | |
| 4691 | _GLIBCXX_NODISCARD |
| 4692 | inline string |
| 4693 | to_string(float __val) |
| 4694 | { |
| 4695 | const int __n = |
| 4696 | __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20; |
| 4697 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
| 4698 | "%f", __val); |
| 4699 | } |
| 4700 | |
| 4701 | _GLIBCXX_NODISCARD |
| 4702 | inline string |
| 4703 | to_string(double __val) |
| 4704 | { |
| 4705 | const int __n = |
| 4706 | __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20; |
| 4707 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
| 4708 | "%f", __val); |
| 4709 | } |
| 4710 | |
| 4711 | _GLIBCXX_NODISCARD |
| 4712 | inline string |
| 4713 | to_string(long double __val) |
| 4714 | { |
| 4715 | const int __n = |
| 4716 | __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20; |
| 4717 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
| 4718 | "%Lf", __val); |
| 4719 | } |
| 4720 | #pragma GCC diagnostic pop |
| 4721 | #endif // _GLIBCXX_USE_C99_STDIO |
| 4722 | |
| 4723 | #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR |
| 4724 | inline int |
| 4725 | stoi(const wstring& __str, size_t* __idx = 0, int __base = 10) |
| 4726 | { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(), |
| 4727 | __idx, __base); } |
| 4728 | |
| 4729 | inline long |
| 4730 | stol(const wstring& __str, size_t* __idx = 0, int __base = 10) |
| 4731 | { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), |
| 4732 | __idx, __base); } |
| 4733 | |
| 4734 | inline unsigned long |
| 4735 | stoul(const wstring& __str, size_t* __idx = 0, int __base = 10) |
| 4736 | { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), |
| 4737 | __idx, __base); } |
| 4738 | |
| 4739 | inline long long |
| 4740 | stoll(const wstring& __str, size_t* __idx = 0, int __base = 10) |
| 4741 | { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), |
| 4742 | __idx, __base); } |
| 4743 | |
| 4744 | inline unsigned long long |
| 4745 | stoull(const wstring& __str, size_t* __idx = 0, int __base = 10) |
| 4746 | { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), |
| 4747 | __idx, __base); } |
| 4748 | |
| 4749 | |
| 4750 | inline float |
| 4751 | stof(const wstring& __str, size_t* __idx = 0) |
| 4752 | { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } |
| 4753 | |
| 4754 | inline double |
| 4755 | stod(const wstring& __str, size_t* __idx = 0) |
| 4756 | { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } |
| 4757 | |
| 4758 | inline long double |
| 4759 | stold(const wstring& __str, size_t* __idx = 0) |
| 4760 | { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } |
| 4761 | #endif |
| 4762 | |
| 4763 | #ifdef _GLIBCXX_USE_WCHAR_T |
| 4764 | #pragma GCC diagnostic push |
| 4765 | #pragma GCC diagnostic ignored "-Wc++17-extensions" |
| 4766 | _GLIBCXX20_CONSTEXPR |
| 4767 | inline void |
| 4768 | __to_wstring_numeric(const char* __s, int __len, wchar_t* __wout) |
| 4769 | { |
| 4770 | |
| 4771 | |
| 4772 | if constexpr (wchar_t('0') == L'0' && wchar_t('-') == L'-' |
| 4773 | && wchar_t('.') == L'.' && wchar_t('e') == L'e') |
| 4774 | { |
| 4775 | for (int __i = 0; __i < __len; ++__i) |
| 4776 | __wout[__i] = (wchar_t) __s[__i]; |
| 4777 | } |
| 4778 | else |
| 4779 | { |
| 4780 | wchar_t __wc[256]; |
| 4781 | for (int __i = '0'; __i <= '9'; ++__i) |
| 4782 | __wc[__i] = L'0' + __i; |
| 4783 | __wc['.'] = L'.'; |
| 4784 | __wc['+'] = L'+'; |
| 4785 | __wc['-'] = L'-'; |
| 4786 | __wc['a'] = L'a'; |
| 4787 | __wc['b'] = L'b'; |
| 4788 | __wc['c'] = L'c'; |
| 4789 | __wc['d'] = L'd'; |
| 4790 | __wc['e'] = L'e'; |
| 4791 | __wc['f'] = L'f'; |
| 4792 | __wc['i'] = L'i'; |
| 4793 | __wc['n'] = L'n'; |
| 4794 | __wc['p'] = L'p'; |
| 4795 | __wc['x'] = L'x'; |
| 4796 | __wc['A'] = L'A'; |
| 4797 | __wc['B'] = L'B'; |
| 4798 | __wc['C'] = L'C'; |
| 4799 | __wc['D'] = L'D'; |
| 4800 | __wc['E'] = L'E'; |
| 4801 | __wc['F'] = L'F'; |
| 4802 | __wc['I'] = L'I'; |
| 4803 | __wc['N'] = L'N'; |
| 4804 | __wc['P'] = L'P'; |
| 4805 | __wc['X'] = L'X'; |
| 4806 | |
| 4807 | for (int __i = 0; __i < __len; ++__i) |
| 4808 | __wout[__i] = __wc[(int)__s[__i]]; |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | #if __glibcxx_constexpr_string >= 201907L |
| 4813 | constexpr |
| 4814 | #endif |
| 4815 | inline wstring |
| 4816 | #ifdef __glibcxx_string_view // >= C++17 |
| 4817 | __to_wstring_numeric(string_view __s) |
| 4818 | #else |
| 4819 | __to_wstring_numeric(const string& __s) |
| 4820 | #endif |
| 4821 | { |
| 4822 | if constexpr (wchar_t('0') == L'0' && wchar_t('-') == L'-' |
| 4823 | && wchar_t('.') == L'.' && wchar_t('e') == L'e') |
| 4824 | return wstring(__s.data(), __s.data() + __s.size()); |
| 4825 | else |
| 4826 | { |
| 4827 | wstring __ws; |
| 4828 | auto __f = __s.data(); |
| 4829 | __ws.__resize_and_overwrite(__s.size(), |
| 4830 | [__f] (wchar_t* __to, int __n) { |
| 4831 | std::__to_wstring_numeric(__f, __n, __to); |
| 4832 | return __n; |
| 4833 | }); |
| 4834 | return __ws; |
| 4835 | } |
| 4836 | } |
| 4837 | #pragma GCC diagnostic pop |
| 4838 | |
| 4839 | _GLIBCXX_NODISCARD |
| 4840 | inline wstring |
| 4841 | to_wstring(int __val) |
| 4842 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4843 | |
| 4844 | _GLIBCXX_NODISCARD |
| 4845 | inline wstring |
| 4846 | to_wstring(unsigned __val) |
| 4847 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4848 | |
| 4849 | _GLIBCXX_NODISCARD |
| 4850 | inline wstring |
| 4851 | to_wstring(long __val) |
| 4852 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4853 | |
| 4854 | _GLIBCXX_NODISCARD |
| 4855 | inline wstring |
| 4856 | to_wstring(unsigned long __val) |
| 4857 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4858 | |
| 4859 | _GLIBCXX_NODISCARD |
| 4860 | inline wstring |
| 4861 | to_wstring(long long __val) |
| 4862 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4863 | |
| 4864 | _GLIBCXX_NODISCARD |
| 4865 | inline wstring |
| 4866 | to_wstring(unsigned long long __val) |
| 4867 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4868 | |
| 4869 | #if __glibcxx_to_string || _GLIBCXX_USE_C99_STDIO |
| 4870 | _GLIBCXX_NODISCARD |
| 4871 | inline wstring |
| 4872 | to_wstring(float __val) |
| 4873 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4874 | |
| 4875 | _GLIBCXX_NODISCARD |
| 4876 | inline wstring |
| 4877 | to_wstring(double __val) |
| 4878 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4879 | |
| 4880 | _GLIBCXX_NODISCARD |
| 4881 | inline wstring |
| 4882 | to_wstring(long double __val) |
| 4883 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4884 | #endif |
| 4885 | #endif // _GLIBCXX_USE_WCHAR_T |
| 4886 | |
| 4887 | _GLIBCXX_END_NAMESPACE_CXX11 |
| 4888 | _GLIBCXX_END_NAMESPACE_VERSION |
| 4889 | } |
| 4890 | |
| 4891 | #endif /* C++11 */ |
| 4892 | |
| 4893 | #if __cplusplus >= 201103L |
| 4894 | |
| 4895 | #include <bits/functional_hash.h> |
| 4896 | |
| 4897 | namespace std _GLIBCXX_VISIBILITY(default) |
| 4898 | { |
| 4899 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 4900 | |
| 4901 | |
| 4902 | |
| 4903 | |
| 4904 | template<typename _CharT, typename _Alloc, |
| 4905 | typename _StrT = basic_string<_CharT, char_traits<_CharT>, _Alloc>> |
| 4906 | struct __str_hash_base |
| 4907 | : public __hash_base<size_t, _StrT> |
| 4908 | { |
| 4909 | [[__nodiscard__]] |
| 4910 | size_t |
| 4911 | operator()(const _StrT& __s) const noexcept |
| 4912 | { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(_CharT)); } |
| 4913 | }; |
| 4914 | |
| 4915 | #ifndef _GLIBCXX_COMPATIBILITY_CXX0X |
| 4916 | |
| 4917 | template<typename _Alloc> |
| 4918 | struct hash<basic_string<char, char_traits<char>, _Alloc>> |
| 4919 | : public __str_hash_base<char, _Alloc> |
| 4920 | { }; |
| 4921 | |
| 4922 | |
| 4923 | template<typename _Alloc> |
| 4924 | struct hash<basic_string<wchar_t, char_traits<wchar_t>, _Alloc>> |
| 4925 | : public __str_hash_base<wchar_t, _Alloc> |
| 4926 | { }; |
| 4927 | |
| 4928 | template<typename _Alloc> |
| 4929 | struct __is_fast_hash<hash<basic_string<wchar_t, char_traits<wchar_t>, |
| 4930 | _Alloc>>> |
| 4931 | : std::false_type |
| 4932 | { }; |
| 4933 | #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */ |
| 4934 | |
| 4935 | #ifdef _GLIBCXX_USE_CHAR8_T |
| 4936 | |
| 4937 | template<typename _Alloc> |
| 4938 | struct hash<basic_string<char8_t, char_traits<char8_t>, _Alloc>> |
| 4939 | : public __str_hash_base<char8_t, _Alloc> |
| 4940 | { }; |
| 4941 | #endif |
| 4942 | |
| 4943 | |
| 4944 | template<typename _Alloc> |
| 4945 | struct hash<basic_string<char16_t, char_traits<char16_t>, _Alloc>> |
| 4946 | : public __str_hash_base<char16_t, _Alloc> |
| 4947 | { }; |
| 4948 | |
| 4949 | |
| 4950 | template<typename _Alloc> |
| 4951 | struct hash<basic_string<char32_t, char_traits<char32_t>, _Alloc>> |
| 4952 | : public __str_hash_base<char32_t, _Alloc> |
| 4953 | { }; |
| 4954 | |
| 4955 | #if ! _GLIBCXX_INLINE_VERSION |
| 4956 | |
| 4957 | template<> struct __is_fast_hash<hash<string>> : std::false_type { }; |
| 4958 | template<> struct __is_fast_hash<hash<wstring>> : std::false_type { }; |
| 4959 | template<> struct __is_fast_hash<hash<u16string>> : std::false_type { }; |
| 4960 | template<> struct __is_fast_hash<hash<u32string>> : std::false_type { }; |
| 4961 | #ifdef _GLIBCXX_USE_CHAR8_T |
| 4962 | template<> struct __is_fast_hash<hash<u8string>> : std::false_type { }; |
| 4963 | #endif |
| 4964 | #else |
| 4965 | |
| 4966 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4967 | struct __is_fast_hash<hash<basic_string<_CharT, _Traits, _Alloc>>> |
| 4968 | : std::false_type |
| 4969 | { }; |
| 4970 | #endif |
| 4971 | |
| 4972 | #ifdef __glibcxx_string_udls // C++ >= 14 |
| 4973 | inline namespace literals |
| 4974 | { |
| 4975 | inline namespace string_literals |
| 4976 | { |
| 4977 | #pragma GCC diagnostic push |
| 4978 | #pragma GCC diagnostic ignored "-Wliteral-suffix" |
| 4979 | |
| 4980 | #if __glibcxx_constexpr_string >= 201907L |
| 4981 | # define _GLIBCXX_STRING_CONSTEXPR constexpr |
| 4982 | #else |
| 4983 | # define _GLIBCXX_STRING_CONSTEXPR |
| 4984 | #endif |
| 4985 | |
| 4986 | _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR |
| 4987 | inline basic_string<char> |
| 4988 | operator""s(const char* __str, size_t __len) |
| 4989 | { return basic_string<char>{__str, __len}; } |
| 4990 | |
| 4991 | _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR |
| 4992 | inline basic_string<wchar_t> |
| 4993 | operator""s(const wchar_t* __str, size_t __len) |
| 4994 | { return basic_string<wchar_t>{__str, __len}; } |
| 4995 | |
| 4996 | #ifdef _GLIBCXX_USE_CHAR8_T |
| 4997 | _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR |
| 4998 | inline basic_string<char8_t> |
| 4999 | operator""s(const char8_t* __str, size_t __len) |
| 5000 | { return basic_string<char8_t>{__str, __len}; } |
| 5001 | #endif |
| 5002 | |
| 5003 | _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR |
| 5004 | inline basic_string<char16_t> |
| 5005 | operator""s(const char16_t* __str, size_t __len) |
| 5006 | { return basic_string<char16_t>{__str, __len}; } |
| 5007 | |
| 5008 | _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR |
| 5009 | inline basic_string<char32_t> |
| 5010 | operator""s(const char32_t* __str, size_t __len) |
| 5011 | { return basic_string<char32_t>{__str, __len}; } |
| 5012 | |
| 5013 | #undef _GLIBCXX_STRING_CONSTEXPR |
| 5014 | #pragma GCC diagnostic pop |
| 5015 | } |
| 5016 | } |
| 5017 | #endif // __glibcxx_string_udls |
| 5018 | |
| 5019 | #ifdef __glibcxx_variant // >= C++17 |
| 5020 | namespace __detail::__variant |
| 5021 | { |
| 5022 | template<typename> struct _Never_valueless_alt; |
| 5023 | |
| 5024 | |
| 5025 | |
| 5026 | template<typename _Tp, typename _Traits, typename _Alloc> |
| 5027 | struct _Never_valueless_alt<std::basic_string<_Tp, _Traits, _Alloc>> |
| 5028 | : __and_< |
| 5029 | is_nothrow_move_constructible<std::basic_string<_Tp, _Traits, _Alloc>>, |
| 5030 | is_nothrow_move_assignable<std::basic_string<_Tp, _Traits, _Alloc>> |
| 5031 | >::type |
| 5032 | { }; |
| 5033 | } |
| 5034 | #endif // C++17 |
| 5035 | |
| 5036 | _GLIBCXX_END_NAMESPACE_VERSION |
| 5037 | } |
| 5038 | |
| 5039 | #endif // C++11 |
| 5040 | |
| 5041 | #endif /* _BASIC_STRING_H */ |