title: (How) can I use the Boost String Algorithms Library with c strings (char pointers)?
body: <p>Is it possible to somehow adapt a c-style string/buffer (<code>char*</code> or <code>wchar_t*</code>) to work with the <a href="http://www.boost.org/doc/libs/1_47_0/doc/html/string_algo.html" rel="nofollow noreferrer">Boost String Algorithms Library</a>?</p>
  <p>That is, for example, it's <code>trim</code>algorithm has the following declaration:</p>
  <pre><code>template&lt;typename SequenceT&gt; 
  void trim(SequenceT &amp;, const std::locale &amp; = std::locale());
  </code></pre>
  <p>and <a href="http://www.boost.org/doc/libs/1_47_0/boost/algorithm/string/trim.hpp" rel="nofollow noreferrer">the implementation</a> (look for <code>trim_left_if</code>) requires that the sequence type has a member function <code>erase</code>.</p>
  <p>How could I use that with a raw character pointer / c string buffer?</p>
  <pre><code>char* pStr = getSomeCString(); // example, could also be something like wchar_t buf[256];
  ...
  boost::trim(pStr); // HOW?
  </code></pre>
  <p><strong>Ideally, the algorithms would work directly on the supplied buffer.</strong> (As far as possible. it obviously can't work if an algorithm needs to allocate additional space in the &quot;string&quot;.)</p>
  <hr />
  <p>@Vitaly asks: <em>why can't you create a std::string from char buffer and then use it in algorithms?</em></p>
  <p>The reason I have char* at all is that I'd like to use a few algorthims on our existing codebase. Refactoring all the char buffers to string would be more work than it's worth, and when changing or adapting something it would be nice to just be able to apply a given algorithm to any c-style string that happens to live in the current code.</p>
  <p>Using a string would mean to (a) copy char* to string, (b) apply algorithm to string and (c) copy string back into char buffer.</p>