From Jason Turner

[utility.intcmp]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp5bun4u3i/{from.md → to.md} +91 -0
tmp/tmp5bun4u3i/{from.md → to.md} RENAMED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Integer comparison functions <a id="utility.intcmp">[[utility.intcmp]]</a>
2
+
3
+ ``` cpp
4
+ template<class T, class U>
5
+ constexpr bool cmp_equal(T t, U u) noexcept;
6
+ ```
7
+
8
+ *Mandates:* Both `T` and `U` are standard integer types or extended
9
+ integer types [[basic.fundamental]].
10
+
11
+ *Effects:* Equivalent to:
12
+
13
+ ``` cpp
14
+ using UT = make_unsigned_t<T>;
15
+ using UU = make_unsigned_t<U>;
16
+ if constexpr (is_signed_v<T> == is_signed_v<U>)
17
+ return t == u;
18
+ else if constexpr (is_signed_v<T>)
19
+ return t < 0 ? false : UT(t) == u;
20
+ else
21
+ return u < 0 ? false : t == UU(u);
22
+ ```
23
+
24
+ ``` cpp
25
+ template<class T, class U>
26
+ constexpr bool cmp_not_equal(T t, U u) noexcept;
27
+ ```
28
+
29
+ *Effects:* Equivalent to: `return !cmp_equal(t, u);`
30
+
31
+ ``` cpp
32
+ template<class T, class U>
33
+ constexpr bool cmp_less(T t, U u) noexcept;
34
+ ```
35
+
36
+ *Mandates:* Both `T` and `U` are standard integer types or extended
37
+ integer types [[basic.fundamental]].
38
+
39
+ *Effects:* Equivalent to:
40
+
41
+ ``` cpp
42
+ using UT = make_unsigned_t<T>;
43
+ using UU = make_unsigned_t<U>;
44
+ if constexpr (is_signed_v<T> == is_signed_v<U>)
45
+ return t < u;
46
+ else if constexpr (is_signed_v<T>)
47
+ return t < 0 ? true : UT(t) < u;
48
+ else
49
+ return u < 0 ? false : t < UU(u);
50
+ ```
51
+
52
+ ``` cpp
53
+ template<class T, class U>
54
+ constexpr bool cmp_greater(T t, U u) noexcept;
55
+ ```
56
+
57
+ *Effects:* Equivalent to: `return cmp_less(u, t);`
58
+
59
+ ``` cpp
60
+ template<class T, class U>
61
+ constexpr bool cmp_less_equal(T t, U u) noexcept;
62
+ ```
63
+
64
+ *Effects:* Equivalent to: `return !cmp_greater(t, u);`
65
+
66
+ ``` cpp
67
+ template<class T, class U>
68
+ constexpr bool cmp_greater_equal(T t, U u) noexcept;
69
+ ```
70
+
71
+ *Effects:* Equivalent to: `return !cmp_less(t, u);`
72
+
73
+ ``` cpp
74
+ template<class R, class T>
75
+ constexpr bool in_range(T t) noexcept;
76
+ ```
77
+
78
+ *Mandates:* Both `T` and `R` are standard integer types or extended
79
+ integer types [[basic.fundamental]].
80
+
81
+ *Effects:* Equivalent to:
82
+
83
+ ``` cpp
84
+ return cmp_greater_equal(t, numeric_limits<R>::min()) &&
85
+ cmp_less_equal(t, numeric_limits<R>::max());
86
+ ```
87
+
88
+ [*Note 1*: These function templates cannot be used to compare `byte`,
89
+ `char`, `char8_t`, `char16_t`, `char32_t`, `wchar_t`, and
90
+ `bool`. — *end note*]
91
+