diff options
| author | Guillaume Chatelet <gchatelet@google.com> | 2023-08-09 09:50:35 +0000 |
|---|---|---|
| committer | Guillaume Chatelet <gchatelet@google.com> | 2023-08-10 08:00:18 +0000 |
| commit | bc2b1193b5a205c288d6f2e1f6562f311fba77f4 (patch) | |
| tree | c36d66e3c313c3f7c131b0d0452428811bca9c99 /libc/src/__support/CPP/algorithm.h | |
| parent | ff5cb1ec6209e939adef52b2f0ddde23c370afd6 (diff) | |
[libc] add the CPP algorithm header for min/max
Reviewed By: jhuber6, sivachandra
Differential Revision: https://reviews.llvm.org/D157405
Diffstat (limited to 'libc/src/__support/CPP/algorithm.h')
| -rw-r--r-- | libc/src/__support/CPP/algorithm.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libc/src/__support/CPP/algorithm.h b/libc/src/__support/CPP/algorithm.h new file mode 100644 index 000000000000..6b17f58ea462 --- /dev/null +++ b/libc/src/__support/CPP/algorithm.h @@ -0,0 +1,31 @@ +//===-- A self contained equivalent of <algorithm> --------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// This file is minimalist on purpose but can receive a few more function if +// they prove useful. +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_ALGORITHM_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_ALGORITHM_H + +#include "src/__support/macros/attributes.h" // LIBC_INLINE + +namespace __llvm_libc { +namespace cpp { + +template <class T> LIBC_INLINE constexpr const T &max(const T &a, const T &b) { + return (a < b) ? b : a; +} + +template <class T> LIBC_INLINE constexpr const T &min(const T &a, const T &b) { + return (a < b) ? a : b; +} + +} // namespace cpp +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_ALGORITHM_H |
