Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-05-17 05:01:04


From: "Daniel Frey" <daniel.frey_at_[hidden]>
>
> template< typename Container >
> bool is_single_element( const Container& container )
> {
> // Resolved at compile-time:
> if( ::boost::is_pointer< Container::iterator >::value )
> return !container.empty() &&
> boost::next( container.begin() ) == container.end();
> else
> return !container.empty() &&
> ++container.begin() == container.end();
> }

template<class It> bool is_single_element(It first, It last)
{
    return first != last && ++first == last;
}


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