sl@0: // -- algorithm.hpp -- Boost Lambda Library ----------------------------------- sl@0: // Copyright (C) 2002 Jaakko Järvi (jaakko.jarvi@cs.utu.fi) sl@0: // Copyright (C) 2002 Gary Powell (gwpowell@hotmail.com) sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: // sl@0: // For more information, see http://www.boost.org sl@0: sl@0: #ifndef BOOST_LAMBDA_ALGORITHM_HPP sl@0: #define BOOST_LAMBDA_ALGORITHM_HPP sl@0: sl@0: #include "boost/lambda/core.hpp" sl@0: sl@0: #include sl@0: #include // for iterator_traits sl@0: #include // for std::pair sl@0: sl@0: namespace boost { sl@0: namespace lambda { sl@0: sl@0: namespace ll { sl@0: sl@0: // for_each --------------------------------- sl@0: sl@0: struct for_each { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::for_each(a, b, c); } sl@0: }; sl@0: sl@0: // find --------------------------------- sl@0: sl@0: struct find { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, const C& c) const sl@0: { return ::std::find(a, b, c); } sl@0: }; sl@0: sl@0: sl@0: // find_if --------------------------------- sl@0: sl@0: struct find_if { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::find_if(a, b, c); } sl@0: }; sl@0: sl@0: // find_end --------------------------------- sl@0: sl@0: struct find_end { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c, C d) const sl@0: { return ::std::find_end(a, b, c, d); } sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return ::std::find_end(a, b, c, d, e); } sl@0: sl@0: }; sl@0: sl@0: // find_first_of --------------------------------- sl@0: sl@0: struct find_first_of { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c, C d) const sl@0: { return ::std::find_first_of(a, b, c, d); } sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return ::std::find_first_of(a, b, c, d, e); } sl@0: sl@0: }; sl@0: sl@0: // adjacent_find --------------------------------- sl@0: sl@0: struct adjacent_find { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b) const sl@0: { return ::std::adjacent_find(a, b); } sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::adjacent_find(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // count --------------------------------- sl@0: sl@0: struct count { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename ::std::iterator_traits< sl@0: typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type sl@0: >::difference_type type; sl@0: }; sl@0: sl@0: template sl@0: typename ::std::iterator_traits::difference_type sl@0: operator()(A a, A b, const C& c) const sl@0: { return ::std::count(a, b, c); } sl@0: }; sl@0: sl@0: // count_if --------------------------------- sl@0: sl@0: struct count_if { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename ::std::iterator_traits< sl@0: typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type sl@0: >::difference_type type; sl@0: }; sl@0: sl@0: template sl@0: typename ::std::iterator_traits::difference_type sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::count_if(a, b, c); } sl@0: }; sl@0: sl@0: sl@0: // mismatch --------------------------------- sl@0: sl@0: struct mismatch { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type element1_type; sl@0: sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type element2_type; sl@0: sl@0: typedef ::std::pair< element1_type, element2_type > type; sl@0: }; sl@0: sl@0: template sl@0: ::std::pair sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::mismatch(a, b, c); } sl@0: sl@0: template sl@0: ::std::pair sl@0: operator()(A a, A b, C c, D d) const sl@0: { return ::std::mismatch(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // equal --------------------------------- sl@0: sl@0: struct equal { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef bool type; sl@0: }; sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::equal(a, b, c); } sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b, C c, D d) const sl@0: { return ::std::equal(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // search -------------------------------- sl@0: sl@0: struct search { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c, C d) const sl@0: { return std::search(a, b, c, d);} sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return std::search(a, b, c, d, e);} sl@0: sl@0: }; sl@0: sl@0: // copy --------------------------------- sl@0: sl@0: struct copy { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::copy(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // copy_backward --------------------------------- sl@0: sl@0: struct copy_backward { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::copy_backward(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // swap --------------------------------- sl@0: sl@0: struct swap { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b) const sl@0: { ::std::swap(a, b); } sl@0: sl@0: }; sl@0: sl@0: // swap_ranges --------------------------------- sl@0: sl@0: struct swap_ranges { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::swap_ranges(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // iter_swap --------------------------------- sl@0: sl@0: struct iter_swap { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b) const sl@0: { ::std::iter_swap(a, b); } sl@0: sl@0: }; sl@0: sl@0: sl@0: // transform -------------------------------- sl@0: sl@0: struct transform { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element< sl@0: boost::tuples::length::value - 2, sl@0: Args sl@0: >::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c, D d) const sl@0: { return std::transform(a, b, c, d);} sl@0: sl@0: template sl@0: D sl@0: operator()(A a, A b, C c, D d, E e) const sl@0: { return std::transform(a, b, c, d, e);} sl@0: sl@0: }; sl@0: sl@0: // replace --------------------------------- sl@0: sl@0: struct replace { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, const C& c, const C& d) const sl@0: { ::std::replace(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // replace_if --------------------------------- sl@0: sl@0: struct replace_if { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, C c, const D& d) const sl@0: { ::std::replace_if(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // replace_copy --------------------------------- sl@0: sl@0: struct replace_copy { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c, const D& d, const D& e) const sl@0: { return ::std::replace_copy(a, b, c, d, e); } sl@0: sl@0: }; sl@0: sl@0: // replace_copy_if --------------------------------- sl@0: sl@0: struct replace_copy_if { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c, D d, const E& e) const sl@0: { return ::std::replace_copy_if(a, b, c, d, e); } sl@0: sl@0: }; sl@0: sl@0: // fill --------------------------------- sl@0: sl@0: struct fill { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, const C& c) const sl@0: { ::std::fill(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // fill_n --------------------------------- sl@0: sl@0: struct fill_n { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, B b, const C& c) const sl@0: { ::std::fill_n(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // generate --------------------------------- sl@0: sl@0: struct generate { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, C c) const sl@0: { ::std::generate(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // generate_n --------------------------------- sl@0: sl@0: struct generate_n { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, B b, C c) const sl@0: { ::std::generate_n(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // remove --------------------------------- sl@0: sl@0: struct remove { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, const C& c) const sl@0: { return ::std::remove(a, b, c); } sl@0: }; sl@0: sl@0: // remove_if --------------------------------- sl@0: sl@0: struct remove_if { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::remove_if(a, b, c); } sl@0: }; sl@0: sl@0: // remove_copy --------------------------------- sl@0: sl@0: struct remove_copy { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c, const D& d) const sl@0: { return ::std::remove_copy(a, b, c, d); } sl@0: }; sl@0: sl@0: // remove_copy_if --------------------------------- sl@0: sl@0: struct remove_copy_if { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c, D d) const sl@0: { return ::std::remove_copy_if(a, b, c, d); } sl@0: }; sl@0: sl@0: // unique --------------------------------- sl@0: sl@0: struct unique { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b) const sl@0: { return ::std::unique(a, b); } sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::unique(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // unique_copy --------------------------------- sl@0: sl@0: struct unique_copy { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::unique_copy(a, b, c); } sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c, D d) const sl@0: { return ::std::unique_copy(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // reverse --------------------------------- sl@0: sl@0: struct reverse { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b) const sl@0: { ::std::reverse(a, b); } sl@0: sl@0: }; sl@0: sl@0: // reverse_copy --------------------------------- sl@0: sl@0: struct reverse_copy { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::reverse_copy(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // rotate --------------------------------- sl@0: sl@0: struct rotate { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, A c) const sl@0: { ::std::rotate(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // rotate_copy --------------------------------- sl@0: sl@0: struct rotate_copy { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: D sl@0: operator()(A a, A b, A c, D d) const sl@0: { return ::std::rotate_copy(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // random_shuffle --------------------------------- sl@0: sl@0: struct random_shuffle { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b) const sl@0: { ::std::random_shuffle(a, b); } sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, const C& c) const sl@0: { ::std::random_shuffle(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: sl@0: // partition --------------------------------- sl@0: sl@0: struct partition { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::partition(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // stable_partition --------------------------------- sl@0: sl@0: struct stable_partition { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::stable_partition(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // sort --------------------------------- sl@0: sl@0: struct sort { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b) const sl@0: { ::std::sort(a, b); } sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, C c) const sl@0: { ::std::sort(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // stable_sort --------------------------------- sl@0: sl@0: struct stable_sort { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b) const sl@0: { ::std::stable_sort(a, b); } sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, C c) const sl@0: { ::std::stable_sort(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // partial_sort --------------------------------- sl@0: sl@0: struct partial_sort { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, A c) const sl@0: { ::std::partial_sort(a, b, c); } sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, A c, D d) const sl@0: { ::std::partial_sort(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // partial_sort_copy --------------------------------- sl@0: sl@0: struct partial_sort_copy { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<3, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c, C d) const sl@0: { return ::std::partial_sort_copy(a, b, c, d); } sl@0: sl@0: template sl@0: C sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return ::std::partial_sort_copy(a, b, c, d, e); } sl@0: }; sl@0: sl@0: // nth_element --------------------------------- sl@0: sl@0: struct nth_element { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, A c) const sl@0: { ::std::nth_element(a, b, c); } sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, A c, D d) const sl@0: { ::std::nth_element(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // lower_bound --------------------------------- sl@0: sl@0: struct lower_bound { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, const C& c) const sl@0: { return ::std::lower_bound(a, b, c); } sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, const C& c, D d) const sl@0: { return ::std::lower_bound(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // upper_bound --------------------------------- sl@0: sl@0: struct upper_bound { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, const C& c) const sl@0: { return ::std::upper_bound(a, b, c); } sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, const C& c, D d) const sl@0: { return ::std::upper_bound(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // equal_range --------------------------------- sl@0: sl@0: struct equal_range { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type element_type; sl@0: sl@0: typedef ::std::pair< element_type, element_type > type; sl@0: }; sl@0: sl@0: template sl@0: ::std::pair sl@0: operator()(A a, A b, const C& c) const sl@0: { return ::std::equal_range(a, b, c); } sl@0: sl@0: template sl@0: ::std::pair sl@0: operator()(A a, A b, const C& c, D d) const sl@0: { return ::std::equal_range(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // binary_search --------------------------------- sl@0: sl@0: struct binary_search { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef bool type; sl@0: }; sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b, const C& c) const sl@0: { return ::std::binary_search(a, b, c); } sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b, const C& c, D d) const sl@0: { return ::std::binary_search(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // merge -------------------------------- sl@0: sl@0: struct merge { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<5, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: E sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return std::merge(a, b, c, d, e);} sl@0: sl@0: template sl@0: E sl@0: operator()(A a, A b, C c, C d, E e, F f) const sl@0: { return std::merge(a, b, c, d, e, f);} sl@0: sl@0: }; sl@0: sl@0: // inplace_merge --------------------------------- sl@0: sl@0: struct inplace_merge { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, A c) const sl@0: { ::std::inplace_merge(a, b, c); } sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, A c, D d) const sl@0: { ::std::inplace_merge(a, b, c, d); } sl@0: sl@0: }; sl@0: sl@0: // includes --------------------------------- sl@0: sl@0: struct includes { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef bool type; sl@0: }; sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b, C c, C d) const sl@0: { return ::std::includes(a, b, c, d); } sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return ::std::includes(a, b, c, d, e); } sl@0: sl@0: }; sl@0: sl@0: // set_union -------------------------------- sl@0: sl@0: struct set_union { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<5, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: E sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return std::set_union(a, b, c, d, e);} sl@0: sl@0: template sl@0: E sl@0: operator()(A a, A b, C c, C d, E e, F f) const sl@0: { return std::set_union(a, b, c, d, e, f);} sl@0: sl@0: }; sl@0: sl@0: // set_intersection -------------------------------- sl@0: sl@0: struct set_intersection { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<5, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: E sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return std::set_intersection(a, b, c, d, e);} sl@0: sl@0: template sl@0: E sl@0: operator()(A a, A b, C c, C d, E e, F f) const sl@0: { return std::set_intersection(a, b, c, d, e, f);} sl@0: sl@0: }; sl@0: sl@0: // set_difference -------------------------------- sl@0: sl@0: struct set_difference { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<5, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: E sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return std::set_difference(a, b, c, d, e);} sl@0: sl@0: template sl@0: E sl@0: operator()(A a, A b, C c, C d, E e, F f) const sl@0: { return std::set_difference(a, b, c, d, e, f);} sl@0: sl@0: }; sl@0: sl@0: sl@0: // set_symmetric_difference -------------------------------- sl@0: sl@0: struct set_symmetric_difference { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<5, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: E sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return std::set_symmetric_difference(a, b, c, d, e);} sl@0: sl@0: template sl@0: E sl@0: operator()(A a, A b, C c, C d, E e, F f) const sl@0: { return std::set_symmetric_difference(a, b, c, d, e, f);} sl@0: sl@0: }; sl@0: sl@0: // push_heap --------------------------------- sl@0: sl@0: struct push_heap { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b) const sl@0: { ::std::push_heap(a, b); } sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, C c) const sl@0: { ::std::push_heap(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // pop_heap --------------------------------- sl@0: sl@0: struct pop_heap { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b) const sl@0: { ::std::pop_heap(a, b); } sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, C c) const sl@0: { ::std::pop_heap(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: sl@0: // make_heap --------------------------------- sl@0: sl@0: struct make_heap { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b) const sl@0: { ::std::make_heap(a, b); } sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, C c) const sl@0: { ::std::make_heap(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // sort_heap --------------------------------- sl@0: sl@0: struct sort_heap { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef void type; sl@0: }; sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b) const sl@0: { ::std::sort_heap(a, b); } sl@0: sl@0: template sl@0: void sl@0: operator()(A a, A b, C c) const sl@0: { ::std::sort_heap(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // min --------------------------------- sl@0: sl@0: struct min { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(const A& a, const A& b) const sl@0: { return (::std::min)(a, b); } sl@0: sl@0: template sl@0: A sl@0: operator()(const A& a, const A& b, C c) const sl@0: { return (::std::min)(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // max --------------------------------- sl@0: sl@0: struct max { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(const A& a, const A& b) const sl@0: { return (::std::max)(a, b); } sl@0: sl@0: template sl@0: A sl@0: operator()(const A& a, const A& b, C c) const sl@0: { return (::std::max)(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: struct min_element { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b) const sl@0: { return ::std::min_element(a, b); } sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::min_element(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // max_element --------------------------------- sl@0: sl@0: struct max_element { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef typename boost::remove_const< sl@0: typename boost::tuples::element<1, Args>::type sl@0: >::type type; sl@0: }; sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b) const sl@0: { return ::std::max_element(a, b); } sl@0: sl@0: template sl@0: A sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::max_element(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: sl@0: // lexicographical_compare --------------------------------- sl@0: sl@0: struct lexicographical_compare { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef bool type; sl@0: }; sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b, C c, C d) const sl@0: { return ::std::lexicographical_compare(a, b, c, d); } sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b, C c, C d, E e) const sl@0: { return ::std::lexicographical_compare(a, b, c, d, e); } sl@0: sl@0: }; sl@0: sl@0: // next_permutation --------------------------------- sl@0: sl@0: struct next_permutation { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef bool type; sl@0: }; sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b) const sl@0: { return ::std::next_permutation(a, b); } sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::next_permutation(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: // prev_permutation --------------------------------- sl@0: sl@0: struct prev_permutation { sl@0: sl@0: template sl@0: struct sig { sl@0: typedef bool type; sl@0: }; sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b) const sl@0: { return ::std::prev_permutation(a, b); } sl@0: sl@0: template sl@0: bool sl@0: operator()(A a, A b, C c) const sl@0: { return ::std::prev_permutation(a, b, c); } sl@0: sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: } // end of ll namespace sl@0: sl@0: // There is no good way to call an overloaded member function in a sl@0: // lambda expression. sl@0: // The macro below defines a function object class for calling a sl@0: // const_iterator returning member function of a container. sl@0: sl@0: #define CALL_MEMBER(X) \ sl@0: struct call_##X { \ sl@0: template \ sl@0: struct sig { \ sl@0: typedef typename boost::remove_const< \ sl@0: typename boost::tuples::element<1, Args>::type \ sl@0: >::type::const_iterator type; \ sl@0: }; \ sl@0: \ sl@0: template \ sl@0: typename T::const_iterator \ sl@0: operator()(const T& t) const \ sl@0: { \ sl@0: return t.X(); \ sl@0: } \ sl@0: }; sl@0: sl@0: // create call_begin and call_end classes sl@0: CALL_MEMBER(begin) sl@0: CALL_MEMBER(end) sl@0: sl@0: #undef CALL_MEMBER sl@0: sl@0: } // end of lambda namespace sl@0: } // end of boost namespace sl@0: sl@0: sl@0: sl@0: #endif