From fdaa01493749892eb5c8a7205c882c6e36eee770 Mon Sep 17 00:00:00 2001 From: JC <8765278+Crzyrndm@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:25:57 +1300 Subject: [PATCH] add `operator+(int, iterator)` overload --- include/nonstd/ring_span.hpp | 6 ++++++ test/ring-span.t.cpp | 1 + 2 files changed, 7 insertions(+) diff --git a/include/nonstd/ring_span.hpp b/include/nonstd/ring_span.hpp index e4f64a8..2e4ea88 100644 --- a/include/nonstd/ring_span.hpp +++ b/include/nonstd/ring_span.hpp @@ -1104,6 +1104,12 @@ inline ring_iterator operator+( ring_iterator it, int i ) nsrs_noexc it += i; return it; } +template< class RS, bool C > +inline ring_iterator operator+( int i, ring_iterator it ) nsrs_noexcept +{ + it += i; return it; +} + template< class RS, bool C > inline ring_iterator operator-( ring_iterator it, int i ) nsrs_noexcept { diff --git a/test/ring-span.t.cpp b/test/ring-span.t.cpp index f2ddec4..706416c 100644 --- a/test/ring-span.t.cpp +++ b/test/ring-span.t.cpp @@ -944,6 +944,7 @@ CASE( "ring_iterator: Allows to offset iterator (+)" " [extension]" ) ring_span::iterator pos = rs.begin(); EXPECT( *(pos + 2) == arr[2] ); + EXPECT( *(2 + pos) == arr[2] ); #endif }