Skip to content

Commit 40a56ae

Browse files
committed
feat: add range constructor and back accessors to webcc::vector
1 parent ab2d339 commit 40a56ae

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

include/webcc/core/vector.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ namespace webcc
5353
(push_back(static_cast<T>(rest)), ...);
5454
}
5555

56+
template <typename InputIt, typename = enable_if_t<__is_pointer(InputIt)>>
57+
vector(InputIt first, InputIt last)
58+
{
59+
for (; first != last; ++first)
60+
{
61+
push_back(static_cast<T>(*first));
62+
}
63+
}
64+
5665
explicit vector(size_t count)
5766
{
5867
resize(count);
@@ -326,6 +335,9 @@ namespace webcc
326335
T *data() { return m_data; }
327336
const T *data() const { return m_data; }
328337

338+
T &back() { return m_data[m_size - 1]; }
339+
const T &back() const { return m_data[m_size - 1]; }
340+
329341
size_t size() const { return m_size; }
330342
size_t capacity() const { return m_capacity; }
331343
bool empty() const { return m_size == 0; }

0 commit comments

Comments
 (0)