[libc-commits] [libc] 260036a - [libc] move in_place_t in utility (#65623)
via libc-commits
libc-commits at lists.llvm.org
Thu Sep 7 09:12:53 PDT 2023
Author: Guillaume Chatelet
Date: 2023-09-07T18:12:50+02:00
New Revision: 260036ab1e722202b90a76bbc881c372cd84b563
URL: https://github.com/llvm/llvm-project/commit/260036ab1e722202b90a76bbc881c372cd84b563
DIFF: https://github.com/llvm/llvm-project/commit/260036ab1e722202b90a76bbc881c372cd84b563.diff
LOG: [libc] move in_place_t in utility (#65623)
This is needed because `cpp::in_place_t` is also used by `cpp::expected`
https://en.cppreference.com/w/cpp/utility/in_place
Added:
libc/src/__support/CPP/utility/in_place.h
Modified:
libc/src/__support/CPP/optional.h
libc/src/__support/CPP/utility.h
utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Removed:
################################################################################
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 3ed14e21a215317..a976f04ae4096ba 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 libc-commits
mailing list