|
103 | 103 | #include <tuple> |
104 | 104 | #include <memory> |
105 | 105 | #endif |
106 | | -#ifdef ZMQ_CPP17 |
107 | | -#ifdef __has_include |
108 | | -#if __has_include(<optional>) |
109 | | -#include <optional> |
110 | | -#define ZMQ_HAS_OPTIONAL 1 |
| 106 | + |
| 107 | +#if defined(__has_include) && defined(ZMQ_CPP17) |
| 108 | +#define CPPZMQ_HAS_INCLUDE_CPP17(X) __has_include(X) |
| 109 | +#else |
| 110 | +#define CPPZMQ_HAS_INCLUDE_CPP17(X) 0 |
111 | 111 | #endif |
112 | | -#if __has_include(<string_view>) |
113 | | -#include <string_view> |
114 | | -#define ZMQ_HAS_STRING_VIEW 1 |
| 112 | + |
| 113 | +#if CPPZMQ_HAS_INCLUDE_CPP17(<optional>) && !defined(CPPZMQ_HAS_OPTIONAL) |
| 114 | +#define CPPZMQ_HAS_OPTIONAL 1 |
115 | 115 | #endif |
| 116 | +#ifndef CPPZMQ_HAS_OPTIONAL |
| 117 | +#define CPPZMQ_HAS_OPTIONAL 0 |
| 118 | +#elif CPPZMQ_HAS_OPTIONAL |
| 119 | +#include <optional> |
116 | 120 | #endif |
117 | 121 |
|
| 122 | +#if CPPZMQ_HAS_INCLUDE_CPP17(<string_view>) && !defined(CPPZMQ_HAS_STRING_VIEW) |
| 123 | +#define CPPZMQ_HAS_STRING_VIEW 1 |
| 124 | +#endif |
| 125 | +#ifndef CPPZMQ_HAS_STRING_VIEW |
| 126 | +#define CPPZMQ_HAS_STRING_VIEW 0 |
| 127 | +#elif CPPZMQ_HAS_STRING_VIEW |
| 128 | +#include <string_view> |
118 | 129 | #endif |
119 | 130 |
|
120 | 131 | /* Version macros for compile-time API version detection */ |
@@ -582,7 +593,7 @@ class message_t |
582 | 593 | { |
583 | 594 | return std::string(static_cast<const char *>(data()), size()); |
584 | 595 | } |
585 | | -#ifdef ZMQ_CPP17 |
| 596 | +#if CPPZMQ_HAS_STRING_VIEW |
586 | 597 | // interpret message content as a string |
587 | 598 | std::string_view to_string_view() const noexcept |
588 | 599 | { |
@@ -830,7 +841,7 @@ struct recv_buffer_size |
830 | 841 | } |
831 | 842 | }; |
832 | 843 |
|
833 | | -#if defined(ZMQ_HAS_OPTIONAL) && (ZMQ_HAS_OPTIONAL > 0) |
| 844 | +#if CPPZMQ_HAS_OPTIONAL |
834 | 845 |
|
835 | 846 | using send_result_t = std::optional<size_t>; |
836 | 847 | using recv_result_t = std::optional<size_t>; |
@@ -1237,7 +1248,7 @@ const_buffer buffer(const std::basic_string<T, Traits, Allocator> &data, |
1237 | 1248 | return detail::buffer_contiguous_sequence(data, n_bytes); |
1238 | 1249 | } |
1239 | 1250 |
|
1240 | | -#if defined(ZMQ_HAS_STRING_VIEW) && (ZMQ_HAS_STRING_VIEW > 0) |
| 1251 | +#if CPPZMQ_HAS_STRING_VIEW |
1241 | 1252 | // std::basic_string_view |
1242 | 1253 | template<class T, class Traits> |
1243 | 1254 | const_buffer buffer(std::basic_string_view<T, Traits> data) noexcept |
@@ -1662,7 +1673,7 @@ class socket_base |
1662 | 1673 | set_option(Opt, buf.data(), buf.size()); |
1663 | 1674 | } |
1664 | 1675 |
|
1665 | | -#ifdef ZMQ_CPP17 |
| 1676 | +#if CPPZMQ_HAS_STRING_VIEW |
1666 | 1677 | // Set array socket option, e.g. |
1667 | 1678 | // `socket.set(zmq::sockopt::routing_id, id_str)` |
1668 | 1679 | template<int Opt, int NullTerm> |
|
0 commit comments