Problem: if constexpr warnings on MSVC

Solution: Use if constexpr where possible in C++17
This commit is contained in:
Gudmundur Adalsteinsson 2020-10-25 09:24:16 +00:00
parent 18db4568f9
commit a7889af4bf
2 changed files with 9 additions and 5 deletions

12
zmq.hpp
View File

@ -97,8 +97,10 @@
#endif
#if defined(ZMQ_CPP17)
#define ZMQ_INLINE_VAR inline
#define ZMQ_CONSTEXPR_IF constexpr
#else
#define ZMQ_INLINE_VAR
#define ZMQ_CONSTEXPR_IF
#endif
#include <cassert>
@ -1769,17 +1771,19 @@ class socket_base
ZMQ_NODISCARD std::string get(sockopt::array_option<Opt, NullTerm>,
size_t init_size = 1024) const
{
if (NullTerm == 2 && init_size == 1024) {
init_size = 41; // get as Z85 string
if ZMQ_CONSTEXPR_IF (NullTerm == 2) {
if (init_size == 1024) {
init_size = 41; // get as Z85 string
}
}
std::string str(init_size, '\0');
size_t size = get(sockopt::array_option<Opt>{}, buffer(str));
if (NullTerm == 1) {
if ZMQ_CONSTEXPR_IF (NullTerm == 1) {
if (size > 0) {
assert(str[size - 1] == '\0');
--size;
}
} else if (NullTerm == 2) {
} else if ZMQ_CONSTEXPR_IF (NullTerm == 2) {
assert(size == 32 || size == 41);
if (size == 41) {
assert(str[size - 1] == '\0');

View File

@ -49,7 +49,7 @@ recv_multipart_n(socket_ref s, OutputIt out, size_t n, recv_flags flags)
size_t msg_count = 0;
message_t msg;
while (true) {
if (CheckN) {
if ZMQ_CONSTEXPR_IF (CheckN) {
if (msg_count >= n)
throw std::runtime_error(
"Too many message parts in recv_multipart_n");