3 ms·
Also I don't think the Standard requires that data() returns a valid pointer after only calling reserve(), so it's technically UB.
by gary_0 3y ago
Also I don't think the Standard requires that data() returns a valid pointer after only calling reserve(), so it's technically UB.
- zabzonk 3y agoi think you may have misunderstood the standard - data() will always return a valid pointer, but the pointer returned may be invalidated by any number of functions: string s; s.reserve(50); char * p = s.data(); // ok so far s.reserve(100); // now p may be invalid