|
Boost : |
From: Damien Fisher (damien_at_[hidden])
Date: 2002-05-15 21:02:55
On Wed, 15 May 2002, Dave Harris wrote:
> In-Reply-To: <Pine.GSO.4.05.10205160011080.5723-100000_at_galois>
> On Thu, 16 May 2002 00:18:41 +1000 (EST) Damien Fisher
> (damien_at_[hidden]) wrote:
> > I would like to see something like this in Boost:
> >
> > template<typename Container>
> > bool is_single_element(const Container &cont);
>
> Should it be defined for iterator pairs as well as, or instead of,
> containers? Most algorithms work on iterators.
I like this. Someone pointed out to me it in a private e-mail that a
length-checked distance function might fit in better with the current
STL naming, eg:
template<typename FwdIt>
std::iterator_traits<FwdIt>::distance_type n
distance_n(
FwdIt first, FwdIt last,
std::iterator_traits<FwdIt>::distance_type n
)
{
std::iterator_traits<FwdIt>::distance_type i = 0;
while(i != n && first != last)
{
++first;
++i;
}
return i;
}
With an appropriate specialization for random-access iterators.
Do people prefer this? If so, I can do it properly (add the appropriate
specialization), add test cases and docs, etc. I have wanted this many
times, and it seems to have gotten a reasonable response (mostly
pointing out the mistakes in my example implementation, which I hadn't
really meant as a real implementation, and which was written late at
night, but, hey, mea culpa for writing e-mails half-asleep :) ).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk