115 if constexpr (std::is_trivially_copyable_v<T>) {
116 mask.foreach_index([&](
const int64_t i) { dst[i] = this->
get(i); });
119 if (dst_is_uninitialized) {
120 mask.foreach_index([&](
const int64_t i) {
new (dst + i)
T(this->
get(i)); });
123 mask.foreach_index([&](
const int64_t i) { dst[i] = this->
get(i); });
135 const bool dst_is_uninitialized)
const
137 if constexpr (std::is_trivially_copyable_v<T>) {
141 if (dst_is_uninitialized) {
181 src.
data(), this->size_,
const_cast<T *
>(
static_cast<const T *
>(info.
data)));
186 this->
set(i, src[i]);
234 if constexpr (std::is_trivially_copyable_v<T>) {
238 if (dst_is_uninitialized) {
249 const bool dst_is_uninitialized)
const override
251 if constexpr (std::is_trivially_copyable_v<T>) {
255 if (dst_is_uninitialized) {
296template<
typename Container,
typename T =
typename Container::value_type>
299 Container container_;
305 this->
data_ =
const_cast<T *
>(container_.data());
337 if constexpr (std::is_trivially_copyable_v<T>) {
341 if (dst_is_uninitialized) {
342 mask.foreach_index([&](
const int64_t i) {
new (dst + i)
T(value_); });
345 mask.foreach_index([&](
const int64_t i) { dst[i] = value_; });
352 const bool dst_is_uninitialized)
const override
354 if constexpr (std::is_trivially_copyable_v<T>) {
358 if (dst_is_uninitialized) {
388 return get_func_(
index);
391 void materialize(
const IndexMask &
mask,
T *dst,
const bool dst_is_uninitialized)
const override
393 if constexpr (std::is_trivially_copyable_v<T>) {
394 mask.foreach_index([&](
const int64_t i) { dst[i] = get_func_(i); });
397 if (dst_is_uninitialized) {
398 mask.foreach_index([&](
const int64_t i) {
new (dst + i)
T(get_func_(i)); });
401 mask.foreach_index([&](
const int64_t i) { dst[i] = get_func_(i); });
406 void materialize_compressed(
const IndexMask &mask,
408 const bool dst_is_uninitialized)
const override
410 if constexpr (std::is_trivially_copyable_v<T>) {
411 mask.foreach_index([&](
const int64_t i,
const int64_t pos) { dst[pos] = get_func_(i); });
414 if (dst_is_uninitialized) {
416 [&](
const int64_t i,
const int64_t pos) {
new (dst + pos)
T(get_func_(i)); });
419 mask.foreach_index([&](
const int64_t i,
const int64_t pos) { dst[pos] = get_func_(i); });
428template<
typename StructT,
430 ElemT (*GetFunc)(
const StructT &),
431 void (*SetFunc)(StructT &, ElemT) =
nullptr>
442 template<
typename OtherStructT,
444 OtherElemT (*OtherGetFunc)(
const OtherStructT &),
445 void (*OtherSetFunc)(OtherStructT &, OtherElemT)>
451 return GetFunc(data_[
index]);
456 SetFunc(data_[
index], std::move(value));
459 void materialize(
const IndexMask &
mask,
461 const bool dst_is_uninitialized)
const override
463 if constexpr (std::is_trivially_copyable_v<ElemT>) {
464 mask.foreach_index([&](
const int64_t i) { dst[i] = GetFunc(data_[i]); });
467 if (dst_is_uninitialized) {
468 mask.foreach_index([&](
const int64_t i) {
new (dst + i) ElemT(GetFunc(data_[i])); });
471 mask.foreach_index([&](
const int64_t i) { dst[i] = GetFunc(data_[i]); });
478 const bool dst_is_uninitialized)
const override
480 if constexpr (std::is_trivially_copyable_v<ElemT>) {
482 [&](
const int64_t i,
const int64_t pos) { dst[pos] = GetFunc(data_[i]); });
485 if (dst_is_uninitialized) {
487 [&](
const int64_t i,
const int64_t pos) {
new (dst + pos) ElemT(GetFunc(data_[i])); });
491 [&](
const int64_t i,
const int64_t pos) { dst[pos] = GetFunc(data_[i]); });
497template<
typename StructT,
499 ElemT (*GetFunc)(
const StructT &),
500 void (*SetFunc)(StructT &, ElemT)>
531 template<
typename ImplT,
typename... Args>
void emplace(Args &&...args)
538 operator bool()
const
562 return (*
this)[
index];
574 return impl_->size();
588 return (*
this)[this->
size() - 1 - n];
594 return this->
size() == 0;
605 return impl_->common_info();
624 return Span<T>(
static_cast<const T *
>(info.
data), this->size());
643 return *
static_cast<const T *
>(info.
data);
655 return *
static_cast<const T *
>(info.
data);
696 return impl_->try_assign_GVArray(varray);
705template<
typename T>
class VMutableArray;
748 template<
typename ImplT,
typename... Args>
static VArray from(Args &&...args)
750 static_assert(std::is_base_of_v<VArrayImpl<T>, ImplT>);
795 template<
typename StructT, T (*GetFunc)(const StructT &)>
834 static_assert(std::is_base_of_v<VMutableArrayImpl<T>, ImplT>);
852 template<
typename StructT, T (*GetFunc)(const StructT &),
void (*SetFunc)(StructT &, T)>
903#if defined(__GNUC__) && !defined(__clang__)
904# pragma GCC diagnostic push
905# pragma GCC diagnostic ignored "-Warray-bounds"
907 this->get_impl()->set(
index, std::move(value));
908#if defined(__GNUC__) && !defined(__clang__)
909# pragma GCC diagnostic pop
919 this->get_impl()->set_all(src);
925 return this->get_impl()->try_assign_GVMutableArray(varray);
971 this->
size_ = varray_.size();
974 this->data_ = static_cast<const T *>(info.data);
977 owned_data_.~Array();
978 new (&owned_data_) Array<T>(varray_.size(), NoInitialization{});
979 varray_.materialize_to_uninitialized(owned_data_);
980 this->data_ = owned_data_.
data();
985 : varray_(std::move(other.varray_)), owned_data_(std::move(other.owned_data_))
990 this->
size_ = varray_.size();
993 this->data_ = static_cast<const T *>(info.data);
996 this->data_ = owned_data_.data();
998 other.data_ =
nullptr;
1004 if (
this == &other) {
1007 std::destroy_at(
this);
1014void print_mutable_varray_span_warning();
1028 bool save_has_been_called_ =
false;
1029 bool show_not_saved_warning_ =
true;
1043 this->
size_ = varray_.size();
1046 this->data_ = const_cast<T *>(static_cast<const T *>(info.data));
1049 if (copy_values_to_span) {
1050 owned_data_.~Array();
1051 new (&owned_data_) Array<T>(varray_.size(), NoInitialization{});
1052 varray_.materialize_to_uninitialized(owned_data_);
1055 owned_data_.reinitialize(varray_.size());
1057 this->data_ = owned_data_.
data();
1062 : varray_(std::move(other.varray_)),
1063 owned_data_(std::move(other.owned_data_)),
1064 show_not_saved_warning_(other.show_not_saved_warning_)
1070 this->
size_ = varray_.size();
1073 this->data_ = static_cast<T *>(const_cast<void *>(info.data));
1076 this->data_ = owned_data_.data();
1078 other.data_ =
nullptr;
1085 if (show_not_saved_warning_) {
1086 if (!save_has_been_called_) {
1095 if (
this == &other) {
1098 std::destroy_at(
this);
1111 save_has_been_called_ =
true;
1112 if (this->data_ != owned_data_.data()) {
1115 varray_.set_all(owned_data_);
1120 show_not_saved_warning_ =
false;
1169 if constexpr (UseSingle) {
1174 if constexpr (UseSpan) {
1191template<
typename T,
typename Func>
1209template<
typename T1,
typename T2,
typename Func>
#define UNUSED_VARS_NDEBUG(...)
constexpr IndexRange()=default
constexpr MutableSpan()=default
constexpr T * data() const
MutableVArraySpan()=default
const VMutableArray< T > & varray() const
void disable_not_applied_warning()
MutableVArraySpan & operator=(MutableVArraySpan &&other)
MutableVArraySpan(MutableVArraySpan &&other)
MutableVArraySpan(VMutableArray< T > varray, const bool copy_values_to_span=true)
SingleAsSpan(const VArray< T > &varray)
const T & operator[](const int64_t index) const
SingleAsSpan(T value, int64_t size)
constexpr const T * data() const
constexpr int64_t size() const
std::optional< T > get_if_single() const
IndexRange index_range() const
VArrayCommon(std::shared_ptr< const VArrayImpl< T > > impl)
void materialize(MutableSpan< T > r_span) const
T operator[](const int64_t index) const
T last(const int64_t n=0) const
VArrayCommon(const VArrayImpl< T > *impl)
void materialize_compressed_to_uninitialized(const IndexMask &mask, MutableSpan< T > r_span) const
T get_internal_single() const
void materialize(const IndexMask &mask, MutableSpan< T > r_span) const
AnyDerived< const VArrayImpl< T > > impl_
T get(const int64_t index) const
void materialize_to_uninitialized(const IndexMask &mask, MutableSpan< T > r_span) const
const VArrayImpl< T > * get_implementation() const
bool try_assign_GVArray(GVArray &varray) const
void materialize_to_uninitialized(MutableSpan< T > r_span) const
void materialize_compressed(const IndexMask &mask, MutableSpan< T > r_span) const
CommonVArrayInfo common_info() const
Span< T > get_internal_span() const
void emplace(Args &&...args)
VArrayImpl_For_ArrayContainer(Container container)
friend class VArrayImpl_For_DerivedSpan
VArrayImpl_For_DerivedSpan(const MutableSpan< StructT > data)
VArrayImpl_For_Func(const int64_t size, GetFunc get_func)
void materialize_compressed(const IndexMask &mask, T *dst, const bool dst_is_uninitialized) const override
VArrayImpl_For_Single(T value, const int64_t size)
void materialize(const IndexMask &mask, T *dst, const bool dst_is_uninitialized) const override
CommonVArrayInfo common_info() const override
T get(const int64_t) const override
VArrayImpl_For_Span_final(const Span< T > data)
CommonVArrayInfo common_info() const override
void set(const int64_t index, T value) final
VArrayImpl_For_Span(const int64_t size)
void materialize(const IndexMask &mask, T *dst, const bool dst_is_uninitialized) const override
T get(const int64_t index) const final
VArrayImpl_For_Span(const MutableSpan< T > data)
void materialize_compressed(const IndexMask &mask, T *dst, const bool dst_is_uninitialized) const override
virtual bool try_assign_GVArray(GVArray &) const
virtual void materialize(const IndexMask &mask, T *dst, const bool dst_is_uninitialized) const
virtual CommonVArrayInfo common_info() const
virtual void materialize_compressed(const IndexMask &mask, T *dst, const bool dst_is_uninitialized) const
virtual T get(int64_t index) const =0
VArrayImpl(const int64_t size)
virtual ~VArrayImpl()=default
VArrayRef(const VArray< T > &ref)
T operator[](const int64_t index) const
VArraySpan(VArray< T > &&varray)
VArraySpan(VArraySpan &&other)
VArraySpan(const VArray< T > &varray)
VArraySpan & operator=(VArraySpan &&other)
static VArray from_derived_span(Span< StructT > values)
VArray(const VArrayImpl< T > *impl)
static VArray from(Args &&...args)
VArray(varray_tag::single, T value, const int64_t size)
static VArray from_std_func(const int64_t size, std::function< T(int64_t index)> get_func)
static VArray from_single(T value, const int64_t size)
static VArray from_func(const int64_t size, GetFunc get_func)
VArray(varray_tag::span, Span< T > span)
VArray(std::shared_ptr< const VArrayImpl< T > > impl)
static VArray from_span(Span< T > values)
static VArray from_container(ContainerT container)
virtual void set(int64_t index, T value)=0
virtual bool try_assign_GVMutableArray(GVMutableArray &) const
virtual void set_all(Span< T > src)
static VMutableArray from_derived_span(MutableSpan< StructT > values)
void set(const int64_t index, T value)
VMutableArray(std::shared_ptr< const VMutableArrayImpl< T > > impl)
static VMutableArray from_container(ContainerT container)
static VMutableArray from(Args &&...args)
bool try_assign_GVMutableArray(GVMutableArray &varray) const
MutableSpan< T > get_internal_span() const
VMutableArray(const VMutableArrayImpl< T > *impl)
static VMutableArray from_span(MutableSpan< T > values)
void set_all(Span< T > src)
constexpr MutableSpan()=default
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
BLI_NOINLINE void fill(T *__restrict data, const T &value, const IndexMask &mask)
BLI_NOINLINE void copy_assign(const T *__restrict src, const IndexMask &mask, T *__restrict dst)
BLI_NOINLINE void gather_assign(const T *__restrict src, const IndexMask &indices, T *__restrict dst)
void print_mutable_varray_span_warning()
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void devirtualize_varray(const VArray< T > &varray, const Func &func, bool enable=true)
void devirtualize_varray2(const VArray< T1 > &varray1, const VArray< T2 > &varray2, const Func &func, bool enable=true)
static constexpr bool is_VArray_v
void initialized_fill_n(T *dst, int64_t n, const T &value)
bool call_with_devirtualized_parameters(const std::tuple< Devirtualizers... > &devis, const Fn &fn)
BMesh const char void * data
static constexpr bool is_VMutableArray_v
void uninitialized_fill_n(T *dst, int64_t n, const T &value)
void initialized_copy_n(const T *src, int64_t n, T *dst)
constexpr bool is_trivial_extended_v
void mask(PageMask &srt, TileMaps &tilemaps, const uint3 global_id, const uint local_tile_index)
CommonVArrayInfo(const Type _type, const bool _may_have_ownership, const void *_data)
CommonVArrayInfo()=default
bool devirtualize(const Fn &fn) const
const VArray< T > & varray