fmap_shared_ptr_aliasing
Declared in <folly/Memory.h>
template<
typename T,
typename GetU,
typename U = std::remove_pointer_t<std::invoke_result_t<GetU&, T const*>>>
std::shared_ptr<U>
fmap_shared_ptr_aliasing(
std::shared_ptr<T> const& owner,
GetU getU);
This is a helper method that allows one to get aliased shared_ptr to an inner object inside another shared_ptr. For example, if you have an object of type T that contains field of type U, you can use this method to get a shared pointer to the field U by calling fmap_shared_ptr_aliasing(ptrToT, getU) where getU is a function that returns a pointer to that field.
a shared_ptr to the field U or nullptr if the owner is nullptr or getU returns nullptr.
| Name | Description |
|---|---|
| owner | the shared_ptr that owns the object of type T |
| getU | a function that returns a const pointer to the field of type U by taking a const T* as an argument. |