Skip to content

Commit

Permalink
Make the intent clearer in manage_as_static
Browse files Browse the repository at this point in the history
Summary: Add a comment clarifying why we use a ctor that alliases an empty `shared_ptr` in `manage_as_static`. Without a comment it's a bit hard to figure out the behavior we get from the docs in https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr, esp. since the set of relevant overloads changed in C++20.

Reviewed By: praihan

Differential Revision: D70422993

fbshipit-source-id: de642aa1f4d7ba73c82821923a052b666c54b3f6
  • Loading branch information
vitaut authored and facebook-github-bot committed Mar 1, 2025
1 parent 36f8a19 commit 0373011
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions thrift/compiler/whisker/managed_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ using managed_ptr = std::shared_ptr<const T>;
*/
template <typename T>
managed_ptr<T> manage_as_static(const T& o) {
// Alias an empty shared_ptr to create a non-owning shared_ptr that doesn't
// allocate a control block (unlike using a noop deleter).
return managed_ptr<T>(managed_ptr<void>(), std::addressof(o));
}

Expand Down

0 comments on commit 0373011

Please sign in to comment.