Skip to content

Commit 17a530a

Browse files
committed
Update message_t range constructor to accept char containers but ignore
std::string(_view)
1 parent a3ca96e commit 17a530a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

tests/message.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ TEST_CASE("message constructor with iterators", "[message]")
4848
CHECK(0 == memcmp(data, hi_msg.data(), 2));
4949
}
5050

51+
TEST_CASE("message constructor with ranges", "[message]")
52+
{
53+
SECTION("trivial type")
54+
{
55+
const std::vector<int> v{1, 2, 3};
56+
const zmq::message_t msg(v);
57+
CHECK(3u * sizeof(int) == msg.size());
58+
}
59+
SECTION("char type")
60+
{
61+
const std::vector<char> hi{'H', 'i'};
62+
const zmq::message_t hi_msg(hi);
63+
CHECK(2u == hi_msg.size());
64+
CHECK(0 == memcmp(data, hi_msg.data(), 2));
65+
}
66+
}
67+
5168
TEST_CASE("message constructor with size", "[message]")
5269
{
5370
const zmq::message_t msg(5);

zmq.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,11 @@ class message_t
492492
typename = typename std::enable_if<
493493
detail::is_range<Range>::value
494494
&& ZMQ_IS_TRIVIALLY_COPYABLE(detail::range_value_t<Range>)
495-
&& !detail::is_char_type<detail::range_value_t<Range>>::value
496-
&& !std::is_same<Range, message_t>::value>::type>
495+
&& !std::is_same<Range, message_t>::value
496+
#if CPPZMQ_HAS_STRING_VIEW
497+
&& !std::is_same<Range, std::string_view>::value
498+
#endif
499+
&& !std::is_same<Range, std::string>::value>::type>
497500
explicit message_t(const Range &rng) :
498501
message_t(detail::ranges::begin(rng), detail::ranges::end(rng))
499502
{

0 commit comments

Comments
 (0)