summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AK/GenericShorthands.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/AK/GenericShorthands.h b/AK/GenericShorthands.h
new file mode 100644
index 0000000000..a39b57342a
--- /dev/null
+++ b/AK/GenericShorthands.h
@@ -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;