Skip to content

Commit 2761890

Browse files
authored
Merge pull request #658 from OpenVicProject/add_typed_span
Add TypedSpan
2 parents 27d04a5 + ee43ca2 commit 2761890

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
using utility::forwardable_span<ValueType, _Extent>::forwardable_span;
19+
20+
constexpr IndexType size() const {
21+
return IndexType(std::span<ValueType, _Extent>::size());
22+
}
23+
24+
constexpr utility::forwardable_span<ValueType, _Extent>::reference operator[](const IndexType _Off) const {
25+
return utility::forwardable_span<ValueType, _Extent>::operator[](static_cast<std::size_t>(type_safe::get(_Off)));
26+
}
27+
28+
constexpr operator TypedSpan<IndexType, const ValueType, _Extent>() {
29+
return TypedSpan<IndexType, const ValueType, _Extent>{*this};
30+
}
31+
};
32+
}

0 commit comments

Comments
 (0)