[libc-commits] [PATCH] D157405: [libc] add the CPP algorithm header for min/max

Guillaume Chatelet via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Aug 8 08:50:34 PDT 2023


gchatelet created this revision.
gchatelet added a reviewer: sivachandra.
Herald added projects: libc-project, All.
Herald added a subscriber: libc-commits.
gchatelet requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157405

Files:
  libc/src/__support/CPP/CMakeLists.txt
  libc/src/__support/CPP/algorithm.h
  utils/bazel/llvm-project-overlay/libc/BUILD.bazel


Index: utils/bazel/llvm-project-overlay/libc/BUILD.bazel
===================================================================
--- utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ 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"],
Index: libc/src/__support/CPP/algorithm.h
===================================================================
--- /dev/null
+++ libc/src/__support/CPP/algorithm.h
@@ -0,0 +1,29 @@
+//===-- 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 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 <class T> const T &max(const T &a, const T &b) {
+  return (a < b) ? b : a;
+}
+
+template <class T> 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
Index: libc/src/__support/CPP/CMakeLists.txt
===================================================================
--- libc/src/__support/CPP/CMakeLists.txt
+++ libc/src/__support/CPP/CMakeLists.txt
@@ -1,3 +1,9 @@
+add_header_library(
+  algorithm
+  HDRS
+    algorithm.h
+)
+
 add_header_library(
   array
   HDRS


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157405.548244.patch
Type: text/x-patch
Size: 2004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230808/92c343c8/attachment.bin>


More information about the libc-commits mailing list