123 lines
3.7 KiB
Markdown
123 lines
3.7 KiB
Markdown
[utility.intcmp]
|
||
|
||
# 22 General utilities library [[utilities]](./#utilities)
|
||
|
||
## 22.2 Utility components [[utility]](utility#intcmp)
|
||
|
||
### 22.2.7 Integer comparison functions [utility.intcmp]
|
||
|
||
[ð](#lib:cmp_equal)
|
||
|
||
`template<class T, class U>
|
||
constexpr bool cmp_equal(T t, U u) noexcept;
|
||
`
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L546)
|
||
|
||
*Mandates*: Both T and U are standard integer types or
|
||
extended integer types ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#1.sentence-1)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L551)
|
||
|
||
*Effects*: Equivalent to:using UT = make_unsigned_t<T>;using UU = make_unsigned_t<U>;if constexpr (is_signed_v<T> == is_signed_v<U>)return t == u;else if constexpr (is_signed_v<T>)return t < 0 ? false : UT(t) == u;elsereturn u < 0 ? false : t == UU(u);
|
||
|
||
[ð](#lib:cmp_not_equal)
|
||
|
||
`template<class T, class U>
|
||
constexpr bool cmp_not_equal(T t, U u) noexcept;
|
||
`
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L573)
|
||
|
||
*Effects*: Equivalent to: return !cmp_equal(t, u);
|
||
|
||
[ð](#lib:cmp_less)
|
||
|
||
`template<class T, class U>
|
||
constexpr bool cmp_less(T t, U u) noexcept;
|
||
`
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L585)
|
||
|
||
*Mandates*: Both T and U are standard integer types or
|
||
extended integer types ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#4.sentence-1)
|
||
|
||
[5](#5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L590)
|
||
|
||
*Effects*: Equivalent to:using UT = make_unsigned_t<T>;using UU = make_unsigned_t<U>;if constexpr (is_signed_v<T> == is_signed_v<U>)return t < u;else if constexpr (is_signed_v<T>)return t < 0 ? true : UT(t) < u;elsereturn u < 0 ? false : t < UU(u);
|
||
|
||
[ð](#lib:cmp_greater)
|
||
|
||
`template<class T, class U>
|
||
constexpr bool cmp_greater(T t, U u) noexcept;
|
||
`
|
||
|
||
[6](#6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L612)
|
||
|
||
*Effects*: Equivalent to: return cmp_less(u, t);
|
||
|
||
[ð](#lib:cmp_less_equal)
|
||
|
||
`template<class T, class U>
|
||
constexpr bool cmp_less_equal(T t, U u) noexcept;
|
||
`
|
||
|
||
[7](#7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L624)
|
||
|
||
*Effects*: Equivalent to: return !cmp_greater(t, u);
|
||
|
||
[ð](#lib:cmp_greater_equal)
|
||
|
||
`template<class T, class U>
|
||
constexpr bool cmp_greater_equal(T t, U u) noexcept;
|
||
`
|
||
|
||
[8](#8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L636)
|
||
|
||
*Effects*: Equivalent to: return !cmp_less(t, u);
|
||
|
||
[ð](#lib:in_range)
|
||
|
||
`template<class R, class T>
|
||
constexpr bool in_range(T t) noexcept;
|
||
`
|
||
|
||
[9](#9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L648)
|
||
|
||
*Mandates*: Both T and R are standard integer types or
|
||
extended integer types ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types"))[.](#9.sentence-1)
|
||
|
||
[10](#10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L653)
|
||
|
||
*Effects*: Equivalent to:return cmp_greater_equal(t, numeric_limits<R>::min()) && cmp_less_equal(t, numeric_limits<R>::max());
|
||
|
||
[11](#11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L662)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
These function templates cannot be used to comparebyte,char,char8_t,char16_t,char32_t,wchar_t, andbool[.](#11.sentence-1)
|
||
|
||
â *end note*]
|