Idiomatic use of smart pointers in cpp2 code #674
Unanswered
AbhinavK00
asked this question in
Q&A
Replies: 1 comment
-
Same as Cpp1. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've never worked on large codebases so apologies in advance if this question turns out to be stupid.
The question, how to use smart pointers in cpp2 code.
Suppose I have a function which takes a
bigStruct
as inout parameter. It works with stack values but if I want to handle the case for a value on free store, what should I do? My first instinct was to write another overload of function which takes a unique pointer to bigStruct. But even with this, should that function take the unique pointer as aninout
parameter or amove
parameter?If the former, wouldn't that require the
get
member to be called?If the latter, how do I garuntee to the caller that I have not stolen the guts to his resource (since my intention was
inout
)?If any of those, what should I expect the caller side code to look like?
Or are there other ways to do this?
Notes: bigStruct is any expensive to copy thing
Beta Was this translation helpful? Give feedback.
All reactions