mirror of
https://github.com/zeromq/cppzmq.git
synced 2024-12-12 10:33:52 +01:00
Assertion and constexpr improvements for str_buffer
This commit is contained in:
parent
13cc1e0fe9
commit
ab588fb7c9
@ -244,7 +244,7 @@ TEST_CASE("const_buffer creation with str_buffer", "[buffer]")
|
||||
CHECK(b.data() == static_cast<const wchar_t*>(wd));
|
||||
|
||||
zmq::const_buffer b2_null = zmq::buffer("hello");
|
||||
zmq::const_buffer b2 = zmq::str_buffer("hello");
|
||||
constexpr zmq::const_buffer b2 = zmq::str_buffer("hello");
|
||||
CHECK(b2_null.size() == 6);
|
||||
CHECK(b2.size() == 5);
|
||||
CHECK(std::string(static_cast<const char*>(b2.data()), b2.size()) == "hello");
|
||||
|
7
zmq.hpp
7
zmq.hpp
@ -1114,12 +1114,13 @@ const_buffer buffer(std::basic_string_view<T, Traits> data, size_t n_bytes) noex
|
||||
// where the buffer size excludes the terminating character.
|
||||
// Equivalent to zmq::buffer(std::string_view("...")).
|
||||
template<class Char, size_t N>
|
||||
const_buffer str_buffer(const Char (&data)[N]) noexcept
|
||||
constexpr const_buffer str_buffer(const Char (&data)[N]) noexcept
|
||||
{
|
||||
static_assert(detail::is_pod_like<Char>::value, "Char must be POD");
|
||||
static_assert(N > 0, "N > 0");
|
||||
#ifdef ZMQ_CPP14
|
||||
assert(data[N - 1] == Char{0});
|
||||
return const_buffer(N == 1 ? nullptr : static_cast<const Char*>(data),
|
||||
#endif
|
||||
return const_buffer(static_cast<const Char*>(data),
|
||||
(N - 1) * sizeof(Char));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user