Would this be the best approach?

It gives me the shivers. Binary data could easily have a zero in the last byte.

Wouldn't it be more explicit to simply provide an overload for boost::utility::string_view and std::string_view?


On 28 November 2017 at 08:43, Martijn Otto via Boost-users <boost-users@lists.boost.org> wrote:
When using boost::asio::buffer with a string literal the terminating
null character is included in the buffer size, leading to bugs like
accidentally sending out a null character. We could fix this by adding
something like this to buffer.hpp:

/// Create a new non-modifiable buffer that represents the given
character array.
/**
  * @returns A const_buffer value equivalent to:
  * @code const_buffer(
  *     static_cast<const void*>(data),
  *     (N - 1) * sizeof(char)); @endcode
  */
template <std::size_t N>
inline BOOST_ASIO_CONST_BUFFER buffer(
    const char (&data)[N]) BOOST_ASIO_NOEXCEPT
{
  return BOOST_ASIO_CONST_BUFFER(data, (N - 1) * sizeof(char));
}

But this might cause trouble when using a const char array that is not
null-terminated, since we then basically drop the last character. Would
this be the best approach?
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
https://lists.boost.org/mailman/listinfo.cgi/boost-users