Skip to content

Commit 9b08c41

Browse files
committed
add slice const conversion
1 parent 0a1eadc commit 9b08c41

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ For faster parallel builds, you can instead generate [ninja](https://ninja-build
285285
- Types
286286
- [ ] Result<T,E>
287287
- [ ] Map: don't store hashes of integer keys
288+
- [ ] Opt: specializations for null representations
288289
- Allocators
289290
- [ ] Per-thread pools
290291
- Misc

rpp/slice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ struct Slice {
4545
length_ = init.size();
4646
}
4747

48+
operator Slice<const T>() const noexcept
49+
requires(!Const<T>)
50+
{
51+
return Slice<const T>{data_, length_};
52+
}
53+
4854
constexpr Slice(const Slice& src) noexcept = default;
4955
constexpr Slice& operator=(const Slice& src) noexcept = default;
5056

test/arrays.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ i32 main() {
106106
static_assert(Same<decltype(deduct4), Slice<i32>>);
107107
auto deduct5 = constv.slice();
108108
static_assert(Same<decltype(deduct5), Slice<const i32>>);
109+
auto deduct6 = Slice<const i32>{deduct4};
110+
static_assert(Same<decltype(deduct6), Slice<const i32>>);
109111

110112
v.pop();
111113
assert(v.length() == 2);

0 commit comments

Comments
 (0)