+2016-09-12 Ville Voutilainen <ville.voutilainen@gmail.com>
+
+ Implement P0253R1, Fixing a design mistake in the searchers
+ interface in Library Fundamentals.
+ * include/std/functional: (utility): New include in C++17 mode.
+ (default_searcher): Use a pair as return type, adjust the definition.
+ (boyer_moore_searcher): Likewise.
+ (boyer_moore_horspool_searcher): Likewise.
+ * testsuite/20_util/function_objects/searchers.cc: Adjust.
+
2016-09-12 Ville Voutilainen <ville.voutilainen@gmail.com>
Implement C++17 string searchers.
#include <unordered_map>
#include <vector>
#include <array>
+#include <utility>
#include <bits/stl_algo.h>
#endif
{ }
template<typename _ForwardIterator2>
- _ForwardIterator2
+ pair<_ForwardIterator2, _ForwardIterator2>
operator()(_ForwardIterator2 __first, _ForwardIterator2 __last) const
{
- return std::search(__first, __last,
- std::get<0>(_M_m), std::get<1>(_M_m),
- std::get<2>(_M_m));
+ _ForwardIterator2 __first_ret =
+ std::search(__first, __last,
+ std::get<0>(_M_m), std::get<1>(_M_m),
+ std::get<2>(_M_m));
+ _ForwardIterator2 __second_ret = __first_ret == __last ?
+ __last : std::next(__first_ret, std::distance(std::get<0>(_M_m),
+ std::get<1>(_M_m)));
+ return std::make_pair(__first_ret, __second_ret);
}
private:
_BinaryPredicate __pred = _BinaryPredicate());
template<typename _RandomAccessIterator2>
- _RandomAccessIterator2
+ pair<_RandomAccessIterator2, _RandomAccessIterator2>
operator()(_RandomAccessIterator2 __first,
_RandomAccessIterator2 __last) const;
{ }
template<typename _RandomAccessIterator2>
- _RandomAccessIterator2
+ pair<_RandomAccessIterator2, _RandomAccessIterator2>
operator()(_RandomAccessIterator2 __first,
_RandomAccessIterator2 __last) const
{
const auto& __pred = this->_M_pred();
auto __patlen = _M_pat_end - _M_pat;
if (__patlen == 0)
- return __first;
+ return std::make_pair(__first, __first);
auto __len = __last - __first;
while (__len >= __patlen)
{
for (auto __scan = __patlen - 1;
__pred(__first[__scan], _M_pat[__scan]); --__scan)
if (__scan == 0)
- return __first;
+ return std::make_pair(__first,
+ std::next(__first, __patlen));
auto __shift = _M_bad_char_shift(__first[__patlen - 1]);
__len -= __shift;
__first += __shift;
}
- return __last;
+ return std::make_pair(__last, __last);
}
private:
template<typename _RAIter, typename _Hash, typename _BinaryPredicate>
template<typename _RandomAccessIterator2>
- _RandomAccessIterator2
+ pair<_RandomAccessIterator2, _RandomAccessIterator2>
boyer_moore_searcher<_RAIter, _Hash, _BinaryPredicate>::
operator()(_RandomAccessIterator2 __first,
_RandomAccessIterator2 __last) const
{
auto __patlen = _M_pat_end - _M_pat;
if (__patlen == 0)
- return __first;
+ return std::make_pair(__first, __first);
const auto& __pred = this->_M_pred();
__diff_type __i = __patlen - 1;
auto __stringlen = __last - __first;
--__j;
}
if (__j < 0)
- return __first + __i + 1;
+ return std::make_pair(__first + __i + 1, std::next(__first,
+ __patlen));
__i += std::max(_M_bad_char_shift(__first[__i]),
_M_good_suffix[__j]);
}
- return __last;
+ return std::make_pair(__last, __last);
}
#endif
auto he = h + std::strlen(h);
auto res = std::search(h, he, n, ne);
auto d_res = d(h, he);
- VERIFY( d_res == res );
+ VERIFY( d_res.first == res );
auto bm_res = bm(h, he);
- VERIFY( bm_res == res );
+ VERIFY( bm_res.first == res );
auto bmh_res = bmh(h, he);
- VERIFY( bmh_res == res );
+ VERIFY( bmh_res.first == res );
}
}
}
auto he = h + std::wcslen(h);
auto res = std::search(h, he, n, ne);
auto d_res = d(h, he);
- VERIFY( d_res == res );
+ VERIFY( d_res.first == res );
auto bm_res = bm(h, he);
- VERIFY( bm_res == res );
+ VERIFY( bm_res.first == res );
auto bmh_res = bmh(h, he);
- VERIFY( bmh_res == res );
+ VERIFY( bmh_res.first == res );
}
}
#endif
auto res = std::search(haystack, he, needle, ne, eq);
auto d_res = d(haystack, he);
- VERIFY( d_res == res );
+ VERIFY( d_res.first == res );
auto bm_res = bm(haystack, he);
- VERIFY( bm_res == res );
+ VERIFY( bm_res.first == res );
auto bmh_res = bmh(haystack, he);
- VERIFY( bmh_res == res );
+ VERIFY( bmh_res.first == res );
}
int