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,
11 typename = void_t<>>
12struct ResultWantsAddFunction : std::false_type {};
13
14template <typename Result, typename Counter, typename Duration>
15struct ResultWantsAddFunction<
16 Result, Counter, Duration,
17 void_t<decltype(std::declval<Result>().Add(
18 std::declval<Counter>(), std::declval<Duration>(),
19 std::declval<Duration>()))>> : std::true_type {};
20
21template <typename Result, typename Counter, typename Duration>
22inline constexpr bool kResultWantsAddFunction =
23 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, Counter,
32 void_t<decltype(std::declval<Result&>() += std::declval<const Counter&>())>>
33 : std::true_type {};
34
35template <typename Result, typename Counter>
36inline constexpr bool kResultCanUseAddAssign =
37 ResultCanUseAddAssign<Result, Counter>::value;
38
39// Detect if a Counter provides a Reset function
40template <typename Counter, typename = void_t<>>
41struct CanReset : std::false_type {};
42
43template <typename Counter>
44struct CanReset<Counter, void_t<decltype(std::declval<Counter&>().Reset())>>
45 : std::true_type {};
46
47template <typename Counter>
48inline constexpr bool kCanReset = CanReset<Counter>::value;
49
50} // namespace utils::statistics::detail
51
52USERVER_NAMESPACE_END