diff options
Diffstat (limited to 'libtransport/includes/hicn/transport/utils/shared_ptr_utils.h')
-rw-r--r-- | libtransport/includes/hicn/transport/utils/shared_ptr_utils.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libtransport/includes/hicn/transport/utils/shared_ptr_utils.h b/libtransport/includes/hicn/transport/utils/shared_ptr_utils.h new file mode 100644 index 000000000..3387997b5 --- /dev/null +++ b/libtransport/includes/hicn/transport/utils/shared_ptr_utils.h @@ -0,0 +1,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
\ No newline at end of file |