Skip to content

Commit c343bde

Browse files
committed
Add constructors
1 parent a9cabf1 commit c343bde

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,22 @@ namespace xtd {
101101
span() = default;
102102
template<class iterator_t>
103103
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} {}
106104
template<class collection_t>
107105
explicit span(const collection_t& items) : data_ {const_cast<type_t*>(items.data())}, size_ {items.size()} {}
108106
template<class collection_t>
109107
explicit span(collection_t& items) : data_ {items.data()}, size_ {items.size()} {}
108+
template<class collection_t>
109+
explicit span(const collection_t& items, xtd::size count) : data_ {const_cast<type_t*>(items.data())}, size_ {count} {}
110+
template<class collection_t>
111+
explicit span(collection_t& items, xtd::size count) : data_ {items.data()}, size_ {count} {}
112+
template<class collection_t>
113+
explicit span(const collection_t& items, xtd::size offset, xtd::size count) : data_ {const_cast<type_t*>(items.data() + offset)}, size_ {count} {
114+
if (offset + count > items.size()) throw argument_out_of_range_exception {};
115+
}
116+
template<class collection_t>
117+
explicit span(collection_t& items, xtd::size offset, xtd::size count) : data_ {items.data() + offset}, size_ {count} {
118+
if (offset + count > items.size()) throw argument_out_of_range_exception {};
119+
}
110120
explicit span(std::initializer_list<type_t> items) noexcept : data_ {const_cast<type_t*>(&(*items.begin()))}, size_ {items.size()} {}
111121
explicit span(const type_t* data, size_type size) : data_ {const_cast<type_t*>(data)}, size_ {size} {}
112122
explicit span(type_t* data, size_type size) : data_ {data}, size_ {size} {}

0 commit comments

Comments
 (0)