|
Boost : |
From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-05-15 10:45:41
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();
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk