summaryrefslogtreecommitdiff
path: root/include/fud_algorithm_no_dep.hpp
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2025-04-02 05:25:26 -0500
committerDominick Allen <djallen@librehumanitas.org>2025-04-02 05:25:26 -0500
commit1d2ad781398d2a8743899eb54153998ca03ac090 (patch)
treec935ffe2880b7101d2d9162a76c8bed5be931ebb /include/fud_algorithm_no_dep.hpp
parent8b0bc70db73b48d833a3b5791e55921768cf6932 (diff)
More work on hash maps.
Diffstat (limited to 'include/fud_algorithm_no_dep.hpp')
-rw-r--r--include/fud_algorithm_no_dep.hpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/include/fud_algorithm_no_dep.hpp b/include/fud_algorithm_no_dep.hpp
new file mode 100644
index 0000000..a69761c
--- /dev/null
+++ b/include/fud_algorithm_no_dep.hpp
@@ -0,0 +1,72 @@
+/*
+ * libfud
+ * Copyright 2025 Dominick Allen
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/** \file This file breaks a dependency chain; min and max are intended to be part of fud_algorithm.
+ *
+ * Consumers are encouraged to include fud_algorithm.hpp instead.
+ */
+
+#ifndef FUD_ALGORITHM_NO_DEP_HPP
+#define FUD_ALGORITHM_NO_DEP_HPP
+
+#include <concepts>
+#include <utility>
+
+namespace fud {
+
+// NOLINTBEGIN(bugprone-return-const-ref-from-parameter)
+
+template <typename T>
+concept LessThanComparable = requires(T lhs, T rhs) {
+ { lhs < rhs } -> std::convertible_to<bool>;
+};
+
+template <LessThanComparable T>
+constexpr const T& min(const T& lhs, const T& rhs)
+{
+ if (lhs < rhs) {
+ return lhs;
+ }
+ return rhs;
+}
+
+template <LessThanComparable T>
+constexpr const T& max(const T& lhs, const T& rhs)
+{
+ if (lhs < rhs) {
+ return rhs;
+ }
+ return lhs;
+}
+
+template <typename T, typename... Args>
+constexpr const T& max(const T& first, const T& second, Args&&... args)
+{
+ return max(first, max(second, std::forward<Args>(args)...));
+}
+
+template <typename T, typename... Args>
+constexpr const T& min(const T& first, const T& second, Args&&... args)
+{
+ return min(first, min(second, std::forward<Args>(args)...));
+}
+
+// NOLINTEND(bugprone-return-const-ref-from-parameter)
+
+} // namespace fud
+
+#endif