async_mqtt 5.0.0
Loading...
Searching...
No Matches
make_shared_helper.hpp
1// Copyright Takatoshi Kondo 2022
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#if !defined(ASYNC_MQTT_UTIL_MAKE_SHARED_HELPER_HPP)
8#define ASYNC_MQTT_UTIL_MAKE_SHARED_HELPER_HPP
9
10#include <memory>
11
12namespace async_mqtt {
13
14template <typename T>
15class make_shared_helper {
16 friend T;
17 struct target : public T {
18 template<typename... Args>
19 target(Args&&... args)
20 :T{std::forward<Args>(args)...}
21 {}
22 };
23
24 template <typename... Args>
25 static std::shared_ptr<T> make_shared(Args&&... args) {
26 return std::make_shared<target>(std::forward<Args>(args)...);
27 }
28
29 template<typename Alloc, typename... Args>
30 static std::shared_ptr<T> allocate_shared(Alloc const& alloc, Args&&... args) {
31 return std::allocate_shared<target>(alloc, std::forward<Args>(args)...);
32 }
33};
34
35} // namespace async_mqtt
36
37#endif // ASYNC_MQTT_UTIL_MAKE_SHARED_HELPER_HPP