Skip to content

Commit d71cd86

Browse files
committed
Add TypedSpan
1 parent 27d04a5 commit d71cd86

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#include <span>
4+
5+
#include <type_safe/strong_typedef.hpp>
6+
7+
#include "openvic-simulation/utility/Concepts.hpp"
8+
9+
namespace OpenVic {
10+
template<
11+
derived_from_specialization_of<type_safe::strong_typedef> IndexType,
12+
typename ValueType,
13+
size_t _Extent = std::dynamic_extent
14+
>
15+
struct TypedSpan : public std::span<ValueType, _Extent> {
16+
public:
17+
constexpr IndexType size() const {
18+
return IndexType(std::span<ValueType, _Extent>::size());
19+
}
20+
21+
constexpr std::span<ValueType, _Extent>::reference operator[](const IndexType _Off) const {
22+
return std::span<ValueType, _Extent>::operator[](static_cast<std::size_t>(type_safe::get(_Off)));
23+
}
24+
25+
constexpr operator TypedSpan<IndexType, const ValueType, _Extent>() {
26+
return TypedSpan<IndexType, const ValueType, _Extent>{*this};
27+
}
28+
};
29+
}

0 commit comments

Comments
 (0)