From dba6f0bc4bc5aa52b6d8a2b196df763b1d9a1078 Mon Sep 17 00:00:00 2001 From: FrHun <28605587+frhun@users.noreply.github.com> Date: Mon, 4 Jul 2022 05:29:46 +0200 Subject: [PATCH] AK: Add header for generic shorthands These are functions that can be expressed with just normal operators, but would be very repetetive. --- AK/GenericShorthands.h | 74 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 AK/GenericShorthands.h diff --git a/AK/GenericShorthands.h b/AK/GenericShorthands.h new file mode 100644 index 00000000000..a39b57342a5 --- /dev/null +++ b/AK/GenericShorthands.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022, Frhun + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +namespace AK { + +template +[[nodiscard]] bool first_is_one_of(T const to_compare, Ts const... valid_values) +{ + return (... || (to_compare == valid_values)); +} + +template +[[nodiscard]] bool first_is_smaller_than_one_of(T const to_compare, Ts const... valid_values) +{ + return (... || (to_compare < valid_values)); +} + +template +[[nodiscard]] bool first_is_smaller_or_equal_than_one_of(T const to_compare, Ts const... valid_values) +{ + return (... || (to_compare <= valid_values)); +} + +template +[[nodiscard]] bool first_is_larger_than_one_of(T const to_compare, Ts const... valid_values) +{ + return (... || (to_compare > valid_values)); +} + +template +[[nodiscard]] bool first_is_larger_or_equal_than_one_of(T const to_compare, Ts const... valid_values) +{ + return (... || (to_compare >= valid_values)); +} + +template +[[nodiscard]] bool first_is_smaller_than_all_of(T const to_compare, Ts const... valid_values) +{ + return (... && (to_compare < valid_values)); +} + +template +[[nodiscard]] bool first_is_smaller_or_equal_than_all_of(T const to_compare, Ts const... valid_values) +{ + return (... && (to_compare <= valid_values)); +} + +template +[[nodiscard]] bool first_is_larger_than_all_of(T const to_compare, Ts const... valid_values) +{ + return (... && (to_compare > valid_values)); +} + +template +[[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;