[asio] Why "const mutable_buffers &" in interfaces?

Hi Just a question asking to clarify the use of "const Mutable_Buffers &mutable_buffers" in the calls to some of the functions, e.g stream_socket::receive(const Mutable_Buffers &buffers, message_flags flags). To me, this is not logical, since I'd expect a receive function to actually modify the stuff I send into it, and the const qualifier doesn't seem to allow this. If it needs to be this way, you might want to explicitly explain this design choice somewhere close to where it is used. Also the reference documentation for asio::mutable_buffer seems to have a copy-paste bug; its detailed description includes "The const_buffer class provides ...", or am I missing something? Mats

Well, the buffer object itself isn't modified, only what it points to. I guess this could use some clarification though. On 12/25/05, Mats Nilsson <mats.nilsson@xware.se> wrote:
Hi
Just a question asking to clarify the use of "const Mutable_Buffers &mutable_buffers" in the calls to some of the functions, e.g stream_socket::receive(const Mutable_Buffers &buffers, message_flags flags).
To me, this is not logical, since I'd expect a receive function to actually modify the stuff I send into it, and the const qualifier doesn't seem to allow this.
If it needs to be this way, you might want to explicitly explain this design choice somewhere close to where it is used.
Also the reference documentation for asio::mutable_buffer seems to have a copy-paste bug; its detailed description includes "The const_buffer class provides ...", or am I missing something?
Mats
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Cory Nelson http://www.int64.org

Hi Mats, --- Mats Nilsson <mats.nilsson@xware.se> wrote:
Just a question asking to clarify the use of "const Mutable_Buffers &mutable_buffers" in the calls to some of the functions, e.g stream_socket::receive(const Mutable_Buffers &buffers, message_flags flags).
To me, this is not logical, since I'd expect a receive function to actually modify the stuff I send into it, and the const qualifier doesn't seem to allow this.
The constness is shallow. In general, the *_buffer classes do as the pairs do. That is, the const_buffer class behaves the same as pair<const void*, size_t>, and mutable_buffer class as pair<void*, size_t>. The buffers parameter is a const& so that temporaries and "heavy" objects (e.g. std::vector<mutable_buffer>) can be passed through efficiently.
If it needs to be this way, you might want to explicitly explain this design choice somewhere close to where it is used.
No problem.
Also the reference documentation for asio::mutable_buffer seems to have a copy-paste bug; its detailed description includes "The const_buffer class provides ...", or am I missing something?
Fixed, thanks. Cheers, Chris
participants (3)
-
Christopher Kohlhoff
-
Cory Nelson
-
Mats Nilsson