J
jacob navia
Gareth Owen a écrit :
I think you are right. But if I change this for the string collection I have
to change Sort for all containers...
But I think you are right basically. An auto-copying interface would be
difficult for big containers.
I will change Sort to be
bool Sort(some_container); // Returns whether Sort succeeded or not
If you want to keep the non-sorted container you copy it before.
Also, if you have a huge
Yes, that is the point I missed. Thanks.
With the changed interface you receive a boolean indicating success/failure.
If there is no memory, a user defined error function is called. The default
function provided by the library prints a message to stdout and aborts.
But you can define an error function of your own. If that function returns
Sort returns false.
Thanks for your input.
Thanks for your full answers, Jacob. Very informative.
Just a couple of quick comments
i) An explicit copy, plus inplace sort() is probably better than an
auto-copying sort. It's more flexible.
I think you are right. But if I change this for the string collection I have
to change Sort for all containers...
But I think you are right basically. An auto-copying interface would be
difficult for big containers.
I will change Sort to be
bool Sort(some_container); // Returns whether Sort succeeded or not
If you want to keep the non-sorted container you copy it before.
Also, if you have a huge
array, you don't want to require twice as much memory.
Yes, that is the point I missed. Thanks.
``ii) What happens if the auto-copying sort runs out of memory? I know
lcc-win has exceptions, and those without can call a user specified
function, but is that function responsible for cleanup, or does the
Sort() routine do this itself?
What happens to control flow, does Sort() return NULL?
With the changed interface you receive a boolean indicating success/failure.
If there is no memory, a user defined error function is called. The default
function provided by the library prints a message to stdout and aborts.
But you can define an error function of your own. If that function returns
Sort returns false.
Thanks for your input.