Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slice<T>::iterator to be contiguous and random_access #1393

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/cxx.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <algorithm>
#include <array>
#include <concepts>
#include <cassert>
#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -217,6 +218,7 @@ template <typename T>
class Slice<T>::iterator final {
public:
using iterator_category = std::random_access_iterator_tag;
using iterator_concept = std::contiguous_iterator_tag;
using value_type = T;
using difference_type = std::ptrdiff_t;
using pointer = typename std::add_pointer<T>::type;
Expand Down Expand Up @@ -244,6 +246,10 @@ class Slice<T>::iterator final {
bool operator>(const iterator &) const noexcept;
bool operator>=(const iterator &) const noexcept;

template <std::integral N>
friend iterator operator+(N n, const iterator& it) noexcept {
return it + n;
}
private:
friend class Slice;
void *pos;
Expand Down
Loading