Skip to content

Commit

Permalink
[stride_span] add ptr() to iterators for direct access to the pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
iboB committed May 15, 2024
1 parent 06a3888 commit 602c2e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/itlib/stride_span.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// itlib-stride_span v1.01
// itlib-stride_span v1.02
//
// A C++11 implementation C++20's of std::span with a dynamic extent
// and an associated stride.
//
// SPDX-License-Identifier: MIT
// MIT License:
// Copyright(c) 2022-2023 Borislav Stanimirov
// Copyright(c) 2022-2024 Borislav Stanimirov
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files(the
Expand All @@ -29,6 +29,7 @@
//
// VERSION HISTORY
//
// 1.02 (2024-05-15) Add ptr() to iterators for direct access to the pointer
// 1.01 (2023-02-27) Proper iterator support
// 1.00 (2022-05-15) Initial release
//
Expand Down Expand Up @@ -205,6 +206,7 @@ class stride_span
t_iterator() noexcept = default;
CT& operator*() const noexcept { return *reinterpret_cast<T*>(p); }
CT* operator->() const noexcept { return reinterpret_cast<T*>(p); }
CT* ptr() const noexcept { return reinterpret_cast<T*>(p); }
t_iterator& operator++() noexcept { p += stride; return *this; }
t_iterator& operator--() noexcept { p -= stride; return *this; }
t_iterator& operator+=(const ptrdiff_t diff) noexcept { p += diff * stride; return *this; }
Expand Down
2 changes: 2 additions & 0 deletions test/t-stride_span-11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ TEST_CASE("[stride_span] construction and iteration")
CHECK(eints.size() == 4);
CHECK(eints.end() - eints.begin() == 4);
CHECK(eints.begin() + 4 == eints.end());
CHECK(eints.begin().ptr() == i);
CHECK((eints.begin() + 1).ptr() == i + 2);
CHECK(*eints.rbegin() == 4);

CHECK(eints.front() == 1);
Expand Down

0 comments on commit 602c2e1

Please sign in to comment.