Boost logo

Boost Users :

Subject: Re: [Boost-users] [intrusive] first impression and constant-time removal
From: Zeljko Vrba (zvrba_at_[hidden])
Date: 2009-02-05 13:41:08


On Thu, Feb 05, 2009 at 07:11:03PM +0100, Ion Gaztañaga wrote:
>
> That can be a good idea, since many lists have no constant-time size, so
> the user should be informed of how many elements have been erased. It's
> not std compliant but it does not break any code, since the function
> returned nothing.
>
I would be careful here because C++ allows void returns. An example:

template<typename T>
void f(T &t)
{ return t.remove(..); }

If you change remove to return something else than void, the code above will
fail to compile. This example is contrived, but things could break in more
elaborate generic algorithm implementations. Heck, the simplest example
of the usefulness of the above is early exit from a function, e.g.:

if(something)
  return t.remove(..);

which avoids compound statement.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net