Is it possible to adapt the c-style string / buffer ( char* or wchar_t* ) in some way to work with the Library of string acceleration algorithms ?
That is, for example, the trim algorithm has the following declaration:
template<typename SequenceT> void trim(SequenceT &, const std::locale & = std::locale());
and the implementation (search trim_left_if ) requires the sequence type to have an erase member erase .
How can I use this with the raw character pointer buffer / c?
char* pStr = getSomeCString();
Ideally, the algorithms will work directly on the supplied buffer. (As far as possible, it obviously cannot work if the algorithm needs to allocate additional space in the "row".)
@Vitaly asks: why can't you create a std :: string buffer from char and then use it in algorithms?
The reason I have a char * is because I would like to use several algorithms on our existing code base. Refactoring all char buffers into a string will be more work than it costs, and when changing or adapting something, it would be nice to just apply this algorithm to any c-style string that lives in the current code.
Using a string would mean: (a) copy the char * to the string, (b) apply the algorithm to the string, and (c) copy the string back to the char buffer.
Martin ba
source share