Skip to content

Commit

Permalink
add slice const conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNumbat committed Apr 10, 2024
1 parent 0a1eadc commit 9b08c41
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ For faster parallel builds, you can instead generate [ninja](https://ninja-build
- Types
- [ ] Result<T,E>
- [ ] Map: don't store hashes of integer keys
- [ ] Opt: specializations for null representations
- Allocators
- [ ] Per-thread pools
- Misc
Expand Down
6 changes: 6 additions & 0 deletions rpp/slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ struct Slice {
length_ = init.size();
}

operator Slice<const T>() const noexcept
requires(!Const<T>)
{
return Slice<const T>{data_, length_};
}

constexpr Slice(const Slice& src) noexcept = default;
constexpr Slice& operator=(const Slice& src) noexcept = default;

Expand Down
2 changes: 2 additions & 0 deletions test/arrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ i32 main() {
static_assert(Same<decltype(deduct4), Slice<i32>>);
auto deduct5 = constv.slice();
static_assert(Same<decltype(deduct5), Slice<const i32>>);
auto deduct6 = Slice<const i32>{deduct4};
static_assert(Same<decltype(deduct6), Slice<const i32>>);

v.pop();
assert(v.length() == 2);
Expand Down

0 comments on commit 9b08c41

Please sign in to comment.