aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/includes/hicn/transport/utils/shared_ptr_utils.h
blob: 3387997b5db857fcf9b9cce8319e86605c939ffc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * Copyright (c) 2021 Cisco and/or its affiliates.
 */

#pragma once

#include <memory>

namespace utils {

template <typename Base>
inline std::shared_ptr<Base> shared_from_base(
    std::enable_shared_from_this<Base>* base) {
  return base->shared_from_this();
}

template <typename Base>
inline std::shared_ptr<const Base> shared_from_base(
    std::enable_shared_from_this<Base> const* base) {
  return base->shared_from_this();
}

template <typename That>
inline std::shared_ptr<That> shared_from(That* that) {
  return std::static_pointer_cast<That>(shared_from_base(that));
}

}  // namespace utils