diff --git a/zmq.hpp b/zmq.hpp index 9a5644d..6c0e91d 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -712,14 +712,16 @@ struct recv_buffer_size } }; -namespace detail -{ - #if defined(ZMQ_HAS_OPTIONAL) && (ZMQ_HAS_OPTIONAL > 0) + using send_result_t = std::optional; using recv_result_t = std::optional; using recv_buffer_result_t = std::optional; + #else + +namespace detail +{ // A C++11 type emulating the most basic // operations of std::optional for trivial types template class trivial_optional @@ -773,12 +775,17 @@ template class trivial_optional T _value{}; bool _has_value{false}; }; +} // namespace detail + +using send_result_t = detail::trivial_optional; +using recv_result_t = detail::trivial_optional; +using recv_buffer_result_t = detail::trivial_optional; -using send_result_t = trivial_optional; -using recv_result_t = trivial_optional; -using recv_buffer_result_t = trivial_optional; #endif +namespace detail +{ + template constexpr T enum_bit_or(T a, T b) noexcept { @@ -1303,7 +1310,7 @@ public: #endif #ifdef ZMQ_CPP11 - detail::send_result_t send(const_buffer buf, send_flags flags = send_flags::none) + send_result_t send(const_buffer buf, send_flags flags = send_flags::none) { const int nbytes = zmq_send(_handle, buf.data(), buf.size(), static_cast(flags)); @@ -1314,7 +1321,7 @@ public: throw error_t(); } - detail::send_result_t send(message_t &msg, send_flags flags) + send_result_t send(message_t &msg, send_flags flags) { int nbytes = zmq_msg_send(msg.handle(), _handle, static_cast(flags)); if (nbytes >= 0) @@ -1324,7 +1331,7 @@ public: throw error_t(); } - detail::send_result_t send(message_t &&msg, send_flags flags) + send_result_t send(message_t &&msg, send_flags flags) { return send(msg, flags); } @@ -1357,8 +1364,9 @@ public: } #ifdef ZMQ_CPP11 - ZMQ_NODISCARD detail::recv_buffer_result_t recv(mutable_buffer buf, - recv_flags flags = recv_flags::none) + ZMQ_NODISCARD + recv_buffer_result_t recv(mutable_buffer buf, + recv_flags flags = recv_flags::none) { const int nbytes = zmq_recv(_handle, buf.data(), buf.size(), static_cast(flags)); @@ -1371,7 +1379,8 @@ public: throw error_t(); } - ZMQ_NODISCARD detail::recv_result_t recv(message_t &msg, recv_flags flags = recv_flags::none) + ZMQ_NODISCARD + recv_result_t recv(message_t &msg, recv_flags flags = recv_flags::none) { const int nbytes = zmq_msg_recv(msg.handle(), _handle, static_cast(flags)); if (nbytes >= 0) { diff --git a/zmq_addon.hpp b/zmq_addon.hpp index 3ef3b3d..ebe9d10 100644 --- a/zmq_addon.hpp +++ b/zmq_addon.hpp @@ -53,8 +53,9 @@ namespace zmq message parts. It is adviced to close this socket in that event. */ template -ZMQ_NODISCARD detail::recv_result_t recv_multipart(socket_ref s, OutputIt out, - recv_flags flags = recv_flags::none) +ZMQ_NODISCARD +recv_result_t recv_multipart(socket_ref s, OutputIt out, + recv_flags flags = recv_flags::none) { size_t msg_count = 0; message_t msg; @@ -93,8 +94,8 @@ template, message_t>::value || detail::is_buffer>::value) >::type> -detail::send_result_t send_multipart(socket_ref s, Range&& msgs, - send_flags flags = send_flags::none) +send_result_t send_multipart(socket_ref s, Range&& msgs, + send_flags flags = send_flags::none) { using std::begin; using std::end;