Skip to content

Conversation

@cacharle
Copy link
Contributor

Makes the bindings slightly easier to use when dealing with durations. With the bindings handling the cast instead of the user

@coveralls
Copy link

coveralls commented Oct 16, 2025

Pull Request Test Coverage Report for Build 18631924080

Details

  • 14 of 14 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 88.424%

Totals Coverage Status
Change from base Build 17909983277: 0.05%
Covered Lines: 909
Relevant Lines: 1028

💛 - Coveralls

@cacharle cacharle force-pushed the std-chrono-any-duration branch from d2be5ed to 79b3bd2 Compare October 17, 2025 16:10
@cacharle
Copy link
Contributor Author

Not sure how to unit test this properly..

Is there a "check if compiles" kind of unit tests for catch2?

@cacharle cacharle marked this pull request as ready for review October 17, 2025 16:11

#ifdef ZMQ_CPP11
template<typename Duration = std::chrono::milliseconds>
bool check_event(Duration timeout = std::chrono::milliseconds{0})
Copy link
Member

Choose a reason for hiding this comment

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

check_event() is ambiguous

{
return detail::poll(items, nitems, static_cast<long>(timeout.count()));
auto timeout_ms = std::chrono::duration_cast<std::chrono::milliseconds>(timeout);
return detail::poll(items, nitems, static_cast<long>(timeout_ms.count()));
Copy link
Member

Choose a reason for hiding this comment

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

One concern is that for poll and poller, -1 millisecond is a special value that may need special handling. E.g. does -1s or -1ns do the right thing?

If the value of timeout is -1, zmq_poll() shall block indefinitely until a requested event has occurred on at least one zmq_pollitem_t.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Negative duration work:

#include <print>
#include <optional>
#include <chrono>

int main()
{
    std::chrono::milliseconds ms{-1};
    std::println("{}", ms);
    std::println("{}", ms.count());

    std::chrono::nanoseconds ns{-1};
    std::println("{}", ns);
    std::println("{}", ns.count());
    return 0;
}

Output:

$ g++ -std=c++23 temp.cpp && ./a.out
-1ms
-1
-1ns
-1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With c++17:

int main()
{
    std::chrono::milliseconds ms{-1};
    // std::cout << ms << '\n';
    std::cout << ms.count() << '\n';

    std::chrono::nanoseconds ns{-1};
    // std::cout << ns << '\n';
    std::cout << ns.count() << '\n';
    return 0;
}

Output:

$ g++ -std=c++17 temp.cpp && ./a.out
-1
-1

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but you cast the input Duration to milliseconds then pass that to libzmq.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, casting from -1ns to ms give 0ms, I'll change that

@gummif
Copy link
Member

gummif commented Oct 19, 2025

To check if something compiles or not you could use C++20/23 and concept or requires expressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants