Skip to content

Commit 5a3dee0

Browse files
committed
Problem: implicit conversion operators in context
Solution: add handle() and mark operators as deprecated
1 parent a3e5b54 commit 5a3dee0

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

tests/context.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,26 @@ TEST_CASE("context create, close and destroy", "[context]")
1515
{
1616
zmq::context_t context;
1717
context.close();
18-
CHECK(NULL == (void *) context);
18+
CHECK(NULL == context.handle());
1919
}
2020

2121
TEST_CASE("context shutdown", "[context]")
2222
{
2323
zmq::context_t context;
2424
context.shutdown();
25-
CHECK(NULL != (void *) context);
25+
CHECK(NULL != context.handle());
2626
context.close();
27-
CHECK(NULL == (void *) context);
27+
CHECK(NULL == context.handle());
2828
}
2929

3030
TEST_CASE("context shutdown again", "[context]")
3131
{
3232
zmq::context_t context;
3333
context.shutdown();
3434
context.shutdown();
35-
CHECK(NULL != (void *) context);
35+
CHECK(NULL != context.handle());
3636
context.close();
37-
CHECK(NULL == (void *) context);
37+
CHECK(NULL == context.handle());
3838
}
3939

4040
#ifdef ZMQ_CPP11

zmq.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,9 @@ class context_t
788788

789789
ZMQ_EXPLICIT operator void const *() const ZMQ_NOTHROW { return ptr; }
790790

791+
ZMQ_NODISCARD void *handle() ZMQ_NOTHROW { return ptr; }
792+
793+
ZMQ_DEPRECATED("from 4.7.0, use handle() != nullptr instead")
791794
operator bool() const ZMQ_NOTHROW { return ptr != ZMQ_NULLPTR; }
792795

793796
void swap(context_t &other) ZMQ_NOTHROW { std::swap(ptr, other.ptr); }
@@ -2051,8 +2054,8 @@ class socket_t : public detail::socket_base
20512054
socket_t() ZMQ_NOTHROW : detail::socket_base(ZMQ_NULLPTR), ctxptr(ZMQ_NULLPTR) {}
20522055

20532056
socket_t(context_t &context_, int type_) :
2054-
detail::socket_base(zmq_socket(static_cast<void *>(context_), type_)),
2055-
ctxptr(static_cast<void *>(context_))
2057+
detail::socket_base(zmq_socket(context_.handle(), type_)),
2058+
ctxptr(context_.handle())
20562059
{
20572060
if (_handle == ZMQ_NULLPTR)
20582061
throw error_t();

0 commit comments

Comments
 (0)