diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt --- a/libc/src/__support/CPP/CMakeLists.txt +++ b/libc/src/__support/CPP/CMakeLists.txt @@ -1,3 +1,9 @@ +add_header_library( + algorithm + HDRS + algorithm.h +) + add_header_library( array HDRS diff --git a/libc/src/__support/CPP/algorithm.h b/libc/src/__support/CPP/algorithm.h new file mode 100644 --- /dev/null +++ b/libc/src/__support/CPP/algorithm.h @@ -0,0 +1,29 @@ +//===-- A self contained equivalent of --------------*- 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 is +// they prove useful. +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_ALGORITHM_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_ALGORITHM_H + +namespace __llvm_libc { +namespace cpp { + +template const T &max(const T &a, const T &b) { + return (a < b) ? b : a; +} + +template 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 diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -143,6 +143,14 @@ ], ) +libc_support_library( + name = "__support_cpp_algorithm", + hdrs = ["src/__support/CPP/algorithm.h"], + deps = [ + ":libc_root", + ], +) + libc_support_library( name = "__support_cpp_array", hdrs = ["src/__support/CPP/array.h"],