Hi again, another topic:
Is there an easy way of deleting elements from dynamic arrays?
Currently i have to walk the array and do alot of copying etc.
Maybe i could use templates to implement a function for deleting an
array element, but i dunno how (i'm a newbie to creating templates).
Thanks,
Markus

Hi again, another topic:
Is there an easy way of deleting elements from dynamic arrays?
Currently i have to walk the array and do alot of copying etc.
Maybe i could use templates to implement a function for deleting an
array element, but i dunno how (i'm a newbie to creating templates).
Thanks,
Markus

Just a quick note, you could change:
... int pFrom ...
to:
... uint pFrom ...
to avoid the validation:
if (pFrom < 0) pFrom = 0;
you may also do likewise for pTo, which you might want to
make sure is >= pFrom. I didn't check your algorithm to see
if it happily handles the case pFrom > pTo.
Regards,
Garett

you may also do likewise for pTo, which you might want to
make sure is >= pFrom. I didn't check your algorithm to see
if it happily handles the case pFrom > pTo.

It just returns without modifying the array. A NOP in effect as the caller
is asking to remove non-existent items. One could throw an exception but it
most likely does no harm to do nothing.
--
Derek
Melbourne, Australia
20/12/2004 5:59:12 PM

Slightly OT...
This is an example of a problem for which I have been unable to decide the
best solution.
Imagine if you will:
# void foo(uint a)
# {
# writef("foo: ",a,"\n");
# }
#
# void bar(int a)
# {
# writef("bar: ",a,"\n");
# }
#
# void main()
# {
# int a = -1;
# foo(a);
# bar(a);
# }
This program will print:
foo: 4294967295
bar: -1
So, as you can see it has implicitly converted the int to a uint, meaning
the -1 is represented as 4294967295.
If this function is expecting an index of >= 0 then -1 is clearly wrong,
and throwing an exception could be a valid choice of action, however, if
you are using a uint as described then you cannot be sure they passed a -1
as they could equally have passed 4294967295.
Given that both -1 and 4294967295 are likely to be out of bounds it's not
a big problem, but I am interested on other peoples opinion of the
different solutions they have taken in the past and why they chose those
solutions.
Regan

Slightly OT...
This is an example of a problem for which I have been unable to decide the
best solution.
Imagine if you will:
# void foo(uint a)
# {
# writef("foo: ",a,"\n");
# }
#
# void bar(int a)
# {
# writef("bar: ",a,"\n");
# }
#
# void main()
# {
# int a = -1;
# foo(a);
# bar(a);
# }
This program will print:
foo: 4294967295
bar: -1
So, as you can see it has implicitly converted the int to a uint, meaning
the -1 is represented as 4294967295.
If this function is expecting an index of >= 0 then -1 is clearly wrong,
and throwing an exception could be a valid choice of action, however, if
you are using a uint as described then you cannot be sure they passed a -1
as they could equally have passed 4294967295.
Given that both -1 and 4294967295 are likely to be out of bounds it's not
a big problem, but I am interested on other peoples opinion of the
different solutions they have taken in the past and why they chose those
solutions.