From 3f04db09bd9463f9d7d022a193c2f79be6fb59b7 Mon Sep 17 00:00:00 2001 From: Claudio DeSouza Date: Sat, 9 Nov 2024 01:38:40 +0000 Subject: [PATCH] `Slice::iterator` to be `contiguous` and `random_access` `rust::Vec` fails `std::ranges::contiguous_range` checks as those have to satisfy `random_access_range`, and `contiguous_iterator`. This has caused mismatches with certain `span` types in other codebases. This PR adds the necessary increment and concept category to `Slice::iterator`, to correct this issue. Bug: https://github.com/dtolnay/cxx/issues/1392 --- include/cxx.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/cxx.h b/include/cxx.h index 3414e4c8a..dc1420da1 100644 --- a/include/cxx.h +++ b/include/cxx.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include #include #include @@ -217,6 +218,7 @@ template class Slice::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::type; @@ -244,6 +246,10 @@ class Slice::iterator final { bool operator>(const iterator &) const noexcept; bool operator>=(const iterator &) const noexcept; + template + friend iterator operator+(N n, const iterator& it) noexcept { + return it + n; + } private: friend class Slice; void *pos;