mirror of
https://github.com/boostorg/container.git
synced 2026-07-06 14:00:47 +02:00
Implement segmented_equal in terms of segmented_mismatch
This commit is contained in:
@@ -21,68 +21,18 @@
|
||||
#include <boost/container/detail/config_begin.hpp>
|
||||
#include <boost/container/detail/workaround.hpp>
|
||||
#include <boost/container/experimental/segmented_iterator_traits.hpp>
|
||||
#include <boost/container/experimental/segmented_mismatch.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
|
||||
template <class InpIter1, class Sent, class InpIter2>
|
||||
bool segmented_equal(InpIter1 first1, Sent last1, InpIter2 first2);
|
||||
|
||||
namespace detail_algo {
|
||||
|
||||
template <class InpIter1, class Sent, class InpIter2>
|
||||
bool equal_ref(InpIter1 first1, Sent last1, InpIter2& first2_out)
|
||||
{
|
||||
InpIter2 first2 = first2_out;
|
||||
for (; first1 != last1; ++first1, ++first2){
|
||||
if (!(*first1 == *first2)) {
|
||||
first2_out = first2;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
first2_out = first2;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class SegIter, class InpIter2>
|
||||
bool segmented_equal_ref
|
||||
(SegIter first1, SegIter last1, InpIter2& first2, segmented_iterator_tag)
|
||||
{
|
||||
typedef segmented_iterator_traits<SegIter> traits;
|
||||
typename traits::segment_iterator sfirst = traits::segment(first1);
|
||||
typename traits::segment_iterator slast = traits::segment(last1);
|
||||
|
||||
if(sfirst == slast) {
|
||||
return (equal_ref)(traits::local(first1), traits::local(last1), first2);
|
||||
}
|
||||
else {
|
||||
if(!(equal_ref)(traits::local(first1), traits::end(sfirst), first2))
|
||||
return false;
|
||||
for(++sfirst; sfirst != slast; ++sfirst)
|
||||
if(!(equal_ref)(traits::begin(sfirst), traits::end(sfirst), first2))
|
||||
return false;
|
||||
return (equal_ref)(traits::begin(sfirst), traits::local(last1), first2);
|
||||
}
|
||||
}
|
||||
|
||||
template <class InpIter1, class Sent, class InpIter2, class Tag>
|
||||
BOOST_CONTAINER_FORCEINLINE typename algo_enable_if_c<
|
||||
!Tag::value || is_sentinel<Sent, InpIter1>::value, bool>::type
|
||||
segmented_equal_ref(InpIter1 first1, Sent last1, InpIter2 first2, Tag)
|
||||
{
|
||||
return (equal_ref)(first1, last1, first2);
|
||||
}
|
||||
|
||||
} // namespace detail_algo
|
||||
|
||||
//! Returns \c true if elements in [first1, last1) are equal to the
|
||||
//! range starting at \c first2. Exploits segmentation on the first range.
|
||||
template <class InpIter1, class Sent, class InpIter2>
|
||||
BOOST_CONTAINER_FORCEINLINE
|
||||
bool segmented_equal(InpIter1 first1, Sent last1, InpIter2 first2)
|
||||
{
|
||||
typedef segmented_iterator_traits<InpIter1> traits;
|
||||
return detail_algo::segmented_equal_ref(first1, last1, first2, typename traits::is_segmented_iterator());
|
||||
return (segmented_mismatch)(first1, last1, first2).first == last1;
|
||||
}
|
||||
|
||||
} // namespace container
|
||||
|
||||
Reference in New Issue
Block a user