Skip to content

Commit

Permalink
Problem: Detail namespace used in API
Browse files Browse the repository at this point in the history
Solution: Move types into zmq namespace
  • Loading branch information
gummif committed Nov 12, 2019
1 parent a34d2a3 commit 0ef29c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
33 changes: 21 additions & 12 deletions zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>;
using recv_result_t = std::optional<size_t>;
using recv_buffer_result_t = std::optional<recv_buffer_size>;

#else

namespace detail
{
// A C++11 type emulating the most basic
// operations of std::optional for trivial types
template<class T> class trivial_optional
Expand Down Expand Up @@ -773,12 +775,17 @@ template<class T> class trivial_optional
T _value{};
bool _has_value{false};
};
} // namespace detail

using send_result_t = detail::trivial_optional<size_t>;
using recv_result_t = detail::trivial_optional<size_t>;
using recv_buffer_result_t = detail::trivial_optional<recv_buffer_size>;

using send_result_t = trivial_optional<size_t>;
using recv_result_t = trivial_optional<size_t>;
using recv_buffer_result_t = trivial_optional<recv_buffer_size>;
#endif

namespace detail
{

template<class T>
constexpr T enum_bit_or(T a, T b) noexcept
{
Expand Down Expand Up @@ -1303,7 +1310,7 @@ class socket_base
#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<int>(flags));
Expand All @@ -1314,7 +1321,7 @@ class socket_base
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<int>(flags));
if (nbytes >= 0)
Expand All @@ -1324,7 +1331,7 @@ class socket_base
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);
}
Expand Down Expand Up @@ -1357,8 +1364,9 @@ class socket_base
}

#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<int>(flags));
Expand All @@ -1371,7 +1379,8 @@ class socket_base
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<int>(flags));
if (nbytes >= 0) {
Expand Down
9 changes: 5 additions & 4 deletions zmq_addon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ namespace zmq
message parts. It is adviced to close this socket in that event.
*/
template<class OutputIt>
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;
Expand Down Expand Up @@ -93,8 +94,8 @@ template<class Range,
&& (std::is_same<detail::range_value_t<Range>, message_t>::value
|| detail::is_buffer<detail::range_value_t<Range>>::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;
Expand Down

0 comments on commit 0ef29c1

Please sign in to comment.