// Copyright 2005 Daniel Wallin. // Copyright 2005 Joel de Guzman. // Copyright 2005 Dan Marsden. // 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_TRANSFORMATION_HPP #define BOOST_PHOENIX_ALGORITHM_TRANSFORMATION_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include //#include is deprecated #include #include #include #include namespace boost { namespace phoenix { namespace impl { struct swap { typedef void result_type; template void operator()(A& a, B& b) const { using std::swap; swap(a, b); } }; struct copy { template struct result; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R& r, I i) const { return std::copy(detail::begin_(r), detail::end_(r), i); } }; struct copy_backward { template struct result; template struct result : result {}; template struct result { typedef I type; }; template I operator()(R& r, I & i) const { return std::copy_backward(detail::begin_(r), detail::end_(r), i); } template I const operator()(R& r, I const & i) const { return std::copy_backward(detail::begin_(r), detail::end_(r), i); } }; struct transform { template struct result; template struct result : detail::decay_array { }; template struct result : detail::decay_array { }; template typename result::type operator()(R& r, O o, F f) const { return std::transform(detail::begin_(r), detail::end_(r), o, f); } template typename result::type operator()(R& r, I i, O o, F f) const { return std::transform(detail::begin_(r), detail::end_(r), i, o, f); } }; struct replace { typedef void result_type; template void operator()(R& r, T const& what, T const& with) const { std::replace(detail::begin_(r), detail::end_(r), what, with); } }; struct replace_if { typedef void result_type; template void operator()(R& r, P p, T const& with) const { std::replace_if(detail::begin_(r), detail::end_(r), p, with); } }; struct replace_copy { template struct result; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R& r, O o, T const& what, T const& with) const { return std::replace_copy(detail::begin_(r), detail::end_(r), o, what, with); } }; struct replace_copy_if { template struct result; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R& r, O o, P p, T const& with) const { return std::replace_copy_if(detail::begin_(r), detail::end_(r), o, p, with); } }; struct fill { typedef void result_type; template void operator()(R& r, T const& x) const { std::fill(detail::begin_(r), detail::end_(r), x); } }; struct fill_n { typedef void result_type; template void operator()(R& r, N n, T const& x) const { std::fill_n(detail::begin_(r), n, x); } }; struct generate { typedef void result_type; template void operator()(R& r, G const & g) const { std::generate(detail::begin_(r), detail::end_(r), g); } }; struct generate_n { typedef void result_type; template void operator()(R& r, N n, G g) const { std::generate_n(detail::begin_(r), n, g); } }; struct remove { template struct result; template struct result : range_iterator { }; template typename range_iterator::type execute(R& r, T const& x, mpl::true_) const { r.remove(x); return detail::end_(r); } template typename range_iterator::type execute(R& r, T const& x, mpl::false_) const { return std::remove(detail::begin_(r), detail::end_(r), x); } template typename range_iterator::type operator()(R& r, T const& x) const { return execute(r, x, has_remove()); } }; struct remove_if { template struct result; template struct result : range_iterator { }; template typename range_iterator::type execute(R& r, P p, mpl::true_) const { r.remove_if(p); return detail::end_(r); } template typename range_iterator::type execute(R& r, P p, mpl::false_) const { return std::remove_if(detail::begin_(r), detail::end_(r), p); } template typename range_iterator::type operator()(R& r, P p) const { return execute(r, p, has_remove_if()); } }; struct remove_copy { template struct result; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R& r, O o, T const& x) const { return std::remove_copy(detail::begin_(r), detail::end_(r), o, x); } }; struct remove_copy_if { template struct result; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R& r, O o, P p) const { return std::remove_copy_if(detail::begin_(r), detail::end_(r), o, p); } }; struct unique { template struct result; template struct result : range_iterator {}; template struct result : range_iterator {}; template typename range_iterator::type execute(R& r, mpl::true_) const { r.unique(); return detail::end_(r); } template typename range_iterator::type execute(R& r, mpl::false_) const { return std::unique(detail::begin_(r), detail::end_(r)); } template typename range_iterator::type operator()(R& r) const { return execute(r, has_unique()); } template typename range_iterator::type execute(R& r, P p, mpl::true_) const { r.unique(p); return detail::end_(r); } template typename range_iterator::type execute(R& r, P p, mpl::false_) const { return std::unique(detail::begin_(r), detail::end_(r), p); } template typename range_iterator::type operator()(R& r, P p) const { return execute(r, p, has_unique()); } }; struct unique_copy { template struct result; template struct result : detail::decay_array {}; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R& r, O o) const { return std::unique_copy( detail::begin_(r) , detail::end_(r) , o ); } template typename detail::decay_array::type operator()(R& r, O o, P p) const { return std::unique_copy( detail::begin_(r) , detail::end_(r) , o , p ); } }; struct reverse { typedef void result_type; template void execute(R& r, mpl::true_) const { r.reverse(); } template void execute(R& r, mpl::false_) const { std::reverse(detail::begin_(r), detail::end_(r)); } template void operator()(R& r) const { execute(r, has_reverse()); } }; struct reverse_copy { template struct result; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R& r, O o) const { return std::reverse_copy( detail::begin_(r) , detail::end_(r) , o ); } }; struct rotate { typedef void result_type; template void operator()(R& r, M m) const { std::rotate( detail::begin_(r) , m , detail::end_(r) ); } }; struct rotate_copy { template struct result; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R& r, M m, O o) const { return std::rotate_copy( detail::begin_(r) , m , detail::end_(r) , o ); } }; #ifndef BOOST_NO_CXX98_RANDOM_SHUFFLE struct random_shuffle { typedef void result_type; template void operator()(R& r) const { return std::random_shuffle(detail::begin_(r), detail::end_(r)); } template void operator()(R& r, G g) const { return std::random_shuffle(detail::begin_(r), detail::end_(r), g); } }; #endif struct partition { template struct result; template struct result : range_iterator {}; template typename range_iterator::type operator()(R& r, P p) const { return std::partition(detail::begin_(r), detail::end_(r), p); } }; struct stable_partition { template struct result; template struct result : range_iterator {}; template typename range_iterator::type operator()(R& r, P p) const { return std::stable_partition(detail::begin_(r), detail::end_(r), p); } }; struct sort { typedef void result_type; template void execute(R& r, mpl::true_) const { r.sort(); } template void execute(R& r, mpl::false_) const { std::sort(detail::begin_(r), detail::end_(r)); } template void operator()(R& r) const { execute(r, has_sort()); } template void execute(R& r, C c, mpl::true_) const { r.sort(c); } template void execute(R& r, C c, mpl::false_) const { std::sort(detail::begin_(r), detail::end_(r), c); } template void operator()(R& r, C c) const { execute(r, c, has_sort()); } }; struct stable_sort { typedef void result_type; template void operator()(R& r) const { std::stable_sort(detail::begin_(r), detail::end_(r)); } template void operator()(R& r, C c) const { std::stable_sort(detail::begin_(r), detail::end_(r), c); } }; struct partial_sort { typedef void result_type; template void operator()(R& r, M m) const { std::partial_sort(detail::begin_(r), m, detail::end_(r)); } template void operator()(R& r, M m, C c) const { std::partial_sort(detail::begin_(r), m, detail::end_(r), c); } }; struct partial_sort_copy { template struct result; template struct result : range_iterator {}; template struct result : range_iterator {}; template typename range_iterator::type operator()(R1& r1, R2& r2) const { return std::partial_sort_copy( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) ); } template typename range_iterator::type operator()(R1& r1, R2& r2, C c) const { return std::partial_sort_copy( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , c ); } }; struct nth_element { typedef void result_type; template void operator()(R& r, N n) const { return std::nth_element(detail::begin_(r), n, detail::end_(r)); } template void operator()(R& r, N n, C c) const { return std::nth_element(detail::begin_(r), n, detail::end_(r), c); } }; struct merge { template struct result; template struct result : detail::decay_array {}; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R1& r1, R2& r2, O o) const { return std::merge( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , o ); } template typename detail::decay_array::type operator()(R1& r1, R2& r2, O o, C c) const { return std::merge( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , o , c ); } }; struct inplace_merge { typedef void result_type; template void operator()(R& r, M m) const { return std::inplace_merge(detail::begin_(r), m, detail::end_(r)); } template void operator()(R& r, M m, C c) const { return std::inplace_merge(detail::begin_(r), m, detail::end_(r), c); } }; struct next_permutation { typedef bool result_type; template bool operator()(R& r) const { return std::next_permutation(detail::begin_(r), detail::end_(r)); } template bool operator()(R& r, C c) const { return std::next_permutation(detail::begin_(r), detail::end_(r), c); } }; struct prev_permutation { typedef bool result_type; template bool operator()(R& r) const { return std::prev_permutation(detail::begin_(r), detail::end_(r)); } template bool operator()(R& r, C c) const { return std::prev_permutation(detail::begin_(r), detail::end_(r), c); } }; struct inner_product { template struct result; template struct result : result {}; template struct result { typedef T type; }; template struct result : result {}; template struct result { typedef T type; }; template T operator()(R& r, I i, T t) const { return std::inner_product( detail::begin_(r), detail::end_(r), i, t); } template T operator()(R& r, I i, T t, C1 c1, C2 c2) const { return std::inner_product( detail::begin_(r), detail::end_(r), i, t, c1, c2); } }; struct partial_sum { template struct result; template struct result : detail::decay_array {}; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R& r, I i) const { return std::partial_sum( detail::begin_(r), detail::end_(r), i); } template typename detail::decay_array::type operator()(R& r, I i, C c) const { return std::partial_sum( detail::begin_(r), detail::end_(r), i, c); } }; struct adjacent_difference { template struct result; template struct result : detail::decay_array {}; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R& r, I i) const { return std::adjacent_difference( detail::begin_(r), detail::end_(r), i); } template typename detail::decay_array::type operator()(R& r, I i, C c) const { return std::adjacent_difference( detail::begin_(r), detail::end_(r), i, c); } }; struct push_heap { typedef void result_type; template void operator()(R& r) const { std::push_heap(detail::begin_(r), detail::end_(r)); } template void operator()(R& r, C c) const { std::push_heap(detail::begin_(r), detail::end_(r), c); } }; struct pop_heap { typedef void result_type; template void operator()(R& r) const { std::pop_heap(detail::begin_(r), detail::end_(r)); } template void operator()(R& r, C c) const { std::pop_heap(detail::begin_(r), detail::end_(r), c); } }; struct make_heap { typedef void result_type; template void operator()(R& r) const { std::make_heap(detail::begin_(r), detail::end_(r)); } template void operator()(R& r, C c) const { std::make_heap(detail::begin_(r), detail::end_(r), c); } }; struct sort_heap { typedef void result_type; template void operator()(R& r) const { std::sort_heap(detail::begin_(r), detail::end_(r)); } template void operator()(R& r, C c) const { std::sort_heap(detail::begin_(r), detail::end_(r), c); } }; struct set_union { template struct result; template struct result : detail::decay_array {}; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R1& r1, R2& r2, O o) const { return std::set_union( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , o ); } template typename detail::decay_array::type operator()(R1& r1, R2& r2, O o, C c) const { return std::set_union( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , o , c ); } }; struct set_intersection { template struct result; template struct result : detail::decay_array {}; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R1& r1, R2& r2, O o) const { return std::set_intersection( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , o ); } template typename detail::decay_array::type operator()(R1& r1, R2& r2, O o, C c) const { return std::set_intersection( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , o , c ); } }; struct set_difference { template struct result; template struct result : detail::decay_array {}; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R1& r1, R2& r2, O o) const { return std::set_difference( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , o ); } template typename detail::decay_array::type operator()(R1& r1, R2& r2, O o, C c) const { return std::set_difference( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , o , c ); } }; struct set_symmetric_difference { template struct result; template struct result : detail::decay_array {}; template struct result : detail::decay_array {}; template typename detail::decay_array::type operator()(R1& r1, R2& r2, O o) const { return std::set_symmetric_difference( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , o ); } template typename detail::decay_array::type operator()(R1& r1, R2& r2, O o, C c) const { return std::set_symmetric_difference( detail::begin_(r1), detail::end_(r1) , detail::begin_(r2), detail::end_(r2) , o , c ); } }; }}} // boost::phoenix::impl namespace boost { namespace phoenix { BOOST_PHOENIX_ADAPT_CALLABLE(swap, impl::swap, 2) BOOST_PHOENIX_ADAPT_CALLABLE(copy, impl::copy, 2) BOOST_PHOENIX_ADAPT_CALLABLE(copy_backward, impl::copy_backward, 2) BOOST_PHOENIX_ADAPT_CALLABLE(transform, impl::transform, 3) BOOST_PHOENIX_ADAPT_CALLABLE(transform, impl::transform, 4) BOOST_PHOENIX_ADAPT_CALLABLE(replace, impl::replace, 3) BOOST_PHOENIX_ADAPT_CALLABLE(replace_if, impl::replace_if, 3) BOOST_PHOENIX_ADAPT_CALLABLE(replace_copy, impl::replace_copy, 4) BOOST_PHOENIX_ADAPT_CALLABLE(replace_copy_if, impl::replace_copy_if, 4) BOOST_PHOENIX_ADAPT_CALLABLE(fill, impl::fill, 2) BOOST_PHOENIX_ADAPT_CALLABLE(fill_n, impl::fill_n, 3) BOOST_PHOENIX_ADAPT_CALLABLE(generate, impl::generate, 2) BOOST_PHOENIX_ADAPT_CALLABLE(generate_n, impl::generate_n, 3) BOOST_PHOENIX_ADAPT_CALLABLE(remove, impl::remove, 2) BOOST_PHOENIX_ADAPT_CALLABLE(remove_if, impl::remove_if, 2) BOOST_PHOENIX_ADAPT_CALLABLE(remove_copy, impl::remove_copy, 3) BOOST_PHOENIX_ADAPT_CALLABLE(remove_copy_if, impl::remove_copy_if, 3) BOOST_PHOENIX_ADAPT_CALLABLE(unique, impl::unique, 1) BOOST_PHOENIX_ADAPT_CALLABLE(unique, impl::unique, 2) BOOST_PHOENIX_ADAPT_CALLABLE(unique_copy, impl::unique_copy, 2) BOOST_PHOENIX_ADAPT_CALLABLE(unique_copy, impl::unique_copy, 3) BOOST_PHOENIX_ADAPT_CALLABLE(reverse, impl::reverse, 1) BOOST_PHOENIX_ADAPT_CALLABLE(reverse_copy, impl::reverse_copy, 2) BOOST_PHOENIX_ADAPT_CALLABLE(rotate, impl::rotate, 2) BOOST_PHOENIX_ADAPT_CALLABLE(rotate_copy, impl::rotate_copy, 3) #ifndef BOOST_NO_CXX98_RANDOM_SHUFFLE BOOST_PHOENIX_ADAPT_CALLABLE(random_shuffle, impl::random_shuffle, 1) BOOST_PHOENIX_ADAPT_CALLABLE(random_shuffle, impl::random_shuffle, 2) #endif BOOST_PHOENIX_ADAPT_CALLABLE(partition, impl::partition, 2) BOOST_PHOENIX_ADAPT_CALLABLE(stable_partition, impl::stable_partition, 2) BOOST_PHOENIX_ADAPT_CALLABLE(sort, impl::sort, 1) BOOST_PHOENIX_ADAPT_CALLABLE(sort, impl::sort, 2) BOOST_PHOENIX_ADAPT_CALLABLE(stable_sort, impl::stable_sort, 1) BOOST_PHOENIX_ADAPT_CALLABLE(stable_sort, impl::stable_sort, 2) BOOST_PHOENIX_ADAPT_CALLABLE(partial_sort, impl::partial_sort, 2) BOOST_PHOENIX_ADAPT_CALLABLE(partial_sort, impl::partial_sort, 3) BOOST_PHOENIX_ADAPT_CALLABLE(partial_sort_copy, impl::partial_sort_copy, 2) BOOST_PHOENIX_ADAPT_CALLABLE(partial_sort_copy, impl::partial_sort_copy, 3) BOOST_PHOENIX_ADAPT_CALLABLE(nth_element, impl::nth_element, 2) BOOST_PHOENIX_ADAPT_CALLABLE(nth_element, impl::nth_element, 3) BOOST_PHOENIX_ADAPT_CALLABLE(merge, impl::merge, 3) BOOST_PHOENIX_ADAPT_CALLABLE(merge, impl::merge, 4) BOOST_PHOENIX_ADAPT_CALLABLE(inplace_merge, impl::inplace_merge, 2) BOOST_PHOENIX_ADAPT_CALLABLE(inplace_merge, impl::inplace_merge, 3) BOOST_PHOENIX_ADAPT_CALLABLE(next_permutation, impl::next_permutation, 1) BOOST_PHOENIX_ADAPT_CALLABLE(next_permutation, impl::next_permutation, 2) BOOST_PHOENIX_ADAPT_CALLABLE(prev_permutation, impl::prev_permutation, 1) BOOST_PHOENIX_ADAPT_CALLABLE(prev_permutation, impl::prev_permutation, 2) BOOST_PHOENIX_ADAPT_CALLABLE(inner_product, impl::inner_product, 3) BOOST_PHOENIX_ADAPT_CALLABLE(inner_product, impl::inner_product, 5) BOOST_PHOENIX_ADAPT_CALLABLE(partial_sum, impl::partial_sum, 2) BOOST_PHOENIX_ADAPT_CALLABLE(partial_sum, impl::partial_sum, 3) BOOST_PHOENIX_ADAPT_CALLABLE(adjacent_difference, impl::adjacent_difference, 2) BOOST_PHOENIX_ADAPT_CALLABLE(adjacent_difference, impl::adjacent_difference, 3) BOOST_PHOENIX_ADAPT_CALLABLE(push_heap, impl::push_heap, 1) BOOST_PHOENIX_ADAPT_CALLABLE(push_heap, impl::push_heap, 2) BOOST_PHOENIX_ADAPT_CALLABLE(pop_heap, impl::pop_heap, 1) BOOST_PHOENIX_ADAPT_CALLABLE(pop_heap, impl::pop_heap, 2) BOOST_PHOENIX_ADAPT_CALLABLE(make_heap, impl::make_heap, 1) BOOST_PHOENIX_ADAPT_CALLABLE(make_heap, impl::make_heap, 2) BOOST_PHOENIX_ADAPT_CALLABLE(sort_heap, impl::sort_heap, 1) BOOST_PHOENIX_ADAPT_CALLABLE(sort_heap, impl::sort_heap, 2) BOOST_PHOENIX_ADAPT_CALLABLE(set_union, impl::set_union, 3) BOOST_PHOENIX_ADAPT_CALLABLE(set_union, impl::set_union, 4) BOOST_PHOENIX_ADAPT_CALLABLE(set_intersection, impl::set_intersection, 3) BOOST_PHOENIX_ADAPT_CALLABLE(set_intersection, impl::set_intersection, 4) BOOST_PHOENIX_ADAPT_CALLABLE(set_difference, impl::set_difference, 3) BOOST_PHOENIX_ADAPT_CALLABLE(set_difference, impl::set_difference, 4) BOOST_PHOENIX_ADAPT_CALLABLE(set_symmetric_difference, impl::set_symmetric_difference, 3) BOOST_PHOENIX_ADAPT_CALLABLE(set_symmetric_difference, impl::set_symmetric_difference, 4) }} #endif