Hand the storage over to array, exactly sized, without copying the
elements. The vector is left empty and without storage.
This is the load-time idiom: build a vector while parsing an input of
unknown length, then take the result into the permanent array.
as_array copies; this does not.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(vector_int64_t), | intent(inout) | :: | self | |||
| integer(kind=int64), | intent(out), | allocatable | :: | array(:) | ||
| type(error_t), | intent(inout), | optional | :: | err |
pure subroutine vec_int64_take(self, array, err) !! Hand the storage over to `array`, exactly sized, without copying the !! elements. The vector is left empty and without storage. !! !! This is the load-time idiom: build a vector while parsing an input of !! unknown length, then `take` the result into the permanent array. !! `as_array` copies; this does not. class(vector_int64_t), intent(inout) :: self integer(int64), allocatable, intent(out) :: array(:) type(error_t), intent(inout), optional :: err ! Spare capacity would otherwise be handed over as live elements, so the ! shrink is part of the contract rather than an optimisation. call vec_int64_shrink_to_fit(self, err) if (vec_int64_capacity(self) /= self%n_items) return if (.not. allocated(self%items)) allocate (self%items(0)) call move_alloc(self%items, array) self%n_items = 0 end subroutine vec_int64_take