Skip to content

Commit

Permalink
Problem: if constexpr warnings on MSVC
Browse files Browse the repository at this point in the history
Solution: Use if constexpr where possible in C++17
  • Loading branch information
gummif committed Nov 26, 2020
1 parent 18db456 commit a7889af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion zmq_addon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit a7889af

Please sign in to comment.