Skip to content

Commit c2269c8

Browse files
[ADT] Move llvm::to_address to STLForwardCompat.h (NFC) (#166315)
This patch moves llvm::to_address to STLForwardCompat.h, a collection of backports from C++20 and beyond.
1 parent a2495ff commit c2269c8

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,16 +2600,6 @@ bool hasNItemsOrLess(ContainerTy &&C, unsigned N) {
26002600
return hasNItemsOrLess(adl_begin(C), adl_end(C), N);
26012601
}
26022602

2603-
/// Returns a raw pointer that represents the same address as the argument.
2604-
///
2605-
/// This implementation can be removed once we move to C++20 where it's defined
2606-
/// as std::to_address().
2607-
///
2608-
/// The std::pointer_traits<>::to_address(p) variations of these overloads has
2609-
/// not been implemented.
2610-
template <class Ptr> auto to_address(const Ptr &P) { return P.operator->(); }
2611-
template <class T> constexpr T *to_address(T *P) { return P; }
2612-
26132603
// Detect incomplete types, relying on the fact that their size is unknown.
26142604
namespace detail {
26152605
template <typename T> using has_sizeof = decltype(sizeof(T));

llvm/include/llvm/ADT/STLForwardCompat.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ struct identity // NOLINT(readability-identifier-naming)
134134
}
135135
};
136136

137+
/// Returns a raw pointer that represents the same address as the argument.
138+
///
139+
/// This implementation can be removed once we move to C++20 where it's defined
140+
/// as std::to_address().
141+
///
142+
/// The std::pointer_traits<>::to_address(p) variations of these overloads has
143+
/// not been implemented.
144+
template <class Ptr> auto to_address(const Ptr &P) { return P.operator->(); }
145+
template <class T> constexpr T *to_address(T *P) { return P; }
146+
137147
//===----------------------------------------------------------------------===//
138148
// Features from C++23
139149
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)