4 ms·
Is the behavior undefined because std::string makes a deep copy of the string? I thought 'Vivian' would be placed in read-only memory and as long as you don't m
by gramakri 7y ago
Is the behavior undefined because std::string makes a deep copy of the string? I thought 'Vivian' would be placed in read-only memory and as long as you don't modify it, you can hold read-only references to it.
- umanwizard 7y agoYes, `std::string` owns its own copy of the string in typical implementations (as does Rust's `String` type). `std::string_view` references that copy. `std::string::clear` destroys it, leaving the `std::string_view` dangling.