Add an item to the end of the list by cloning it.
That is, using a sourced allocation: allocate(newitem, source=value).
A clone is made of the original value, which is not affected.
The list contains only the clone, which will be deallocated (and
finalized if a finalizer is present) when removed from the list.
This is different from the add_pointer routine, which takes a pointer input.
This one would normally be used for basic variables and types that do not contain pointers to other variables (and are not pointed to by other variables)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(list), | intent(inout) | :: | me | |||
| class(*), | intent(in) | :: | key | |||
| class(*), | intent(in) | :: | value |
subroutine add_clone(me,key,value) implicit none class(list),intent(inout) :: me class(*),intent(in) :: key class(*),intent(in) :: value class(*),pointer :: p_value allocate(p_value, source=value) !make a copy call me%add_pointer(key,p_value,destroy_on_delete=.true.) nullify(p_value) end subroutine add_clone