Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-05-15 10:00:27


----- Original Message -----
From: "Damien Fisher" <damien_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, May 15, 2002 9:31 AM
Subject: Re: [boost] is_single_element?

> On Thu, 16 May 2002, Damien Fisher wrote:
>
> > template<typename Container>
> > bool is_n_elements(const Container &cont, unsigned int n)
> > {
> > // ...
> > }
>
> I should point out that this function would have complexity O(n), where
> n is the parameter passed in, whereas using std::list<T>::size() would
> result in complexity O(m), where m is the size of the list. Using the
> above would then only really be necessary/useful if m >> n.

But the implementation you supplied invokes undefined behavior when used on
empty containers.

-D


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