Skip to content

Commit 730cf6c

Browse files
committed
Add a helper form of ArrayRefView to create a cast<> projection.
1 parent 3a808ff commit 730cf6c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

include/swift/Basic/ArrayRefView.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define SWIFT_BASIC_ARRAYREFVIEW_H
2020

2121
#include "llvm/ADT/ArrayRef.h"
22+
#include "llvm/Support/Casting.h"
2223

2324
namespace swift {
2425

@@ -152,6 +153,20 @@ class ArrayRefView {
152153
}
153154
};
154155

156+
/// Helper for \c CastArrayRefView that casts the original type to the
157+
/// projected type.
158+
template<typename Projected, typename Orig>
159+
inline Projected *arrayRefViewCastHelper(const Orig &value) {
160+
using llvm::cast_or_null;
161+
return cast_or_null<Projected>(value);
162+
}
163+
164+
/// An ArrayRefView that performs a cast_or_null on each element in the
165+
/// underlying ArrayRef.
166+
template<typename Orig, typename Projected>
167+
using CastArrayRefView =
168+
ArrayRefView<Orig, Projected *, arrayRefViewCastHelper<Projected, Orig>>;
169+
155170
} // end namespace swift
156171

157172
#endif // SWIFT_BASIC_ARRAYREFVIEW_H

0 commit comments

Comments
 (0)