mqtt_cpp
shared_ptr_array.hpp
Go to the documentation of this file.
1 // Copyright Takatoshi Kondo 2019
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(MQTT_SHARED_PTR_ARRAY_HPP)
8 #define MQTT_SHARED_PTR_ARRAY_HPP
9 
10 #if defined(_DOXYGEN_)
11 
20 using shared_ptr_array = std::shared_ptr<char []>;
21 using const_shared_ptr_array = std::shared_ptr<char const []>;
22 
35 
36 #else // defined(_DOXYGEN_)
37 
38 #include <mqtt/namespace.hpp>
39 
40 #ifdef MQTT_STD_SHARED_PTR_ARRAY
41 
42 #include <memory>
43 
44 namespace MQTT_NS {
45 
46 using shared_ptr_array = std::shared_ptr<char []>;
47 using const_shared_ptr_array = std::shared_ptr<char const []>;
48 
49 inline shared_ptr_array make_shared_ptr_array(std::size_t size) {
50 #if __cplusplus > 201703L // C++20 date is not determined yet
51  return std::make_shared<char[]>(size);
52 #else // __cplusplus > 201703L
53  return std::shared_ptr<char[]>(new char[size]);
54 #endif // __cplusplus > 201703L
55 }
56 
57 } // namespace MQTT_NS
58 
59 #else // MQTT_STD_SHARED_PTR_ARRAY
60 
61 #include <boost/shared_ptr.hpp>
62 #include <boost/smart_ptr/make_shared.hpp>
63 
64 namespace MQTT_NS {
65 
66 using shared_ptr_array = boost::shared_ptr<char []>;
67 using const_shared_ptr_array = boost::shared_ptr<char const []>;
68 
69 inline shared_ptr_array make_shared_ptr_array(std::size_t size) {
70  return boost::make_shared<char[]>(size);
71 }
72 
73 } // namespace MQTT_NS
74 
75 #endif // MQTT_STD_SHARED_PTR_ARRAY
76 
77 #endif // defined(_DOXYGEN_)
78 
79 #endif // MQTT_SHARED_PTR_ARRAY_HPP
Definition: any.hpp:27
std::size_t size(basic_message_variant< PacketIdBytes > const &mv)
Definition: message_variant.hpp:93
std::shared_ptr< char[]> shared_ptr_array
Type alias of shared_ptr char array. You can choose the target type.
Definition: shared_ptr_array.hpp:20
shared_ptr_array make_shared_ptr_array(std::size_t size)
shared_ptr_array creating function. You can choose the target type.
std::shared_ptr< char const[]> const_shared_ptr_array
Definition: shared_ptr_array.hpp:21