mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Add SharedVector<T>::empty() and a constructor that takes an initializer list
This commit is contained in:
parent
ffb1d7bd83
commit
dc30106037
2 changed files with 29 additions and 0 deletions
|
@ -11,6 +11,7 @@ LICENSE END */
|
|||
#include "sixtyfps_sharedvector_internal.h"
|
||||
#include <atomic>
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
|
||||
namespace sixtyfps {
|
||||
|
||||
|
@ -22,6 +23,17 @@ struct SharedVector
|
|||
cbindgen_private::sixtyfps_shared_vector_empty())))
|
||||
{
|
||||
}
|
||||
SharedVector(std::initializer_list<T> args) : SharedVector()
|
||||
{
|
||||
auto new_array = SharedVector::with_capacity(args.size());
|
||||
auto new_data = reinterpret_cast<T *>(new_array.inner + 1);
|
||||
auto input_it = args.begin();
|
||||
for (std::size_t i = 0; i < args.size(); ++i, ++input_it) {
|
||||
new (new_data + i) T(*input_it);
|
||||
new_array.inner->size++;
|
||||
}
|
||||
*this = std::move(new_array);
|
||||
}
|
||||
|
||||
SharedVector(const SharedVector &other) : inner(other.inner)
|
||||
{
|
||||
|
@ -69,6 +81,8 @@ struct SharedVector
|
|||
|
||||
std::size_t size() const { return inner->size; }
|
||||
|
||||
bool empty() const { return inner->size == 0; }
|
||||
|
||||
T &operator[](std::size_t index) { return begin()[index]; }
|
||||
const T &operator[](std::size_t index) const { return begin()[index]; }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue