Boost logo

Boost :

Subject: [boost] [ Interest? ] [ out_ptr ] Tiny C++ Abstraction for C-Style Output Pointers
From: ThePhD (phdofthehouse_at_[hidden])
Date: 2018-06-28 19:03:57

Dear Boost Community,

     I was encouraged to submit this small library that I had created as a
formal public investigation of the performance and API-interop benefits to
the Boost Mailing List, to perhaps see if other people have come up with
something similar to this at their own comapnies.

     out_ptr is a small abstraction for making types such as
std::unique_ptr, std::shared_ptr, boost::shared_ptr, and the upcoming
<> work
work C-Style output functions as a parameter, addressing the need of
wanting to be able to do "my_c_api_init( foo, bar, &my_smart_ptr );". It's
design is meant to be extensible by both the library implementer and the
user, enabling it to be used with other pointer types that do not originate
from either `boost::` or `std::`.

     The library replaces the sought-after syntax of:

my_c_api_init( foo, bar, &my_start_ptr );

     with a free function that does not impose on the interface of the
smart pointer:

my_c_api_init( foo, bar, out_ptr( my_smart_ptr ) );

     This makes it possible to use a temporary return value to give a
reference to a pointer value that then performs a reset on the smart

     Is there any want for something like this? I know it has seen use at
companies and Studios I have worked in and interacted with, including
Microsoft and VMWare. std::retain_ptr's author also has a need for this to
make interop easier with reference-counting C APIs and beyond, and I myself
implemented something like it 5 years ago and have been using it ever since.


P.S.: this is also going to end up going in the Post-Rapperswil Standards
C++ Mailing as well. The proposal is also contained in the repository:

Boost list run by bdawes at, gregod at, cpdaniel at, john at