@@ -342,8 +342,8 @@ inline int poll(std::vector<zmq_pollitem_t> &items, long timeout_ = -1)
342342}
343343
344344template <std::size_t SIZE>
345- inline int poll (std::array<zmq_pollitem_t , SIZE>& items,
346- std::chrono::milliseconds timeout)
345+ inline int poll (std::array<zmq_pollitem_t , SIZE> & items,
346+ std::chrono::milliseconds timeout)
347347{
348348 return poll (items.data (), items.size (), static_cast <long >(timeout.count ()));
349349}
@@ -362,6 +362,20 @@ inline std::tuple<int, int, int> version()
362362 zmq_version (&std::get<0 >(v), &std::get<1 >(v), &std::get<2 >(v));
363363 return v;
364364}
365+
366+ #if !defined(ZMQ_CPP11_PARTIAL)
367+ namespace detail
368+ {
369+ template <class T > struct is_char_type
370+ {
371+ // true if character type for string literals in C++11
372+ static constexpr bool value =
373+ std::is_same<T, char >::value || std::is_same<T, wchar_t >::value
374+ || std::is_same<T, char16_t >::value || std::is_same<T, char32_t >::value;
375+ };
376+ }
377+ #endif
378+
365379#endif
366380
367381class message_t
@@ -398,8 +412,7 @@ class message_t
398412 int rc = zmq_msg_init_size (&msg, size_);
399413 if (rc != 0 )
400414 throw error_t ();
401- if (size_)
402- {
415+ if (size_) {
403416 // this constructor allows (nullptr, 0),
404417 // memcpy with a null pointer is UB
405418 memcpy (data (), data_, size_);
@@ -413,16 +426,40 @@ class message_t
413426 throw error_t ();
414427 }
415428
429+ // overload set of string-like types and generic containers
416430#if defined(ZMQ_CPP11) && !defined(ZMQ_CPP11_PARTIAL)
431+ // NOTE this constructor will include the null terminator
432+ // when called with a string literal.
433+ // An overload taking const char* can not be added because
434+ // it would be preferred over this function and break compatiblity.
435+ template <
436+ class Char ,
437+ size_t N,
438+ typename = typename std::enable_if<detail::is_char_type<Char>::value>::type>
439+ ZMQ_DEPRECATED (" from 4.7.0, use constructors taking iterators, (pointer, size) "
440+ " or strings instead" )
441+ explicit message_t(const Char (&data)[N]) :
442+ message_t(detail::ranges::begin(data), detail::ranges::end(data))
443+ {
444+ }
445+
417446 template <class Range ,
418447 typename = typename std::enable_if<
419448 detail::is_range<Range>::value
420449 && ZMQ_IS_TRIVIALLY_COPYABLE(detail::range_value_t <Range>)
450+ && !detail::is_char_type<detail::range_value_t<Range>>::value
421451 && !std::is_same<Range, message_t>::value>::type>
422452 explicit message_t(const Range &rng) :
423453 message_t(detail::ranges::begin(rng), detail::ranges::end(rng))
424454 {
425455 }
456+
457+ explicit message_t (const std::string &str) : message_t(str.data(), str.size()) {}
458+
459+ #if CPPZMQ_HAS_STRING_VIEW
460+ explicit message_t (std::string_view str) : message_t(str.data(), str.size()) {}
461+ #endif
462+
426463#endif
427464
428465#ifdef ZMQ_HAS_RVALUE_REFS
@@ -1337,19 +1374,19 @@ template<int Opt, int NullTerm = 1> struct array_option
13371374
13381375#define ZMQ_DEFINE_INTEGRAL_OPT (OPT, NAME, TYPE ) \
13391376 using NAME##_t = integral_option<OPT, TYPE, false >; \
1340- ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME{}
1377+ ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME {}
13411378#define ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT (OPT, NAME, TYPE ) \
13421379 using NAME##_t = integral_option<OPT, TYPE, true >; \
1343- ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME{}
1380+ ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME {}
13441381#define ZMQ_DEFINE_ARRAY_OPT (OPT, NAME ) \
13451382 using NAME##_t = array_option<OPT>; \
1346- ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME{}
1383+ ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME {}
13471384#define ZMQ_DEFINE_ARRAY_OPT_BINARY (OPT, NAME ) \
13481385 using NAME##_t = array_option<OPT, 0 >; \
1349- ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME{}
1386+ ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME {}
13501387#define ZMQ_DEFINE_ARRAY_OPT_BIN_OR_Z85 (OPT, NAME ) \
13511388 using NAME##_t = array_option<OPT, 2 >; \
1352- ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME{}
1389+ ZMQ_INLINE_VAR ZMQ_CONSTEXPR_VAR NAME##_t NAME {}
13531390
13541391// duplicate definition from libzmq 4.3.3
13551392#if defined _WIN32
@@ -2161,7 +2198,6 @@ class socket_t : public detail::socket_base
21612198 throw error_t ();
21622199 if (ctxptr == ZMQ_NULLPTR)
21632200 throw error_t ();
2164-
21652201 }
21662202};
21672203
0 commit comments