userver: userver/utils/statistics/recentperiod_detail.hpp Source File
Loading...
Searching...
No Matches
recentperiod_detail.hpp
1#pragma once
2
3#include <userver/utils/void_t.hpp>
4
5USERVER_NAMESPACE_BEGIN
6
7namespace utils::statistics::detail {
8
9// Detect if the result type provides Add(Counter, Duration, Duration) function
10template <typename Result, typename Counter, typename Duration, typename = void_t<>>
11struct ResultWantsAddFunction : std::false_type {};
12
13template <typename Result, typename Counter, typename Duration>
14struct ResultWantsAddFunction<
15 Result,
16 Counter,
17 Duration,
18 void_t<decltype(std::declval<Result>()
19 .Add(std::declval<Counter>(), std::declval<Duration>(), std::declval<Duration>()))>>
20 : std::true_type {};
21
22template <typename Result, typename Counter, typename Duration>
23inline constexpr bool kResultWantsAddFunction = ResultWantsAddFunction<Result, Counter, Duration>::value;
24
25// Detect if a counter can be added to the result
26template <typename Result, typename Counter, typename = void_t<>>
27struct ResultCanUseAddAssign : std::false_type {};
28
29template <typename Result, typename Counter>
30struct ResultCanUseAddAssign<
31 Result,
32 Counter,
33 void_t<decltype(std::declval<Result&>() += std::declval<const Counter&>())>> : std::true_type {};
34
35template <typename Result, typename Counter>
36inline constexpr bool kResultCanUseAddAssign = ResultCanUseAddAssign<Result, Counter>::value;
37
38// Detect if a Counter provides a Reset function
39template <typename Counter, typename = void_t<>>
40struct CanReset : std::false_type {};
41
42template <typename Counter>
43struct CanReset<Counter, void_t<decltype(std::declval<Counter&>().Reset())>> : std::true_type {};
44
45template <typename Counter>
46inline constexpr bool kCanReset = CanReset<Counter>::value;
47
48} // namespace utils::statistics::detail
49
50USERVER_NAMESPACE_END