Skip to content

Commit 260036a

Browse files
authored
[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
1 parent f8a1c8b commit 260036a

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

libc/src/__support/CPP/optional.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
namespace __llvm_libc {
1717
namespace cpp {
1818

19-
// Trivial in_place_t struct.
20-
struct in_place_t {
21-
LIBC_INLINE constexpr explicit in_place_t() = default;
22-
};
23-
2419
// Trivial nullopt_t struct.
2520
struct nullopt_t {
2621
LIBC_INLINE constexpr explicit nullopt_t() = default;
@@ -29,9 +24,6 @@ struct nullopt_t {
2924
// nullopt that can be used and returned.
3025
LIBC_INLINE_VAR constexpr nullopt_t nullopt{};
3126

32-
// in_place that can be used in the constructor.
33-
LIBC_INLINE_VAR constexpr in_place_t in_place{};
34-
3527
// This is very simple implementation of the std::optional class. It makes
3628
// several assumptions that the underlying type is trivially constructable,
3729
// copyable, or movable.

libc/src/__support/CPP/utility.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "src/__support/CPP/utility/declval.h"
1313
#include "src/__support/CPP/utility/forward.h"
14+
#include "src/__support/CPP/utility/in_place.h"
1415
#include "src/__support/CPP/utility/integer_sequence.h"
1516
#include "src/__support/CPP/utility/move.h"
1617

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===-- in_place utility ----------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_IN_PLACE_H
9+
#define LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_IN_PLACE_H
10+
11+
#include "src/__support/macros/attributes.h"
12+
13+
#include <stddef.h> // size_t
14+
15+
namespace __llvm_libc::cpp {
16+
17+
// in_place
18+
struct in_place_t {
19+
explicit in_place_t() = default;
20+
};
21+
LIBC_INLINE_VAR constexpr in_place_t in_place{};
22+
23+
template <class T> struct in_place_type_t {
24+
explicit in_place_type_t() = default;
25+
};
26+
template <class T> LIBC_INLINE_VAR constexpr in_place_type_t<T> in_place_type{};
27+
28+
template <size_t I> struct in_place_index_t {
29+
explicit in_place_index_t() = default;
30+
};
31+
template <size_t I>
32+
LIBC_INLINE_VAR constexpr in_place_index_t<I> in_place_index{};
33+
34+
} // namespace __llvm_libc::cpp
35+
36+
#endif // LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_IN_PLACE_H

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ libc_support_library(
344344
"src/__support/CPP/utility.h",
345345
"src/__support/CPP/utility/declval.h",
346346
"src/__support/CPP/utility/forward.h",
347+
"src/__support/CPP/utility/in_place.h",
347348
"src/__support/CPP/utility/integer_sequence.h",
348349
"src/__support/CPP/utility/move.h",
349350
],

0 commit comments

Comments
 (0)