123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660 |
- // Copyright 2005 Daniel Wallin.
- // Copyright 2005 Joel de Guzman.
- // Copyright 2005 Dan Marsden.
- // Copyright 2008 Hartmut Kaiser.
- // Copyright 2015 John Fletcher.
- //
- // Use, modification and distribution is subject to the Boost Software
- // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- // http://www.boost.org/LICENSE_1_0.txt)
- //
- // Modeled after range_ex, Copyright 2004 Eric Niebler
- #ifndef BOOST_PHOENIX_ALGORITHM_QUERYING_HPP
- #define BOOST_PHOENIX_ALGORITHM_QUERYING_HPP
- #include <algorithm>
- #include <boost/phoenix/core/limits.hpp>
- #include <boost/phoenix/stl/algorithm/detail/has_find.hpp>
- #include <boost/phoenix/stl/algorithm/detail/has_lower_bound.hpp>
- #include <boost/phoenix/stl/algorithm/detail/has_upper_bound.hpp>
- #include <boost/phoenix/stl/algorithm/detail/has_equal_range.hpp>
- #include <boost/phoenix/stl/algorithm/detail/begin.hpp>
- #include <boost/phoenix/stl/algorithm/detail/end.hpp>
- #include <boost/phoenix/stl/algorithm/detail/decay_array.hpp>
- #include <boost/phoenix/function/adapt_callable.hpp>
- //#include <boost/range/result_iterator.hpp> is deprecated
- #include <boost/range/iterator.hpp>
- #include <boost/range/difference_type.hpp>
- namespace boost { namespace phoenix {
- namespace impl
- {
- struct find
- {
- template <typename Sig>
- struct result;
- template <typename This, class R, class T>
- struct result<This(R&, T&)>
- : range_iterator<R>
- {};
- template<class R, class T>
- typename range_iterator<R>::type
- execute(R& r, T const& x, mpl::true_) const
- {
- return r.find(x);
- }
- template<class R, class T>
- typename range_iterator<R>::type
- execute(R& r, T const& x, mpl::false_) const
- {
- return std::find(detail::begin_(r), detail::end_(r), x);
- }
- template<class R, class T>
- typename range_iterator<R>::type
- operator()(R& r, T const& x) const
- {
- return execute(r, x, has_find<R>());
- }
- };
- struct find_if
- {
- template <typename Sig>
- struct result;
- template <typename This, class R, class P>
- struct result<This(R&, P)>
- : range_iterator<R>
- {};
- template<class R, class P>
- typename range_iterator<R>::type
- operator()(R& r, P p) const
- {
- return std::find_if(detail::begin_(r), detail::end_(r), p);
- }
- };
- struct find_end
- {
- template <typename Sig>
- struct result;
- template<typename This, class R, class R2>
- struct result<This(R&, R2&)>
- : range_iterator<R>
- {};
- template<typename This, class R, class R2, class P>
- struct result<This(R&, R2&, P)>
- : range_iterator<R>
- {};
- template<class R, class R2>
- typename range_iterator<R>::type
- operator()(R& r, R2& r2) const
- {
- return std::find_end(
- detail::begin_(r)
- , detail::end_(r)
- , detail::begin_(r2)
- , detail::end_(r2)
- );
- }
- template<class R, class R2, class P>
- typename range_iterator<R>::type
- operator()(R& r, R2& r2, P p) const
- {
- return std::find_end(
- detail::begin_(r)
- , detail::end_(r)
- , detail::begin_(r2)
- , detail::end_(r2)
- , p
- );
- }
- };
- struct find_first_of
- {
- template <typename Sig>
- struct result;
- template<typename This, class R, class R2>
- struct result<This(R&, R2&)>
- : range_iterator<R>
- {};
- template<typename This, class R, class R2, class P>
- struct result<This(R&, R2&, P)>
- : range_iterator<R>
- {};
- template<class R, class R2>
- typename range_iterator<R>::type
- operator()(R& r, R2& r2) const
- {
- return std::find_first_of(
- detail::begin_(r)
- , detail::end_(r)
- , detail::begin_(r2)
- , detail::end_(r2)
- );
- }
- template<class R, class R2, class P>
- typename range_iterator<R>::type
- operator()(R& r, R2& r2, P p) const
- {
- return std::find_first_of(
- detail::begin_(r)
- , detail::end_(r)
- , detail::begin_(r2)
- , detail::end_(r2)
- , p
- );
- }
- };
- struct adjacent_find
- {
- template <typename Sig>
- struct result;
- template <typename This, class R>
- struct result<This(R&)>
- : range_iterator<R>
- {};
- template <typename This, class R, class P>
- struct result<This(R&, P)>
- : range_iterator<R>
- {};
- template<class R>
- typename range_iterator<R>::type
- operator()(R& r) const
- {
- return std::adjacent_find(detail::begin_(r), detail::end_(r));
- }
- template<class R, class P>
- typename range_iterator<R>::type
- operator()(R& r, P p) const
- {
- return std::adjacent_find(detail::begin_(r), detail::end_(r), p);
- }
- };
- struct count
- {
- template <typename Sig>
- struct result;
- template <typename This, class R, class T>
- struct result<This(R&, T&)>
- : range_difference<R>
- {};
- template<class R, class T>
- typename range_difference<R>::type
- operator()(R& r, T const& x) const
- {
- return std::count(detail::begin_(r), detail::end_(r), x);
- }
- };
- struct count_if
- {
- template <typename Sig>
- struct result;
- template <typename This, class R, class P>
- struct result<This(R&, P)>
- : range_difference<R>
- {};
- template<class R, class P>
- typename range_difference<R>::type
- operator()(R& r, P p) const
- {
- return std::count_if(detail::begin_(r), detail::end_(r), p);
- }
- };
- struct distance
- {
- template <typename Sig>
- struct result;
- template <typename This, class R>
- struct result<This(R&)>
- : range_difference<R>
- {};
- template<class R>
- typename range_difference<R>::type
- operator()(R& r) const
- {
- return std::distance(detail::begin_(r), detail::end_(r));
- }
- };
- struct equal
- {
- typedef bool result_type;
- template<class R, class I>
- bool operator()(R& r, I i) const
- {
- return std::equal(detail::begin_(r), detail::end_(r), i);
- }
- template<class R, class I, class P>
- bool operator()(R& r, I i, P p) const
- {
- return std::equal(detail::begin_(r), detail::end_(r), i, p);
- }
- };
- struct search
- {
- template <typename Sig>
- struct result;
- template <typename This, class R, typename R2>
- struct result<This(R&, R2&)>
- : range_iterator<R>
- {};
- template <typename This, class R, typename R2, class P>
- struct result<This(R&, R2&, P)>
- : range_iterator<R>
- {};
- template<class R, class R2>
- typename range_iterator<R>::type
- operator()(R& r, R2& r2) const
- {
- return std::search(
- detail::begin_(r)
- , detail::end_(r)
- , detail::begin_(r2)
- , detail::end_(r2)
- );
- }
- template<class R, class R2, class P>
- typename range_iterator<R>::type
- operator()(R& r, R2& r2, P p) const
- {
- return std::search(
- detail::begin_(r)
- , detail::end_(r)
- , detail::begin_(r2)
- , detail::end_(r2)
- , p
- );
- }
- };
- struct lower_bound
- {
- template <typename Sig>
- struct result;
- template <typename This, class R, class T>
- struct result<This(R&, T&)>
- : range_iterator<R>
- {};
- template <typename This, class R, class T, class C>
- struct result<This(R&, T&, C)>
- : range_iterator<R>
- {};
- template<class R, class T>
- typename range_iterator<R>::type
- execute(R& r, T const& val, mpl::true_) const
- {
- return r.lower_bound(val);
- }
- template<class R, class T>
- typename range_iterator<R>::type
- execute(R& r, T const& val, mpl::false_) const
- {
- return std::lower_bound(detail::begin_(r), detail::end_(r), val);
- }
- template<class R, class T>
- typename range_iterator<R>::type
- operator()(R& r, T const& val) const
- {
- return execute(r, val, has_lower_bound<R>());
- }
- template<class R, class T, class C>
- typename range_iterator<R>::type
- operator()(R& r, T const& val, C c) const
- {
- return std::lower_bound(detail::begin_(r), detail::end_(r), val, c);
- }
- };
- struct upper_bound
- {
- template <typename Sig>
- struct result;
- template <typename This, class R, class T>
- struct result<This(R&, T&)>
- : range_iterator<R>
- {};
- template <typename This, class R, class T, class C>
- struct result<This(R&, T&, C)>
- : range_iterator<R>
- {};
- template<class R, class T>
- typename range_iterator<R>::type
- execute(R& r, T const& val, mpl::true_) const
- {
- return r.upper_bound(val);
- }
- template<class R, class T>
- typename range_iterator<R>::type
- execute(R& r, T const& val, mpl::false_) const
- {
- return std::upper_bound(detail::begin_(r), detail::end_(r), val);
- }
- template<class R, class T>
- typename range_iterator<R>::type
- operator()(R& r, T const& val) const
- {
- return execute(r, val, has_upper_bound<R>());
- }
- template<class R, class T, class C>
- typename range_iterator<R>::type
- operator()(R& r, T const& val, C c) const
- {
- return std::upper_bound(detail::begin_(r), detail::end_(r), val, c);
- }
- };
- namespace result_of
- {
- template <typename R, typename T, typename C = void>
- struct equal_range
- {
- typedef std::pair<
- typename range_iterator<R>::type
- , typename range_iterator<R>::type
- > type;
- };
- }
- struct equal_range
- {
- template <typename Sig>
- struct result;
- template <typename This, class R, class T>
- struct result<This(R&, T&)>
- : result_of::equal_range<R,T>
- {};
- template <typename This, class R, class T, class C>
- struct result<This(R&, T&, C)>
- : result_of::equal_range<R,T, C>
- {};
- template<class R, class T>
- typename result_of::equal_range<R, T>::type
- execute(R& r, T const& val, mpl::true_) const
- {
- return r.equal_range(val);
- }
- template<class R, class T>
- typename result_of::equal_range<R, T>::type
- execute(R& r, T const& val, mpl::false_) const
- {
- return std::equal_range(detail::begin_(r), detail::end_(r), val);
- }
- template<class R, class T>
- typename result_of::equal_range<R, T>::type
- operator()(R& r, T const& val) const
- {
- return execute(r, val, has_equal_range<R>());
- }
- template<class R, class T, class C>
- typename result_of::equal_range<R, T, C>::type
- operator()(R& r, T const& val, C c) const
- {
- return std::equal_range(detail::begin_(r), detail::end_(r), val, c);
- }
- };
- namespace result_of
- {
- template <typename R, typename I, typename P = void>
- struct mismatch
- {
- typedef std::pair<
- typename range_iterator<R>::type
- , typename detail::decay_array<I>::type
- > type;
- };
- }
- struct mismatch
- {
- template <typename Sig>
- struct result;
- template<typename This, class R, class I>
- struct result<This(R&, I)>
- : result_of::mismatch<R, I>
- {};
- template<typename This, class R, class I, class P>
- struct result<This(R&, I, P)>
- : result_of::mismatch<R, I, P>
- {};
- template<class R, class I>
- typename result_of::mismatch<R, I>::type
- operator()(R& r, I i) const
- {
- return std::mismatch(detail::begin_(r), detail::end_(r), i);
- }
- template<class R, class I, class P>
- typename result_of::mismatch<R, I, P>::type
- operator()(R& r, I i, P p) const
- {
- return std::mismatch(detail::begin_(r), detail::end_(r), i, p);
- }
- };
- struct binary_search
- {
- typedef bool result_type;
- template<class R, class T>
- bool operator()(R& r, T const& val) const
- {
- return std::binary_search(detail::begin_(r), detail::end_(r), val);
- }
- template<class R, class T, class C>
- bool operator()(R& r, T const& val, C c) const
- {
- return std::binary_search(detail::begin_(r), detail::end_(r), val, c);
- }
- };
- struct includes
- {
- typedef bool result_type;
- template<class R1, class R2>
- bool operator()(R1& r1, R2& r2) const
- {
- return std::includes(
- detail::begin_(r1), detail::end_(r1)
- , detail::begin_(r2), detail::end_(r2)
- );
- }
- template<class R1, class R2, class C>
- bool operator()(R1& r1, R2& r2, C c) const
- {
- return std::includes(
- detail::begin_(r1), detail::end_(r1)
- , detail::begin_(r2), detail::end_(r2)
- , c
- );
- }
- };
- struct min_element
- {
- template <typename Sig>
- struct result;
-
- template <typename This, class R>
- struct result<This(R&)>
- : range_iterator<R>
- {};
- template <typename This, class R, class P>
- struct result<This(R&, P)>
- : range_iterator<R>
- {};
- template<class R>
- typename range_iterator<R>::type
- operator()(R& r) const
- {
- return std::min_element(detail::begin_(r), detail::end_(r));
- }
-
- template<class R, class P>
- typename range_iterator<R>::type
- operator()(R& r, P p) const
- {
- return std::min_element(detail::begin_(r), detail::end_(r), p);
- }
- };
- struct max_element
- {
- template <typename Sig>
- struct result;
- template <typename This, class R>
- struct result<This(R&)>
- : range_iterator<R>
- {};
- template <typename This, class R, class P>
- struct result<This(R&, P)>
- : range_iterator<R>
- {};
- template<class R>
- typename range_iterator<R>::type
- operator()(R& r) const
- {
- return std::max_element(detail::begin_(r), detail::end_(r));
- }
-
- template<class R, class P>
- typename range_iterator<R>::type
- operator()(R& r, P p) const
- {
- return std::max_element(detail::begin_(r), detail::end_(r), p);
- }
- };
- struct lexicographical_compare
- {
- typedef bool result_type;
- template<class R1, class R2>
- bool operator()(R1& r1, R2& r2) const
- {
- return std::lexicographical_compare(
- detail::begin_(r1), detail::end_(r1)
- , detail::begin_(r2), detail::end_(r2)
- );
- }
-
- template<class R1, class R2, class P>
- bool operator()(R1& r1, R2& r2, P p) const
- {
- return std::lexicographical_compare(
- detail::begin_(r1), detail::end_(r1)
- , detail::begin_(r2), detail::end_(r2)
- , p
- );
- }
- };
- }
- BOOST_PHOENIX_ADAPT_CALLABLE(find, impl::find, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(find_if, impl::find_if, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(find_end, impl::find_end, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(find_end, impl::find_end, 3)
- BOOST_PHOENIX_ADAPT_CALLABLE(find_first_of, impl::find_first_of, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(find_first_of, impl::find_first_of, 3)
- BOOST_PHOENIX_ADAPT_CALLABLE(adjacent_find, impl::adjacent_find, 1)
- BOOST_PHOENIX_ADAPT_CALLABLE(adjacent_find, impl::adjacent_find, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(count, impl::count, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(count_if, impl::count_if, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(distance, impl::distance, 1)
- BOOST_PHOENIX_ADAPT_CALLABLE(equal, impl::equal, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(equal, impl::equal, 3)
- BOOST_PHOENIX_ADAPT_CALLABLE(search, impl::search, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(search, impl::search, 3)
- BOOST_PHOENIX_ADAPT_CALLABLE(lower_bound, impl::lower_bound, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(lower_bound, impl::lower_bound, 3)
- BOOST_PHOENIX_ADAPT_CALLABLE(upper_bound, impl::upper_bound, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(upper_bound, impl::upper_bound, 3)
- BOOST_PHOENIX_ADAPT_CALLABLE(equal_range, impl::equal_range, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(equal_range, impl::equal_range, 3)
- BOOST_PHOENIX_ADAPT_CALLABLE(mismatch, impl::mismatch, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(mismatch, impl::mismatch, 3)
- BOOST_PHOENIX_ADAPT_CALLABLE(binary_search, impl::binary_search, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(binary_search, impl::binary_search, 3)
- BOOST_PHOENIX_ADAPT_CALLABLE(includes, impl::includes, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(includes, impl::includes, 3)
- BOOST_PHOENIX_ADAPT_CALLABLE(min_element, impl::min_element, 1)
- BOOST_PHOENIX_ADAPT_CALLABLE(min_element, impl::min_element, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(max_element, impl::max_element, 1)
- BOOST_PHOENIX_ADAPT_CALLABLE(max_element, impl::max_element, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(lexicographical_compare, impl::lexicographical_compare, 2)
- BOOST_PHOENIX_ADAPT_CALLABLE(lexicographical_compare, impl::lexicographical_compare, 3)
- }}
- #endif
|