YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/util/std_util.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#ifndef YB_UTIL_STD_UTIL_H
15
#define YB_UTIL_STD_UTIL_H
16
17
// Implementation of std functions we want to use, but cannot until we switch to newer C++.
18
19
namespace yb {
20
21
namespace std_util {
22
23
// cmp_* code is based on examples from https://en.cppreference.com/w/cpp/utility/intcmp
24
// TODO: remove once we switch to C++20:
25
26
template <class T, class U>
27
constexpr std::enable_if_t<std::is_signed<T>::value == std::is_signed<U>::value, bool> cmp_equal(
28
    T t, U u) noexcept {
29
  return t == u;
30
}
31
32
template <class T, class U>
33
constexpr std::enable_if_t<std::is_signed<T>::value && !std::is_signed<U>::value, bool> cmp_equal(
34
    T t, U u) noexcept {
35
  using UT = std::make_unsigned_t<T>;
36
  return t < 0 ? false : UT(t) == u;
37
}
38
39
template <class T, class U>
40
constexpr std::enable_if_t<!std::is_signed<T>::value && std::is_signed<U>::value, bool> cmp_equal(
41
    T t, U u) noexcept {
42
  using UU = std::make_unsigned_t<U>;
43
  return u < 0 ? false : t == UU(u);
44
}
45
46
template <class T, class U>
47
constexpr std::enable_if_t<std::is_signed<T>::value == std::is_signed<U>::value, bool> cmp_less(
48
    T t, U u) noexcept {
49
  return t < u;
50
}
51
52
template <class T, class U>
53
constexpr std::enable_if_t<std::is_signed<T>::value && !std::is_signed<U>::value, bool> cmp_less(
54
23.9M
    T t, U u) noexcept {
55
23.9M
  using UT = std::make_unsigned_t<T>;
56
23.9M
  return t < 0 ? true : UT(t) < u;
57
23.9M
}
_ZN2yb8std_util8cmp_lessIljEENSt3__19enable_ifIXaasr3std9is_signedIT_EE5valuentsr3std9is_signedIT0_EE5valueEbE4typeES4_S5_
Line
Count
Source
54
23.9M
    T t, U u) noexcept {
55
23.9M
  using UT = std::make_unsigned_t<T>;
56
23.9M
  return t < 0 ? true : UT(t) < u;
57
23.9M
}
_ZN2yb8std_util8cmp_lessIimEENSt3__19enable_ifIXaasr3std9is_signedIT_EE5valuentsr3std9is_signedIT0_EE5valueEbE4typeES4_S5_
Line
Count
Source
54
11.2k
    T t, U u) noexcept {
55
11.2k
  using UT = std::make_unsigned_t<T>;
56
11.2k
  return t < 0 ? true : UT(t) < u;
57
11.2k
}
58
59
template <class T, class U>
60
constexpr std::enable_if_t<!std::is_signed<T>::value && std::is_signed<U>::value, bool> cmp_less(
61
688k
    T t, U u) noexcept {
62
688k
  using UU = std::make_unsigned_t<U>;
63
688k
  return u < 0 ? false : t < UU(u);
64
688k
}
65
66
template <class T, class U>
67
constexpr bool cmp_not_equal(T t, U u) noexcept {
68
  return !cmp_equal(t, u);
69
}
70
71
template <class T, class U>
72
11.2k
constexpr bool cmp_greater(T t, U u) noexcept {
73
11.2k
  return cmp_less(u, t);
74
11.2k
}
75
76
template <class T, class U>
77
constexpr bool cmp_less_equal(T t, U u) noexcept {
78
  return !cmp_greater(t, u);
79
}
80
81
template <class T, class U>
82
688k
constexpr bool cmp_greater_equal(T t, U u) noexcept {
83
688k
  return !cmp_less(t, u);
84
688k
}
85
86
}  // namespace std_util
87
88
} // namespace yb
89
90
#endif  // YB_UTIL_STD_UTIL_H