mirror of
https://github.com/zeromq/cppzmq.git
synced 2024-12-14 02:57:48 +01:00
Problem: if constexpr warnings on MSVC
Solution: Use if constexpr where possible in C++17
This commit is contained in:
parent
18db4568f9
commit
a7889af4bf
10
zmq.hpp
10
zmq.hpp
@ -97,8 +97,10 @@
|
|||||||
#endif
|
#endif
|
||||||
#if defined(ZMQ_CPP17)
|
#if defined(ZMQ_CPP17)
|
||||||
#define ZMQ_INLINE_VAR inline
|
#define ZMQ_INLINE_VAR inline
|
||||||
|
#define ZMQ_CONSTEXPR_IF constexpr
|
||||||
#else
|
#else
|
||||||
#define ZMQ_INLINE_VAR
|
#define ZMQ_INLINE_VAR
|
||||||
|
#define ZMQ_CONSTEXPR_IF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@ -1769,17 +1771,19 @@ class socket_base
|
|||||||
ZMQ_NODISCARD std::string get(sockopt::array_option<Opt, NullTerm>,
|
ZMQ_NODISCARD std::string get(sockopt::array_option<Opt, NullTerm>,
|
||||||
size_t init_size = 1024) const
|
size_t init_size = 1024) const
|
||||||
{
|
{
|
||||||
if (NullTerm == 2 && init_size == 1024) {
|
if ZMQ_CONSTEXPR_IF (NullTerm == 2) {
|
||||||
|
if (init_size == 1024) {
|
||||||
init_size = 41; // get as Z85 string
|
init_size = 41; // get as Z85 string
|
||||||
}
|
}
|
||||||
|
}
|
||||||
std::string str(init_size, '\0');
|
std::string str(init_size, '\0');
|
||||||
size_t size = get(sockopt::array_option<Opt>{}, buffer(str));
|
size_t size = get(sockopt::array_option<Opt>{}, buffer(str));
|
||||||
if (NullTerm == 1) {
|
if ZMQ_CONSTEXPR_IF (NullTerm == 1) {
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
assert(str[size - 1] == '\0');
|
assert(str[size - 1] == '\0');
|
||||||
--size;
|
--size;
|
||||||
}
|
}
|
||||||
} else if (NullTerm == 2) {
|
} else if ZMQ_CONSTEXPR_IF (NullTerm == 2) {
|
||||||
assert(size == 32 || size == 41);
|
assert(size == 32 || size == 41);
|
||||||
if (size == 41) {
|
if (size == 41) {
|
||||||
assert(str[size - 1] == '\0');
|
assert(str[size - 1] == '\0');
|
||||||
|
@ -49,7 +49,7 @@ recv_multipart_n(socket_ref s, OutputIt out, size_t n, recv_flags flags)
|
|||||||
size_t msg_count = 0;
|
size_t msg_count = 0;
|
||||||
message_t msg;
|
message_t msg;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (CheckN) {
|
if ZMQ_CONSTEXPR_IF (CheckN) {
|
||||||
if (msg_count >= n)
|
if (msg_count >= n)
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"Too many message parts in recv_multipart_n");
|
"Too many message parts in recv_multipart_n");
|
||||||
|
Loading…
Reference in New Issue
Block a user