Hi Eugene,
--- "Alterman, Eugene" <Eugene.Alterman@Staples.com> wrote:
> I think it is better to have (mutable_/const_)buffer_conteiner_1
> derived
> from boost::array<..._buffer, 1>. Then the only thing you need to do
> is to
> add construction from a buffer:
>
> class mutable_buffer_container_1
> : public boost::array<mutable_buffer, 1>
> {
> public:
> /// Construct to represent a single modifiable buffer.
> explicit mutable_buffer_container_1(const mutable_buffer& b)
> {
> *begin() = b;
> }
> };
The problem was that I also wanted the return value of asio::buffer()
to be assignable directly into a const_buffer or mutable_buffer, e.g.:
asio::const_buffer b = asio::buffer(data, size);
or
asio::mutable_buffer b = asio::buffer(data, size);
Furthermore, in the case of asio::buffer() returning a
mutable_buffer_container_1, I want the "conversion" to mutable_buffer
to be a better conversion than to const_buffer.
Otherwise you get ambiguities with code like:
void foo(const mutable_buffer&);
void foo(const const_buffer&);
char data[1024];
foo(asio::buffer(data));
Using the inheritance here was the only way I could find to make this
the "better" conversion. I'd be happy to know about alternative ways of
doing it.
> Aside from more code, there is another problem with the current
> approach -
> 'end()' is defined as 'begin() + 1', but you can use pointer
> arithmetic
> legally only within an array.
According to the C++ standard, in section 5.7/4 which discusses pointer
arithmetic:
"For the purposes of these operators, a pointer to a nonarray object
behaves the same as a pointer to the first element of an aray of length
one with the type of the object as its element type."
which i took to mean it was legal. I could be wrong though :)
Cheers,
Chris
|