Skip to content

Commit de05d33

Browse files
authored
Merge pull request #355 from phlptp/cpp17_library_fixes
C++17 library fixes
2 parents ca1ca7c + d5cbaf4 commit de05d33

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

zmq.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,17 @@
8787
#include <memory>
8888
#endif
8989
#ifdef ZMQ_CPP17
90+
#ifdef __has_include
91+
#if __has_include(<optional>)
9092
#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+
91101
#endif
92102

93103
/* Version macros for compile-time API version detection */
@@ -127,12 +137,17 @@
127137
#if defined(ZMQ_CPP11) && !defined(__llvm__) && !defined(__INTEL_COMPILER) \
128138
&& defined(__GNUC__) && __GNUC__ < 5
129139
#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
130144
#endif
131145

132146
#ifdef ZMQ_CPP11
133147
#ifdef ZMQ_CPP11_PARTIAL
134148
#define ZMQ_IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
135149
#else
150+
#include <type_traits>
136151
#define ZMQ_IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable<T>::value
137152
#endif
138153
#endif
@@ -700,7 +715,7 @@ struct recv_buffer_size
700715
namespace detail
701716
{
702717

703-
#ifdef ZMQ_CPP17
718+
#if defined(ZMQ_HAS_OPTIONAL) && (ZMQ_HAS_OPTIONAL > 0)
704719
using send_result_t = std::optional<size_t>;
705720
using recv_result_t = std::optional<size_t>;
706721
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,
10971112
return detail::buffer_contiguous_sequence(data, n_bytes);
10981113
}
10991114

1100-
#ifdef ZMQ_CPP17
1115+
#if defined(ZMQ_HAS_STRING_VIEW) && (ZMQ_HAS_STRING_VIEW > 0)
11011116
// std::basic_string_view
11021117
template<class T, class Traits>
11031118
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
11211136
#ifdef ZMQ_CPP14
11221137
assert(data[N - 1] == Char{0});
11231138
#endif
1124-
return const_buffer(static_cast<const Char*>(data),
1139+
return const_buffer(static_cast<const Char*>(data),
11251140
(N - 1) * sizeof(Char));
11261141
}
11271142

0 commit comments

Comments
 (0)