:github_url: https://github.com/svenevs/exhale-companion .. _program_listing_file_ckpttncpp_array_like.hpp: Program Listing for File array_like.hpp ======================================= |exhale_lsh| :ref:`Return to documentation for file ` (``ckpttncpp/array_like.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include #include // #include template inline auto get_repeat_array(const Val& a, std::ptrdiff_t n) { using repeat_n_return_type = decltype(ranges::views::repeat_n(a, n)); struct iterable_wrapper : public repeat_n_return_type { public: using value_type [[maybe_unused]] = Val; // luk: using key_type [[maybe_unused]] = size_t; // luk: iterable_wrapper(repeat_n_return_type&& base) : repeat_n_return_type {std::forward(base)} { } [[nodiscard]] auto operator[](const std::any& /* don't care */) const -> const Val& { return *this->begin(); } }; return iterable_wrapper {ranges::views::repeat_n(a, n)}; } template class shift_array : public C { using value_type = typename C::value_type; private: size_t _start {0U}; public: shift_array() : C {} { } shift_array(C&& base) : C {std::forward(base)} { } void set_start(const size_t& start) { this->_start = start; } auto operator[](const size_t& index) const -> const value_type& { assert(index >= this->_start); return C::operator[](index - this->_start); } [[nodiscard]] auto operator[](const size_t& index) -> value_type& { return C::operator[](index - this->_start); } };