Subject: [Boost-bugs] [Boost C++ Libraries] #11180: has_set_intersection
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-04-10 10:36:15
#11180: has_set_intersection
------------------------------+-----------------------
Reporter: gast128@⦠| Owner: marshall
Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: algorithm
Version: Boost 1.57.0 | Severity: Problem
Keywords: |
------------------------------+-----------------------
We sometimes have the requirement that we are only interested if two
ranges have overlap. While in general for ranges this is somewhat
difficult, for sorted ranges it seems easy:
template<class In1, class In2, class BinaryPredicate>
bool has_set_intersection(In1 itFirst1, In1 itLast1, In2 itFirst2, In2
itLast2, BinaryPredicate comp)
{
bool bOverlap = false;
while (itFirst1 != itLast1 && itFirst2 != itLast2)
{
if (comp(*itFirst1, *itFirst2))
{
++itFirst1;
}
else if (comp(*itFirst2, *itFirst1))
{
++itFirst2;
}
else
{
bOverlap = true;
break;
}
}
return bOverlap;
}
Ofc this can be achieved with the normal set_intersection as well but that
loops until the end of one of the ranges and requires an extra output
iterator functor.
Maybe an idea?
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11180> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:18 UTC