I'm trying to read from an asio socket into a std::string without copying. This implementation seems to work but I'm not sure if it is reliable.
string read(int bytes)
{
string str;
str.resize(bytes);
char* buffer = (char*) str.data();
//socket is declared as class member
asio::read(socket,asio::buffer(buffer,bytes));
return str;
}