mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
AK: Add header for generic shorthands
These are functions that can be expressed with just normal operators, but would be very repetetive.
This commit is contained in:
parent
f35efe9bc8
commit
dba6f0bc4b
Notes:
sideshowbarker
2024-07-17 22:55:25 +09:00
Author: https://github.com/frhun Commit: https://github.com/SerenityOS/serenity/commit/dba6f0bc4b Pull-request: https://github.com/SerenityOS/serenity/pull/14478 Issue: https://github.com/SerenityOS/serenity/issues/14420
1 changed files with 74 additions and 0 deletions
74
AK/GenericShorthands.h
Normal file
74
AK/GenericShorthands.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Frhun <serenitystuff@frhun.de>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
[[nodiscard]] bool first_is_one_of(T const to_compare, Ts const... valid_values)
|
||||
{
|
||||
return (... || (to_compare == valid_values));
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
[[nodiscard]] bool first_is_smaller_than_one_of(T const to_compare, Ts const... valid_values)
|
||||
{
|
||||
return (... || (to_compare < valid_values));
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
[[nodiscard]] bool first_is_smaller_or_equal_than_one_of(T const to_compare, Ts const... valid_values)
|
||||
{
|
||||
return (... || (to_compare <= valid_values));
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
[[nodiscard]] bool first_is_larger_than_one_of(T const to_compare, Ts const... valid_values)
|
||||
{
|
||||
return (... || (to_compare > valid_values));
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
[[nodiscard]] bool first_is_larger_or_equal_than_one_of(T const to_compare, Ts const... valid_values)
|
||||
{
|
||||
return (... || (to_compare >= valid_values));
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
[[nodiscard]] bool first_is_smaller_than_all_of(T const to_compare, Ts const... valid_values)
|
||||
{
|
||||
return (... && (to_compare < valid_values));
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
[[nodiscard]] bool first_is_smaller_or_equal_than_all_of(T const to_compare, Ts const... valid_values)
|
||||
{
|
||||
return (... && (to_compare <= valid_values));
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
[[nodiscard]] bool first_is_larger_than_all_of(T const to_compare, Ts const... valid_values)
|
||||
{
|
||||
return (... && (to_compare > valid_values));
|
||||
}
|
||||
|
||||
template<typename T, typename... Ts>
|
||||
[[nodiscard]] bool first_is_larger_or_equal_than_all_of(T const to_compare, Ts const... valid_values)
|
||||
{
|
||||
return (... && (to_compare >= valid_values));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
Loading…
Reference in a new issue