Boost logo

Boost :

From: Victor A. Wagner, Jr. (vawjr_at_[hidden])
Date: 2002-05-17 02:01:21


At Wednesday 2002/05/15 08:45, you wrote:
>Damien Fisher wrote:
> >
> > I would like to see something like this in Boost:
> >
> > template<typename Container>
> > bool is_single_element(const Container &cont)
> > {
> > return boost::next(cont.begin()) == cont.end();
> > }
> >
> > [...]
> >
> > Comments?
>
> return !cont.empty() && ++cont.begin() == cont.end();

As Scott Meyers points out in his "Effective STL", ++cont.begin() MAY NOT
compile, depending on the implementation. That's a _serious_ drawback,
IMO. Slow (for stupid compilers) beats not compiling any day.

>The bug was also mentioned by David and is fixed by the test for
>!empty() and using 'boost::next' is pointless in the given context, it
>might even be slower for stupid compilers. Besides that, the function is
>nice to have. I'd like to see it in next to 'prior' and 'next' (the name
>could need some discussion, but I don't have a better idea).
>
>Regards, Daniel
>
>--
>Daniel Frey
>
>aixigo AG - financial training, research and technology
>Schloß-Rahe-Straße 15, 52072 Aachen, Germany
>fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
>eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
>_______________________________________________
>Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Victor A. Wagner Jr. http://rudbek.com
PGP RSA fingerprint = 4D20 EBF6 0101 B069 3817 8DBF C846 E47A
PGP D-H fingerprint = 98BC 65E3 1A19 43EC 3908 65B9 F755 E6F4 63BB 9D93
The five most dangerous words in the English language:
               "There oughta be a law"


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk