async_mqtt 9.0.1
Loading...
Searching...
No Matches
shared_ptr_array.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_SHARED_PTR_ARRAY_HPP)
8#define ASYNC_MQTT_UTIL_SHARED_PTR_ARRAY_HPP
9
10#include <memory>
11
12namespace async_mqtt {
13
25inline std::shared_ptr<char []> make_shared_ptr_char_array(std::size_t size) {
26#if __cpp_lib_shared_ptr_arrays >= 201707L
27 return std::make_shared<char[]>(size);
28#else // __cpp_lib_shared_ptr_arrays >= 201707L
29 return std::shared_ptr<char[]>(new char[size]);
30#endif // __cpp_lib_shared_ptr_arrays >= 201707Lhai
31}
32
45template <typename Alloc>
46inline std::shared_ptr<char []> allocate_shared_ptr_char_array(Alloc&& alloc, std::size_t size) {
47#if __cpp_lib_shared_ptr_arrays >= 201707L
48 return std::allocate_shared<char[]>(alloc, size);
49#else // __cpp_lib_shared_ptr_arrays >= 201707L
50 return std::shared_ptr<char[]>(
51 alloc.allocate(size),
52 [alloc, size](char* ptr) mutable { alloc.deallocate(ptr, size); }
53 );
54#endif // __cpp_lib_shared_ptr_arrays >= 201707Lhai
55}
56
57} // namespace async_mqtt
58
59#endif // ASYNC_MQTT_UTIL_SHARED_PTR_ARRAY_HPP
std::shared_ptr< char[]> allocate_shared_ptr_char_array(Alloc &&alloc, std::size_t size)
shared_ptr<char[]> creating function with allocator. You can choose the target type.
Definition shared_ptr_array.hpp:46
std::shared_ptr< char[]> make_shared_ptr_char_array(std::size_t size)
shared_ptr<char[]> creating function. You can choose the target type.
Definition shared_ptr_array.hpp:25