Branch data Line data Source code
1 : : #pragma once
2 : :
3 : : #include <cassert>
4 : : #include <cstddef>
5 : : #include <functional>
6 : : #include <limits>
7 : :
8 : : namespace sl3
9 : : {
10 : :
11 : : inline size_t
12 : 430 : as_size_t (int val)
13 : : {
14 : 430 : assert (val >= 0); // LCOV_EXCL_BR_LINE
15 : 430 : return static_cast<size_t> (val);
16 : : }
17 : :
18 : : inline size_t
19 : 12 : as_size_t (ptrdiff_t val)
20 : : {
21 : 12 : assert (val >= 0); // LCOV_EXCL_BR_LINE
22 : 12 : return static_cast<size_t> (val);
23 : : }
24 : :
25 : : inline int
26 : 8 : as_int (size_t val)
27 : : {
28 : 8 : assert (val < std::numeric_limits<int>::max ()); // LCOV_EXCL_BR_LINE
29 : 8 : return static_cast<int> (val);
30 : : }
31 : :
32 : : template <typename T1, typename T2>
33 : : bool
34 : 10 : is_less (const T1& a, const T2& b)
35 : : {
36 : : using common_type = std::common_type_t<T1, T2>;
37 : 20 : return std::less<common_type>{}(static_cast<common_type> (a),
38 : 10 : static_cast<common_type> (b));
39 : : }
40 : :
41 : : template <typename T1, typename T2>
42 : : bool
43 : 3 : is_greater (const T1& a, const T2& b)
44 : : {
45 : : using common_type = std::common_type_t<T1, T2>;
46 : 6 : return std::greater<common_type>{}(static_cast<common_type> (a),
47 : 3 : static_cast<common_type> (b));
48 : : }
49 : :
50 : : template <typename T1, typename T2>
51 : : bool
52 : 3 : is_less_equal (const T1& a, const T2& b)
53 : : {
54 : : using common_type = std::common_type_t<T1, T2>;
55 : 6 : return std::less_equal<common_type>{}(static_cast<common_type> (a),
56 : 3 : static_cast<common_type> (b));
57 : : }
58 : :
59 : : template <typename T1, typename T2>
60 : : bool
61 : 4 : is_equal (const T1& a, const T2& b)
62 : : {
63 : : using common_type = std::common_type_t<T1, T2>;
64 : 8 : return std::equal_to<common_type>{}(static_cast<common_type> (a),
65 : 4 : static_cast<common_type> (b));
66 : : }
67 : :
68 : : }
|