From ee43ca21e635d5bfd0f79055034a094726c7f503 Mon Sep 17 00:00:00 2001 From: wvpm <24685035+wvpm@users.noreply.github.com> Date: Thu, 20 Nov 2025 09:45:26 +0100 Subject: [PATCH] Add TypedSpan --- src/openvic-simulation/types/TypedSpan.hpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/openvic-simulation/types/TypedSpan.hpp diff --git a/src/openvic-simulation/types/TypedSpan.hpp b/src/openvic-simulation/types/TypedSpan.hpp new file mode 100644 index 00000000..957f31aa --- /dev/null +++ b/src/openvic-simulation/types/TypedSpan.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include + +#include "openvic-simulation/utility/Concepts.hpp" +#include "openvic-simulation/utility/ForwardableSpan.hpp" + +namespace OpenVic { + template< + derived_from_specialization_of IndexType, + typename ValueType, + size_t _Extent = std::dynamic_extent + > + struct TypedSpan : public utility::forwardable_span { + public: + using utility::forwardable_span::forwardable_span; + + constexpr IndexType size() const { + return IndexType(std::span::size()); + } + + constexpr utility::forwardable_span::reference operator[](const IndexType _Off) const { + return utility::forwardable_span::operator[](static_cast(type_safe::get(_Off))); + } + + constexpr operator TypedSpan() { + return TypedSpan{*this}; + } + }; +} \ No newline at end of file