11#include <userver/utils/meta_light.hpp>
13USERVER_NAMESPACE_BEGIN
20using IsPointerLike =
decltype(std::declval<T&>() ? std::addressof(*std::declval<T&&>()) :
nullptr);
23inline constexpr bool kIsPointerLike = meta::kIsDetected<IsPointerLike, T>;
27template <
typename Leaf>
28constexpr auto* GetIf(Leaf&& leaf) {
29 if constexpr (impl::kIsPointerLike<Leaf>) {
30 return leaf ?
utils::GetIf(*std::forward<Leaf>(leaf)) :
nullptr;
32 return std::addressof(std::forward<Leaf>(leaf));
40template <
typename Root,
typename Head,
typename... Tail>
41constexpr auto*
GetIf(Root&& root, Head&& head, Tail&&... tail) {
42 if constexpr (impl::kIsPointerLike<Root>) {
43 return root ?
utils::GetIf(*std::forward<Root>(root), std::forward<Head>(head), std::forward<Tail>(tail)...)
47 std::invoke(std::forward<Head>(head), std::forward<Root>(root)), std::forward<Tail>(tail)...