|
Boost : |
From: Joe Gottman (joegottman_at_[hidden])
Date: 2001-12-04 20:48:27
One algorithm that I have found useful is sets_intersect(). It takes two
sorted ranges and return a boolean saying whether they have any elements in
common.
template <typename Iterator1, typename Iterator2>
bool sets_intersect(Iterator1 start1, Iterator1 end1, Iterator2 start2,
Iterator2 end2)
{
while ((start1 != end1) && (start2 != end2)) {
if (*start1 < *start2) {
++start1;
} else if (*start2 < *start1) {
++start2;
} else {
return true;
}
}
return false;
}
There is a similar function that takes a predicate as a third template
parameter. You could use std::set_intersection() to determine if two ranges
intersect, but this function has two advantages. You do not have to
allocate space for the output set, and this function returns true as soon as
the first point of intersection is found. The one thing I'm not sure about
is the name. It's very close to std::set_intersection(), but I can't think
of a better one off the top of my head.
Joe Gottman
----- Original Message -----
From: "Jeremy Siek" <jsiek_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, December 04, 2001 4:53 PM
Subject: [boost] Boost.Algorithm library
> Hi All,
>
> Every so often the topic comes up of miscellaneous algorithms that aren't
> in STL, and would be good to have in Boost. I had volunteered to get that
> started, but haven't had much time to do so, and didn't have a good idea
> of how to get started.
>
> So, to finally get things started, I've created a page at the Boost Users
> Wiki.
>
>
http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?STLAlgorithmE
xtensions
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk