3 ms·
wouldn't it be more in C++11 manner to use move semantics to solve the problem of generating new strings on concatenation?
by polskibus 13y ago
wouldn't it be more in C++11 manner to use move semantics to solve the problem of generating new strings on concatenation?
- zaphoyd 13y agoMove wouldn't actually help in this case. Move works by letting a wrapper object (like a string or vector) that manages a pointer to some dynamically allocated storage take over the pointer of the object being moved rather than allocating new storage, copying data, then freeing the old storage. In the case of concatenation, where the goal is to end up with a contiguous array of the characters from the strings to be joined, no block of memory sufficiently large exists anywhere to be appropriated, so new memory must be allocated.