Subject: Re: [boost] [ Interest? ] [ out_ptr ] Tiny C++ Abstraction for C-Style Output Pointers
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2018-07-03 23:21:31
On 4/07/2018 01:04, ThePhD wrote:
> In the proposal linked as part the P.S., that's actually one of the
> names listed. It was also recommended by another person outside this list,
> so I will keep that in mind going forward (the pair of names was
> `c_out_ptr` and `c_inout_ptr`)!
> This library is not explicitly an annotation, but it also doubles as
> that by its design: the free function makes it very noticeable that this
> parameter is an output parameter.
I guess my question is whether it could be used as a within-C++
annotation as well, eg:
auto r = some_function(foo, bar, out_ptr(my_smart_ptr));
bool some_function(int foo, int bar, out_ptr<SmartPtr> local_smart_ptr)
local_smart_ptr = x;
where the out_ptr itself is received by value (cheap to copy or move
since it just contains a reference to the actual smart pointer), but
offers a way to alter the value of my_smart_ptr through modification of
local_smart_ptr -- as close as possible to the behaviour of the argument
being type SmartPtr&, but requiring the explicit annotation at the call
site rather than being invisible.
While serving both roles obviously can't be a requirement (I'm not sure
if it's even possible), if this can be done then it would truly be
deserving of a generic name like "out_ptr".