87
87
#include < memory>
88
88
#endif
89
89
#ifdef ZMQ_CPP17
90
+ #ifdef __has_include
91
+ #if __has_include(<optional>)
90
92
#include < optional>
93
+ #define ZMQ_HAS_OPTIONAL 1
94
+ #endif
95
+ #if __has_include(<string_view>)
96
+ #include < string_view>
97
+ #define ZMQ_HAS_STRING_VIEW 1
98
+ #endif
99
+ #endif
100
+
91
101
#endif
92
102
93
103
/* Version macros for compile-time API version detection */
127
137
#if defined(ZMQ_CPP11) && !defined(__llvm__) && !defined(__INTEL_COMPILER) \
128
138
&& defined(__GNUC__) && __GNUC__ < 5
129
139
#define ZMQ_CPP11_PARTIAL
140
+ #elif defined(__GLIBCXX__) && __GLIBCXX__ < 20160805
141
+ // the date here is the last date of gcc 4.9.4, which
142
+ // effectively means libstdc++ from gcc 5.5 and higher won't trigger this branch
143
+ #define ZMQ_CPP11_PARTIAL
130
144
#endif
131
145
132
146
#ifdef ZMQ_CPP11
133
147
#ifdef ZMQ_CPP11_PARTIAL
134
148
#define ZMQ_IS_TRIVIALLY_COPYABLE (T ) __has_trivial_copy(T)
135
149
#else
150
+ #include < type_traits>
136
151
#define ZMQ_IS_TRIVIALLY_COPYABLE (T ) std::is_trivially_copyable<T>::value
137
152
#endif
138
153
#endif
@@ -700,7 +715,7 @@ struct recv_buffer_size
700
715
namespace detail
701
716
{
702
717
703
- #ifdef ZMQ_CPP17
718
+ #if defined(ZMQ_HAS_OPTIONAL) && (ZMQ_HAS_OPTIONAL > 0)
704
719
using send_result_t = std::optional<size_t >;
705
720
using recv_result_t = std::optional<size_t >;
706
721
using recv_buffer_result_t = std::optional<recv_buffer_size>;
@@ -1097,7 +1112,7 @@ const_buffer buffer(const std::basic_string<T, Traits, Allocator> &data,
1097
1112
return detail::buffer_contiguous_sequence (data, n_bytes);
1098
1113
}
1099
1114
1100
- #ifdef ZMQ_CPP17
1115
+ #if defined(ZMQ_HAS_STRING_VIEW) && (ZMQ_HAS_STRING_VIEW > 0)
1101
1116
// std::basic_string_view
1102
1117
template <class T , class Traits >
1103
1118
const_buffer buffer (std::basic_string_view<T, Traits> data) noexcept
@@ -1121,7 +1136,7 @@ constexpr const_buffer str_buffer(const Char (&data)[N]) noexcept
1121
1136
#ifdef ZMQ_CPP14
1122
1137
assert (data[N - 1 ] == Char{0 });
1123
1138
#endif
1124
- return const_buffer (static_cast <const Char*>(data),
1139
+ return const_buffer (static_cast <const Char*>(data),
1125
1140
(N - 1 ) * sizeof (Char));
1126
1141
}
1127
1142
0 commit comments