Skip to content

Commit 89f4d1b

Browse files
authored
Merge pull request #408 from gummif/gfa/ctx-handle
Problem: implicit conversion operators in context
2 parents 452f736 + 5a3dee0 commit 89f4d1b

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
@@ -812,6 +812,9 @@ class context_t
812812

813813
ZMQ_EXPLICIT operator void const *() const ZMQ_NOTHROW { return ptr; }
814814

815+
ZMQ_NODISCARD void *handle() ZMQ_NOTHROW { return ptr; }
816+
817+
ZMQ_DEPRECATED("from 4.7.0, use handle() != nullptr instead")
815818
operator bool() const ZMQ_NOTHROW { return ptr != ZMQ_NULLPTR; }
816819

817820
void swap(context_t &other) ZMQ_NOTHROW { std::swap(ptr, other.ptr); }
@@ -2075,8 +2078,8 @@ class socket_t : public detail::socket_base
20752078
socket_t() ZMQ_NOTHROW : detail::socket_base(ZMQ_NULLPTR), ctxptr(ZMQ_NULLPTR) {}
20762079

20772080
socket_t(context_t &context_, int type_) :
2078-
detail::socket_base(zmq_socket(static_cast<void *>(context_), type_)),
2079-
ctxptr(static_cast<void *>(context_))
2081+
detail::socket_base(zmq_socket(context_.handle(), type_)),
2082+
ctxptr(context_.handle())
20802083
{
20812084
if (_handle == ZMQ_NULLPTR)
20822085
throw error_t();

0 commit comments

Comments
 (0)