From 1d2ad781398d2a8743899eb54153998ca03ac090 Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Wed, 2 Apr 2025 05:25:26 -0500 Subject: More work on hash maps. --- include/fud_algorithm_no_dep.hpp | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 include/fud_algorithm_no_dep.hpp (limited to 'include/fud_algorithm_no_dep.hpp') 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 +#include + +namespace fud { + +// NOLINTBEGIN(bugprone-return-const-ref-from-parameter) + +template +concept LessThanComparable = requires(T lhs, T rhs) { + { lhs < rhs } -> std::convertible_to; +}; + +template +constexpr const T& min(const T& lhs, const T& rhs) +{ + if (lhs < rhs) { + return lhs; + } + return rhs; +} + +template +constexpr const T& max(const T& lhs, const T& rhs) +{ + if (lhs < rhs) { + return rhs; + } + return lhs; +} + +template +constexpr const T& max(const T& first, const T& second, Args&&... args) +{ + return max(first, max(second, std::forward(args)...)); +} + +template +constexpr const T& min(const T& first, const T& second, Args&&... args) +{ + return min(first, min(second, std::forward(args)...)); +} + +// NOLINTEND(bugprone-return-const-ref-from-parameter) + +} // namespace fud + +#endif -- cgit v1.2.3