2022-07-04 05:29:46 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2022, Frhun <serenitystuff@frhun.de>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-11-26 12:18:30 +01:00
|
|
|
#include <AK/Platform.h>
|
2025-01-07 16:23:23 +01:00
|
|
|
#include <AK/StdLibExtras.h>
|
2022-11-26 12:18:30 +01:00
|
|
|
|
2022-07-04 05:29:46 +02:00
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
|
|
template<typename T, typename... Ts>
|
2025-01-07 16:23:23 +01:00
|
|
|
[[nodiscard]] constexpr bool first_is_one_of(T&& to_compare, Ts&&... valid_values)
|
2022-07-04 05:29:46 +02:00
|
|
|
{
|
2025-01-07 16:23:23 +01:00
|
|
|
return (... || (forward<T>(to_compare) == forward<Ts>(valid_values)));
|
2022-07-04 05:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename... Ts>
|
2025-01-07 16:23:23 +01:00
|
|
|
[[nodiscard]] constexpr bool first_is_smaller_than_one_of(T&& to_compare, Ts&&... valid_values)
|
2022-07-04 05:29:46 +02:00
|
|
|
{
|
2025-01-07 16:23:23 +01:00
|
|
|
return (... || (forward<T>(to_compare) < forward<Ts>(valid_values)));
|
2022-07-04 05:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename... Ts>
|
2025-01-07 16:23:23 +01:00
|
|
|
[[nodiscard]] constexpr bool first_is_smaller_or_equal_than_one_of(T&& to_compare, Ts&&... valid_values)
|
2022-07-04 05:29:46 +02:00
|
|
|
{
|
2025-01-07 16:23:23 +01:00
|
|
|
return (... || (forward<T>(to_compare) <= forward<Ts>(valid_values)));
|
2022-07-04 05:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename... Ts>
|
2025-01-07 16:23:23 +01:00
|
|
|
[[nodiscard]] constexpr bool first_is_larger_than_one_of(T&& to_compare, Ts&&... valid_values)
|
2022-07-04 05:29:46 +02:00
|
|
|
{
|
2025-01-07 16:23:23 +01:00
|
|
|
return (... || (forward<T>(to_compare) > forward<Ts>(valid_values)));
|
2022-07-04 05:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename... Ts>
|
2025-01-07 16:23:23 +01:00
|
|
|
[[nodiscard]] constexpr bool first_is_larger_or_equal_than_one_of(T&& to_compare, Ts&&... valid_values)
|
2022-07-04 05:29:46 +02:00
|
|
|
{
|
2025-01-07 16:23:23 +01:00
|
|
|
return (... || (forward<T>(to_compare) >= forward<Ts>(valid_values)));
|
2022-07-04 05:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
2025-03-18 12:46:51 +00:00
|
|
|
template<typename T, typename... Ts>
|
|
|
|
|
[[nodiscard]] constexpr bool first_is_equal_to_all_of(T&& to_compare, Ts&&... valid_values)
|
|
|
|
|
{
|
|
|
|
|
return (... && (forward<T>(to_compare) == forward<Ts>(valid_values)));
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 05:29:46 +02:00
|
|
|
template<typename T, typename... Ts>
|
2025-01-07 16:23:23 +01:00
|
|
|
[[nodiscard]] constexpr bool first_is_smaller_than_all_of(T&& to_compare, Ts&&... valid_values)
|
2022-07-04 05:29:46 +02:00
|
|
|
{
|
2025-01-07 16:23:23 +01:00
|
|
|
return (... && (forward<T>(to_compare) < forward<Ts>(valid_values)));
|
2022-07-04 05:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename... Ts>
|
2025-01-07 16:23:23 +01:00
|
|
|
[[nodiscard]] constexpr bool first_is_smaller_or_equal_than_all_of(T&& to_compare, Ts&&... valid_values)
|
2022-07-04 05:29:46 +02:00
|
|
|
{
|
2025-01-07 16:23:23 +01:00
|
|
|
return (... && (forward<T>(to_compare) <= forward<Ts>(valid_values)));
|
2022-07-04 05:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename... Ts>
|
2025-01-07 16:23:23 +01:00
|
|
|
[[nodiscard]] constexpr bool first_is_larger_than_all_of(T&& to_compare, Ts&&... valid_values)
|
2022-07-04 05:29:46 +02:00
|
|
|
{
|
2025-01-07 16:23:23 +01:00
|
|
|
return (... && (forward<T>(to_compare) > forward<Ts>(valid_values)));
|
2022-07-04 05:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T, typename... Ts>
|
2025-01-07 16:23:23 +01:00
|
|
|
[[nodiscard]] constexpr bool first_is_larger_or_equal_than_all_of(T&& to_compare, Ts&&... valid_values)
|
2022-07-04 05:29:46 +02:00
|
|
|
{
|
2025-01-07 16:23:23 +01:00
|
|
|
return (... && (forward<T>(to_compare) >= forward<Ts>(valid_values)));
|
2022-07-04 05:29:46 +02:00
|
|
|
}
|
2025-05-13 07:06:33 -04:00
|
|
|
|
2022-07-04 05:29:46 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-26 12:18:30 +01:00
|
|
|
#if USING_AK_GLOBALLY
|
2025-03-18 12:46:51 +00:00
|
|
|
using AK::first_is_equal_to_all_of;
|
2022-07-04 05:29:46 +02:00
|
|
|
using AK::first_is_larger_or_equal_than_all_of;
|
|
|
|
|
using AK::first_is_larger_or_equal_than_one_of;
|
|
|
|
|
using AK::first_is_larger_than_all_of;
|
|
|
|
|
using AK::first_is_larger_than_one_of;
|
|
|
|
|
using AK::first_is_one_of;
|
|
|
|
|
using AK::first_is_smaller_or_equal_than_all_of;
|
|
|
|
|
using AK::first_is_smaller_or_equal_than_one_of;
|
|
|
|
|
using AK::first_is_smaller_than_all_of;
|
|
|
|
|
using AK::first_is_smaller_than_one_of;
|
2022-11-26 12:18:30 +01:00
|
|
|
#endif
|