On Wed, 2019-04-03 at 15:19 +0200, Rabih M wrote:
> Hello,
>
> I am using the latest version of proton cpp 0.27.0.
>
> I have a suggestion for the signature of the messaging handler's
> methods:
> In my opinion, giving the parameters as references is error prone.
> Because
> it gives the user the illusion that he can keep a reference on the
> proton
> object in his handler and that proton is managing the life cycle of
> this
> object which is not the case. In other words, proton is giving a
> reference
> to a temporary variable.
>
> I understand that you would like to optimise the copy but now with
> C++ 11
> we can move the objects.
>
> What do you think?
I think you are mistaken! Passing a reference - merely signals that
there will always be a value here never a null - It doesn't (in my
experience) signal anything about the lifetime of that reference.
Usually things passed into a call are only guaranteed to last for the
duration of the call itself!
In any event you can't keep a reference in any case irrespective of the
passing convention. It seems you think that the following should be
safe:
class Foo {
proton::connection* connection;
...
void on_connection_blah(connection& c) {
connection = &c;
}
}
Huh?
However the following is safe the lifetime of connection will be
extended until the instance of Foo itself is destroyed - if not there
is a bug:
class Foo {
proton::connection connection;
...
void on_connection_blah(connection& c) {
connection = c;
}
}
There would be no advantage to making the signatures
void on_connection_blah(connection)
which would force a copy for every callback. And the signature
void on_connection_blah(connection&&) is just wrong as we are not
passing the ownership of the connection to the callback.
Andrew
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]