I want to pass a string with string.reserve(1000) and ensure that memory is allocated when I pass it into different structs. Is there a way to do this without explicitly doing it after every instantiation?
I want to avoid having to do this:
struct Prefix{
std::string path;
};
int main() {
std::string path = "hel";
path.reserve(1000);
std::cout << path.capacity() << "\n"; // 1000
Prefix x = {path};
std::cout << x.path.capacity() << "\n"; // 15
x.path.reserve(1000);
x.path += somestring;
Prefix y = {x.path};
std::cout << y.path.capacity() << "\n"; // 15
y.reserve(1000);
}