Skip to content

Commit ab588fb

Browse files
committed
Assertion and constexpr improvements for str_buffer
1 parent 13cc1e0 commit ab588fb

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

tests/buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ TEST_CASE("const_buffer creation with str_buffer", "[buffer]")
244244
CHECK(b.data() == static_cast<const wchar_t*>(wd));
245245

246246
zmq::const_buffer b2_null = zmq::buffer("hello");
247-
zmq::const_buffer b2 = zmq::str_buffer("hello");
247+
constexpr zmq::const_buffer b2 = zmq::str_buffer("hello");
248248
CHECK(b2_null.size() == 6);
249249
CHECK(b2.size() == 5);
250250
CHECK(std::string(static_cast<const char*>(b2.data()), b2.size()) == "hello");

zmq.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,12 +1114,13 @@ const_buffer buffer(std::basic_string_view<T, Traits> data, size_t n_bytes) noex
11141114
// where the buffer size excludes the terminating character.
11151115
// Equivalent to zmq::buffer(std::string_view("...")).
11161116
template<class Char, size_t N>
1117-
const_buffer str_buffer(const Char (&data)[N]) noexcept
1117+
constexpr const_buffer str_buffer(const Char (&data)[N]) noexcept
11181118
{
11191119
static_assert(detail::is_pod_like<Char>::value, "Char must be POD");
1120-
static_assert(N > 0, "N > 0");
1120+
#ifdef ZMQ_CPP14
11211121
assert(data[N - 1] == Char{0});
1122-
return const_buffer(N == 1 ? nullptr : static_cast<const Char*>(data),
1122+
#endif
1123+
return const_buffer(static_cast<const Char*>(data),
11231124
(N - 1) * sizeof(Char));
11241125
}
11251126

0 commit comments

Comments
 (0)