Skip to content

Commit 58c557c

Browse files
committed
xtd::span implementation
1 parent 3c76412 commit 58c557c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/xtd.core/include/xtd/span.hpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ namespace xtd {
110110
explicit span(type_t* data) : data_ {data} {
111111
}
112112

113+
explicit span(const type_t* data, size_type size) : data_ {const_cast<type_t*>(data)}, size_ {size} {
114+
}
115+
explicit span(type_t* data, size_type size) : data_ {data}, size_ {size} {
116+
}
117+
113118
span(span&& items) = default;
114119
span(const span& items) = default;
115120

@@ -162,17 +167,19 @@ namespace xtd {
162167
if (index >= size_) throw argument_out_of_range_exception {};
163168
return *(data_ + index);
164169
}
165-
166-
template<xtd::size count__>
167-
span<type_t, count__> last() {return span<type_t, count__> {data_ + size_ - count__};}
168170

169171
template<xtd::size count__>
170-
span<element_type, count__> first() {return span<element_type, count__> {data_};}
172+
span<element_type, count__> first() const {return span<element_type, count__> {data_};}
173+
174+
template<xtd::size count__>
175+
span<type_t, count__> last() const {return span<type_t, count__> {data_ + size_ - count__};}
171176

177+
span<type_t> subspan(size_type offset, size_type count) const {return span<type_t> {data_ + offset, count};}
178+
172179
string to_string() const noexcept override {return xtd::string::format("[{}]", xtd::string::join(", ", *this));}
173180
/// @}
174181

175-
/// @name Public Opertors
182+
/// @name Public Operators
176183

177184
/// @{
178185
const_reference operator[](size_t index) const {

0 commit comments

Comments
 (0)