Skip to content

Commit

Permalink
Refactored timeout.h by adding template ctr and removed redundant ctrs (
Browse files Browse the repository at this point in the history
  • Loading branch information
laxerhd committed Oct 26, 2024
1 parent 5f47552 commit b9f0653
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions include/cpr/timeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ namespace cpr {

class Timeout {
public:
// Template constructor to accept any chrono duration type and convert it to milliseconds
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Timeout(const std::chrono::milliseconds& duration) : ms{duration} {}
template <typename Rep, typename Period>
Timeout(const std::chrono::duration<Rep, Period>& duration)
: ms{std::chrono::duration_cast<std::chrono::milliseconds>(duration)} {}

// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Timeout(const std::int32_t& milliseconds) : Timeout{std::chrono::milliseconds(milliseconds)} {}
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
Timeout(const std::chrono::seconds& duration) : ms{std::chrono::milliseconds(duration).count()} {}

// No way around since curl uses a long here.
// NOLINTNEXTLINE(google-runtime-int)
Expand Down

0 comments on commit b9f0653

Please sign in to comment.