I'm learning the Gandiva module in Apache Arrow. I found that many APIs require parameters in the form of std::shared_ptr<T>*
, eg here is an typical API:
static inline Status Make(SchemaPtr schema, ConditionPtr condition, std::shared_ptr<Filter> *filter)
I don't understand why it uses a pointer to a shared_ptr
instead of a simple shared_ptr
. To my understanding, a raw pointer should be avoided in C++ as much as possible, and shared_ptr
is designed as an alternative to using raw pointers.
This is their code style convention for output parameters.
filter – [out] the returned filter object
Usage
std::shared_ptr<Filter> filter;
Filter::Make(..., &filter);
I would use
Status Make(..., std::shared_ptr<Filter> &filter);
std::shared_ptr<Filter> filter;
Filter::Make(..., filter);
Perhaps seeing the usage &filter
they know filter
is an output argument w/o looking at the function declaration.
Apache Arrow Development Guidelines - Code Style, Linting, and CI
- We prefer pointers for output and input/output parameters (the style guide recommends mutable references in some cases).