Skip to content

Usage of smart pointers #900

Answered by rainman110
MarAlder asked this question in Q&A
Feb 17, 2022 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Obviously, TiGL's codebase comes from the pre C++11 area, with std::shared_ptr as the only smart pointer. This is the primary reason for the lack of smart pointers.

C++ libraries rarely return smart pointers as this implies a change of ownership, returning e.g. unique_ptr always implies the transfer of ownership to the caller, which often only makes sense for factories.

Having just raw pointers (optional type) or references in the interface helps also keeping interfaces to other languages simpler. Generally though, I favor having smart pointers to manage the lifetime of objects.

There's a good talk "Back to basics: smart pointers" at the CPPCon: https://youtu.be/xGDLkt-jBJ4

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by MarAlder
Comment options

MarAlder
Apr 2, 2022
Collaborator Author

You must be logged in to vote
1 reply
@joergbrech
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #879 on April 05, 2022 08:52.