Subject: Re: [boost] [ Interest? ] [ out_ptr ] Tiny C++ Abstraction for C-Style Output Pointers
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2018-07-04 02:17:50
On 4/07/2018 13:48, ThePhD wrote:
> I am not sure whether this provides much more benefit than just
> passing the smart pointer itself: the `some_function` already sticks
> `SmartPtr` in its signature (so you might as well just pass the SmartPtr
> itself, since you've already nailed the smart pointer to the signature).
The benefit is, as I said, in making it obvious at the call-site that
the pointer can be modified. The alternative is:
auto r = some_function(foo, bar, /*out*/ my_smart_ptr);
bool some_function(int foo, int bar, SmartPtr& local_smart_ptr);
Where obviously the comment is trying to be an annotation, but as it's
just a comment it has no real effect and is easily forgotten and then
there is no evidence at all (at the call site) that my_smart_ptr can be
modified by the call.
It's not really a pointer-specific issue, it's just a flaw in C++'s
reference-passing syntax in general. Some other languages handle this
better by being more explicit about the purpose of a reference parameter.
So it would be nice if there were a way to have a compiler-enforced
annotation, as long as it doesn't have negative performance impact.
As I said, this is not really in-scope for what you're trying to do with
your library, but it's a related problem space and it would be nice if
one solution could solve both problems uniformly.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk