Skip to content

Commit eb72c9a

Browse files
committed
Add constructors
1 parent b4865ee commit eb72c9a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,21 @@ namespace xtd {
9999

100100
/// @{
101101
span() = default;
102+
template<class iterator_t>
103+
explicit span(iterator_t first, iterator_t last) : data_ {const_cast<type_t*>(&(*first))}, size_ {static_cast<size_type>(std::distance(first, last))} {}
104+
template<class iterator_t>
105+
explicit span(iterator_t first, size_type count) : data_ {const_cast<type_t*>(&(*first))}, size_ {count} {}
102106
template<class collection_t>
103107
explicit span(const collection_t& items) : data_ {const_cast<type_t*>(items.data())}, size_ {items.size()} {}
104108
template<class collection_t>
105109
explicit span(collection_t& items) : data_ {items.data()}, size_ {items.size()} {}
106-
explicit span(const type_t* data) : data_ {const_cast<type_t*>(data)} {}
107-
explicit span(type_t* data) : data_ {data} {}
108-
110+
explicit span(std::initializer_list<type_t> items) : data_ {const_cast<type_t*>(&(*items.begin()))}, size_ {items.size()} {}
109111
explicit span(const type_t* data, size_type size) : data_ {const_cast<type_t*>(data)}, size_ {size} {}
110112
explicit span(type_t* data, size_type size) : data_ {data}, size_ {size} {}
113+
template<std::size_t len_>
114+
constexpr span(const type_t (&array)[len_] ) noexcept : data_ {array}, size_ {len_} {}
115+
template<std::size_t len_>
116+
constexpr span(type_t (&array)[len_] ) noexcept : data_ {array}, size_ {len_} {}
111117

112118
span(span&& items) = default;
113119
span(const span& items) = default;
@@ -171,13 +177,13 @@ namespace xtd {
171177
template<xtd::size count__>
172178
span<element_type, count__> first() const {
173179
if (count__ > size_) throw argument_out_of_range_exception {};
174-
return span<element_type, count__> {data_};
180+
return span<element_type, count__> {data_, count__};
175181
}
176182

177183
template<xtd::size count__>
178184
span<type_t, count__> last() const {
179185
if (count__ > size_) throw argument_out_of_range_exception {};
180-
return span<type_t, count__> {data_ + size_ - count__};
186+
return span<type_t, count__> {data_ + size_ - count__, count__};
181187
}
182188

183189
span<type_t> subspan(size_type offset, size_type count) const {

0 commit comments

Comments
 (0)