tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
cmp_equal.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_UTILITY_CMP_EQUAL_HPP
4#define TETL_UTILITY_CMP_EQUAL_HPP
5
9
10namespace etl {
11
20template <builtin_integer T, builtin_integer U>
21[[nodiscard]] constexpr auto cmp_equal(T t, U u) noexcept -> bool
22{
23 using UT = etl::make_unsigned_t<T>;
24 using UU = etl::make_unsigned_t<U>;
25
27 return t == u;
28 } else if constexpr (etl::is_signed_v<T>) {
29 return t < 0 ? false : UT(t) == u;
30 } else {
31 return u < 0 ? false : t == UU(u);
32 }
33}
34
35} // namespace etl
36
37#endif // TETL_UTILITY_CMP_EQUAL_HPP
constexpr auto cmp_equal(T t, U u) noexcept -> bool
Compare the values of two integers t and u. Unlike builtin comparison operators, negative signed inte...
Definition cmp_equal.hpp:21
Definition adjacent_find.hpp:8
constexpr bool is_signed_v
Definition is_signed.hpp:30
typename make_unsigned< T >::type make_unsigned_t
Definition make_unsigned.hpp:75