Skip to content

Commit 7f14aff

Browse files
committed
[NFC] Give NullablePtr some PointerLikeTypeTraits
Allows it to be used in PointerIntPair and PointerUnion.
1 parent d02b34c commit 7f14aff

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/swift/Basic/NullablePtr.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <cassert>
2121
#include <cstddef>
2222
#include <type_traits>
23+
#include "llvm/Support/PointerLikeTypeTraits.h"
2324

2425
namespace swift {
2526
/// NullablePtr pointer wrapper - NullablePtr is used for APIs where a
@@ -81,4 +82,19 @@ class NullablePtr {
8182

8283
} // end namespace swift
8384

85+
namespace llvm {
86+
template <typename T> struct PointerLikeTypeTraits;
87+
template <typename T> struct PointerLikeTypeTraits<swift::NullablePtr<T>> {
88+
public:
89+
static inline void *getAsVoidPointer(swift::NullablePtr<T> ptr) {
90+
return static_cast<void *>(ptr.getPtrOrNull());
91+
}
92+
static inline swift::NullablePtr<T> getFromVoidPointer(void *ptr) {
93+
return swift::NullablePtr<T>(static_cast<T*>(ptr));
94+
}
95+
enum { NumLowBitsAvailable = PointerLikeTypeTraits<T *>::NumLowBitsAvailable };
96+
};
97+
98+
}
99+
84100
#endif // SWIFT_BASIC_NULLABLEPTR_H

0 commit comments

Comments
 (0)