Skip to content

Commit 07a60f2

Browse files
committed
Add TypedSpan
1 parent 27d04a5 commit 07a60f2

File tree

1 file changed

+30
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)