vec_int64_push_back Subroutine

private pure subroutine vec_int64_push_back(self, value, err)

Append one element. ERROR_ALLOC if storage cannot be grown, in which case the vector is unchanged.

Type Bound

vector_int64_t

Arguments

Type IntentOptional Attributes Name
class(vector_int64_t), intent(inout) :: self
integer(kind=int64), intent(in) :: value
type(error_t), intent(inout), optional :: err

Calls

proc~~vec_int64_push_back~~CallsGraph proc~vec_int64_push_back vector_int64_t%vec_int64_push_back proc~error_raise error_raise proc~vec_int64_push_back->proc~error_raise proc~vec_int64_capacity vector_int64_t%vec_int64_capacity proc~vec_int64_push_back->proc~vec_int64_capacity proc~vec_int64_grow vec_int64_grow proc~vec_int64_push_back->proc~vec_int64_grow proc~error_set error_t%error_set proc~error_raise->proc~error_set proc~vec_int64_grow->proc~error_raise proc~vec_int64_grow->proc~vec_int64_capacity

Source Code

   pure subroutine vec_int64_push_back(self, value, err)
      !! Append one element. `ERROR_ALLOC` if storage cannot be grown, in which
      !! case the vector is unchanged.
      class(vector_int64_t), intent(inout) :: self
      integer(int64), intent(in) :: value
      type(error_t), intent(inout), optional :: err

      ! Checked before adding, not after: `n_items + 1` at the maximum wraps
      ! negative, and every downstream test would then read as "plenty of
      ! room" while the append walked off the end of the array.
      if (self%n_items >= PIC_VECTOR_MAX_CAPACITY) then
         call error_raise(err, ERROR_ALLOC, &
                          "vector_int64_t: already holds PIC_VECTOR_MAX_CAPACITY elements.")
         return
      end if

      call vec_int64_grow(self, self%n_items + 1, err)
      if (self%n_items + 1 > vec_int64_capacity(self)) return

      self%n_items = self%n_items + 1
      self%items(self%n_items) = value
   end subroutine vec_int64_push_back