Page MenuHome

BLI: GArray improve: first, last, index_range, fill
AbandonedPublic

Authored by Iliya Katueshenock (Moder) on Aug 5 2022, 10:59 PM.

Details

Summary

GArray can be useful in many situations. But its functionality is not as
developed as other containers. This patch adds the fill, first/last
and index_range.

Diff Detail

Event Timeline

Iliya Katueshenock (Moder) requested review of this revision.Aug 5 2022, 10:59 PM
Iliya Katueshenock (Moder) created this revision.

I think the best solution would be to add a method to both types to set the new memory and size, and then make the function for swap ownership of the memorys

Iliya Katueshenock (Moder) retitled this revision from BLI: GArray improve: typed<>(), first, last, index_range, fill to BLI: GArray improve: first, last, index_range, fill.
Iliya Katueshenock (Moder) edited the summary of this revision. (Show Details)

Cancellation of type casting. This will be moved to another patch.

After sorting through different implementation options and looking for the most general method without code generation, I decided to think about something like this. https://developer.blender.org/P3132

Do you have a use case for the first and last functions? Generally I wouldn't expect much complex processing with this type, generic spans or typed spans should usually be used instead.

source/blender/blenlib/BLI_generic_array.hh
269–271

This doesn't work when the type is nontrivial. The CPPType methods should be used instead.
Passing the type to this method is redundant, just the assertion is fine.

Indeed, this patch was proposed before I knew that features are only added when really needed.
I found a workaround for the need to swap memory between the template and generic containers. And since that was also taken out of this patch, I feel like it's redundant now.
I'd say it would be handy to represent it as a range, but I don't have any examples.