CkPttn 1.2.4
Loading...
Searching...
No Matches
array_like.hpp
Go to the documentation of this file.
1
6#pragma once
7
8// #include <any>
9#include <cassert>
10#include <cstddef>
11#include <utility>
12// #include <range/v3/view/repeat_n.hpp>
13// #include <type_traits>
14
15// template <typename Val> inline auto get_repeat_array(const Val& a,
16// std::ptrdiff_t n) {
17// using repeat_n_return_type = decltype(ranges::views::repeat_n(a, n));
18
19// struct iterable_wrapper : public repeat_n_return_type {
20// public:
21// using value_type [[maybe_unused]] = Val; // luk:
22// using key_type [[maybe_unused]] = size_t; // luk:
23
24// iterable_wrapper(repeat_n_return_type&& base)
25// : repeat_n_return_type{std::forward<repeat_n_return_type>(base)}
26// {}
27
28// auto operator[](const std::any& /* don't care */) const -> const Val&
29// {
30// return *this->begin();
31// }
32// };
33
34// return iterable_wrapper{ranges::views::repeat_n(a, n)};
35// }
36
47template <typename Container> class ShiftArray : public Container {
48 using value_type = typename Container::value_type;
49
50 private:
52 size_t _start{0U};
53
54 public:
59 ShiftArray() : Container{} {}
60
66 explicit ShiftArray(Container&& base) : Container{std::move(base)} {}
67
73 void set_start(const size_t& start) { this->_start = start; }
74
81 auto operator[](const size_t& index) const -> const value_type& {
82 assert(index >= this->_start);
83 return Container::operator[](index - this->_start);
84 }
85
92 auto operator[](const size_t& index) -> value_type& {
93 return Container::operator[](index - this->_start);
94 }
95};
Shift Array container with shifted index access.
Definition array_like.hpp:47
ShiftArray(Container &&base)
Construct a new Shift Array object.
Definition array_like.hpp:66
auto operator[](const size_t &index) -> value_type &
Access element with shifted index (non-const version).
Definition array_like.hpp:92
ShiftArray()
Construct a new Shift Array object.
Definition array_like.hpp:59
void set_start(const size_t &start)
Set the start index for shifted access.
Definition array_like.hpp:73
auto operator[](const size_t &index) const -> const value_type &
Access element with shifted index (const version).
Definition array_like.hpp:81