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