Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ jobs:

- name: format
run: |
git ls-files | grep -E '\.(cpp|hpp)' | xargs clang-format --dry-run --Werror
clang-format --version
git ls-files | grep -E '\.(cpp|hpp)' | xargs clang-format --dry-run --Werror

- name: build
env:
Expand Down
45 changes: 32 additions & 13 deletions zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
// To avoid the `(std::min)` workaround for when a min macro is defined
#ifdef min
#define WINDOWS_MIN min
#undef min
#endif
#ifdef max
#define WINDOWS_MAX max
#undef max
#endif
Comment on lines +33 to +41
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was initially to fix the formatting being different between clang-format 14 and 20 for the (std::min)(x, y) trick.

I ended up fixing it differently but this "guard" macros seems a bit cleaner than having to remember the (std::min) workaround. Let me know if I should keep it

(Still have to test if it works on Windows tho)

#endif

// included here for _HAS_CXX* macros
Expand Down Expand Up @@ -701,7 +710,7 @@ class message_t
std::stringstream os;

const unsigned char *msg_data = this->data<unsigned char>();
size_t size_to_print = (std::min) (this->size(), max_size);
size_t size_to_print = std::min(this->size(), max_size);
int is_ascii[2] = {0, 0};
// Set is_ascii for the first character
if (size_to_print > 0)
Expand Down Expand Up @@ -1101,8 +1110,7 @@ class mutable_buffer
constexpr size_t size() const noexcept { return _size; }
mutable_buffer &operator+=(size_t n) noexcept
{
// (std::min) is a workaround for when a min macro is defined
const auto shift = (std::min) (n, _size);
const auto shift = std::min(n, _size);
_data = static_cast<char *>(_data) + shift;
_size -= shift;
return *this;
Expand All @@ -1115,8 +1123,8 @@ class mutable_buffer

inline mutable_buffer operator+(const mutable_buffer &mb, size_t n) noexcept
{
return mutable_buffer(static_cast<char *>(mb.data()) + (std::min) (n, mb.size()),
mb.size() - (std::min) (n, mb.size()));
return mutable_buffer(static_cast<char *>(mb.data()) + std::min(n, mb.size()),
mb.size() - std::min(n, mb.size()));
}
inline mutable_buffer operator+(size_t n, const mutable_buffer &mb) noexcept
{
Expand All @@ -1142,7 +1150,7 @@ class const_buffer
constexpr size_t size() const noexcept { return _size; }
const_buffer &operator+=(size_t n) noexcept
{
const auto shift = (std::min) (n, _size);
const auto shift = std::min(n, _size);
_data = static_cast<const char *>(_data) + shift;
_size -= shift;
return *this;
Expand All @@ -1156,8 +1164,8 @@ class const_buffer
inline const_buffer operator+(const const_buffer &cb, size_t n) noexcept
{
return const_buffer(static_cast<const char *>(cb.data())
+ (std::min) (n, cb.size()),
cb.size() - (std::min) (n, cb.size()));
+ std::min(n, cb.size()),
cb.size() - std::min(n, cb.size()));
}
inline const_buffer operator+(size_t n, const const_buffer &cb) noexcept
{
Expand All @@ -1180,15 +1188,15 @@ constexpr mutable_buffer buffer(const mutable_buffer &mb) noexcept
}
inline mutable_buffer buffer(const mutable_buffer &mb, size_t n) noexcept
{
return mutable_buffer(mb.data(), (std::min) (mb.size(), n));
return mutable_buffer(mb.data(), std::min(mb.size(), n));
}
constexpr const_buffer buffer(const const_buffer &cb) noexcept
{
return cb;
}
inline const_buffer buffer(const const_buffer &cb, size_t n) noexcept
{
return const_buffer(cb.data(), (std::min) (cb.size(), n));
return const_buffer(cb.data(), std::min(cb.size(), n));
}

namespace detail
Expand Down Expand Up @@ -1241,7 +1249,7 @@ auto buffer_contiguous_sequence(Seq &&seq, size_t n_bytes) noexcept

const auto size = seq_size(seq);
return buffer(size != 0u ? std::addressof(*std::begin(seq)) : nullptr,
(std::min) (size * sizeof(T), n_bytes));
std::min(size * sizeof(T), n_bytes));
}

} // namespace detail
Expand Down Expand Up @@ -2050,7 +2058,7 @@ class socket_base
zmq_recv(_handle, buf.data(), buf.size(), static_cast<int>(flags));
if (nbytes >= 0) {
return recv_buffer_size{
(std::min) (static_cast<size_t>(nbytes), buf.size()),
std::min(static_cast<size_t>(nbytes), buf.size()),
static_cast<size_t>(nbytes)};
}
if (zmq_errno() == EAGAIN)
Expand Down Expand Up @@ -2778,7 +2786,7 @@ template<typename T = no_user_data> class poller_t
{
int rc = zmq_poller_size(const_cast<void *>(poller_ptr.get()));
ZMQ_ASSERT(rc >= 0);
return static_cast<size_t>((std::max) (rc, 0));
return static_cast<size_t>(std::max(rc, 0));
}
#endif

Expand Down Expand Up @@ -2900,4 +2908,15 @@ class timers

} // namespace zmq

#ifdef _WIN32
#ifdef WINDOWS_MIN
#define min WINDOWS_MIN
#undef WINDOWS_MIN
#endif
#ifdef WINDOWS_MAX
#define max WINDOWS_MAX
#undef WINDOWS_MAX
#endif
#endif

#endif // __ZMQ_HPP_INCLUDED__
Loading