[llvm] [libc] move in_place_t in utility (PR #65623)

Guillaume Chatelet via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 08:37:51 PDT 2023


https://github.com/gchatelet created https://github.com/llvm/llvm-project/pull/65623:

None

>From ff90c640218815cc027a97451be6b99e9c489565 Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Thu, 7 Sep 2023 15:36:41 +0000
Subject: [PATCH] [libc] move in_place_t in utility

---
 libc/src/__support/CPP/optional.h             |  8 -----
 libc/src/__support/CPP/utility.h              |  1 +
 libc/src/__support/CPP/utility/in_place.h     | 36 +++++++++++++++++++
 .../llvm-project-overlay/libc/BUILD.bazel     |  1 +
 4 files changed, 38 insertions(+), 8 deletions(-)
 create mode 100644 libc/src/__support/CPP/utility/in_place.h

diff --git a/libc/src/__support/CPP/optional.h b/libc/src/__support/CPP/optional.h
index bbf9188087c1b3b..07cc1d2adac65ae 100644
--- a/libc/src/__support/CPP/optional.h
+++ b/libc/src/__support/CPP/optional.h
@@ -16,11 +16,6 @@
 namespace __llvm_libc {
 namespace cpp {
 
-// Trivial in_place_t struct.
-struct in_place_t {
-  LIBC_INLINE constexpr explicit in_place_t() = default;
-};
-
 // Trivial nullopt_t struct.
 struct nullopt_t {
   LIBC_INLINE constexpr explicit nullopt_t() = default;
@@ -29,9 +24,6 @@ struct nullopt_t {
 // nullopt that can be used and returned.
 LIBC_INLINE_VAR constexpr nullopt_t nullopt{};
 
-// in_place that can be used in the constructor.
-LIBC_INLINE_VAR constexpr in_place_t in_place{};
-
 // This is very simple implementation of the std::optional class. It makes
 // several assumptions that the underlying type is trivially constructable,
 // copyable, or movable.
diff --git a/libc/src/__support/CPP/utility.h b/libc/src/__support/CPP/utility.h
index 105d3a21dc2b00d..9be50350292db61 100644
--- a/libc/src/__support/CPP/utility.h
+++ b/libc/src/__support/CPP/utility.h
@@ -11,6 +11,7 @@
 
 #include "src/__support/CPP/utility/declval.h"
 #include "src/__support/CPP/utility/forward.h"
+#include "src/__support/CPP/utility/in_place.h"
 #include "src/__support/CPP/utility/integer_sequence.h"
 #include "src/__support/CPP/utility/move.h"
 
diff --git a/libc/src/__support/CPP/utility/in_place.h b/libc/src/__support/CPP/utility/in_place.h
new file mode 100644
index 000000000000000..45c37066a4f1283
--- /dev/null
+++ b/libc/src/__support/CPP/utility/in_place.h
@@ -0,0 +1,36 @@
+//===-- in_place utility ----------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_IN_PLACE_H
+#define LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_IN_PLACE_H
+
+#include "src/__support/macros/attributes.h"
+
+#include <stddef.h> // size_t
+
+namespace __llvm_libc::cpp {
+
+// in_place
+struct in_place_t {
+  explicit in_place_t() = default;
+};
+LIBC_INLINE_VAR constexpr in_place_t in_place{};
+
+template <class T> struct in_place_type_t {
+  explicit in_place_type_t() = default;
+};
+template <class T> LIBC_INLINE_VAR constexpr in_place_type_t<T> in_place_type{};
+
+template <size_t I> struct in_place_index_t {
+  explicit in_place_index_t() = default;
+};
+template <size_t I>
+LIBC_INLINE_VAR constexpr in_place_index_t<I> in_place_index{};
+
+} // namespace __llvm_libc::cpp
+
+#endif // LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_IN_PLACE_H
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 0f35d3df4c49a1c..cdcb19340d0dbdf 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -344,6 +344,7 @@ libc_support_library(
         "src/__support/CPP/utility.h",
         "src/__support/CPP/utility/declval.h",
         "src/__support/CPP/utility/forward.h",
+        "src/__support/CPP/utility/in_place.h",
         "src/__support/CPP/utility/integer_sequence.h",
         "src/__support/CPP/utility/move.h",
     ],



More information about the llvm-commits mailing list