folly::fmap_shared_ptr_aliasing

fmap_shared_ptr_aliasing

Synopsis

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);

Description

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.

Return Value

a shared_ptr to the field U or nullptr if the owner is nullptr or getU returns nullptr.

Parameters

NameDescription
ownerthe shared_ptr that owns the object of type T
getUa function that returns a const pointer to the field of type U by taking a const T* as an argument.