title: alternatives to std::string to use with boost::asio
body: <p><code>boost::asio</code>'s various <code>read</code> and <code>write</code> functions and methods accept <code>boost::asio::buffer</code>. According to <a href="http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/reference/buffer.html" rel="nofollow noreferrer">buffer's documentation</a>, a mutable <code>std::string</code> cannot be wrapped in <code>boost::asio::buffer</code>, and thus cannot be used for asio's <code>read</code> functions. This is probably due to the fact that <code>std::string</code> does not allow mutable access to its internal buffer (this was discussed previously <a href="https://stackoverflow.com/questions/2790383/how-to-asynchronously-read-to-stdstring-using-boostasio/2795371#2795371">here</a>).</p>
  
  <p>This is a shame, because <code>std::string</code> is a convenient way to represent mutable buffers of data in C++. Without it, we're either left with POD arrays, <code>boost::array</code> and <code>std::vector&lt;char&gt;</code>. The first two are inconvenient with variable-length messages. <code>std::vector&lt;char&gt;</code> can work, but it's an unnatural way to carry buffers of data around (*)</p>
  
  <p>Questions:</p>
  
  <ol>
  <li>Are there other alternatives to <code>std::string</code> with <code>boost::asio</code> for reading buffers? Am I missing something here?</li>
  <li>I wonder why <code>std::vector&lt;char&gt;</code> <em>is</em> supported in a mutable buffer. Is it because it guarantees its internal buffer is contiguous in memory and allows mutable access to it with <code>&amp;vec[0]</code> ?</li>
  </ol>
  
  <p>Thanks in advance</p>
  
  <hr>
  
  <p>(*) IMHO. Look at <code>protobuf</code> serialization for instance - it offers serialization into <code>std::string</code> but not into <code>std::vector&lt;char&gt;</code>, at least not explicitly.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> I ended up using <code>vector&lt;char&gt;</code> after all. <code>protobuf</code> allows serialization into a <code>vector&lt;char&gt;</code> by means of the <code>SerializeToArray</code> call which takes a pointer (<code>&amp;vec[0]</code> can be passed there). </p>