# wilhelmtell/wtl

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
747 lines (637 sloc) 21.5 KB
 #ifndef ALGORITHM_ISEQ_HH_ #define ALGORITHM_ISEQ_HH_ /////////////////////////////////////////////////////////////////////////////// /// STL extensions /// /// iseq algorithms are wrappers for algorithms that make calling the /// algorithms slightly easier. These wrappers take a single parameter, called /// an "iseq" (for "input sequence"), instead of the usual two iterators that /// represent the range the algorithm will act upon. The iseq expresses the /// entire range from begin to end of a sequence. Thus, algorithm(iseq(c)) == /// algorithm(c.begin(), c.end()) /// /// The iseq() function is a helper for creating an object of the class /// input_sequence_range, which holds the range begin-to-end of the given /// container. /// /// January 2009 /// /// Matan Nassau /////////////////////////////////////////////////////////////////////////////// #include #include #include namespace wt { // WRAPPERS FOR STANDARD ALGORITHMS template Fwd adjacent_find(input_sequence_range range) { return std::adjacent_find(range.first, range.second); } template Fwd adjacent_find(input_sequence_range range, BinPred op) { return std::adjacent_find(range.first, range.second, op); } template Op for_each(input_sequence_range range, Op op) { return std::for_each(range.first, range.second, op); } template In find(input_sequence_range range, const V& val) { return std::find(range.first, range.second, val); } template In find_if(input_sequence_range range, Pred op) { return std::find_if(range.first, range.second, op); } template Fwd find_first_of(input_sequence_range range, input_sequence_range range2) { return std::find_first_of(range.first, range.second, range2.first, range2.second); } template Fwd find_first_of(input_sequence_range range, input_sequence_range range2, BinPred op) { return std::find_first_of(range.first, range.second, range2.first, range2.second, op); } template typename std::iterator_traits::difference_type count(input_sequence_range range, const V& val) { return std::count(range.first, range.second, val); } template typename std::iterator_traits::difference_type count_if(input_sequence_range range, const V& val, BinPred op) { return std::count(range.first, range.second, val, op); } template bool equal(input_sequence_range range, input_sequence_range range2) { return std::equal(range.first, range.second, range2.first, range2.second); } template bool equal(input_sequence_range range, input_sequence_range range2, BinPred op) { return std::equal(range.first, range.second, range2.first, range2.second, op); } template std::pair mismatch(input_sequence_range range, In2 first2) { return std::mismatch(range.first, range.second, first2); } template std::pair mismatch(input_sequence_range range, In2 first2, BinPred op) { return std::mismatch(range.first, range.second, first2, op); } template Fwd search(input_sequence_range range, input_sequence_range range2) { return std::search(range.first, range.second, range2.first, range2.second); } template Fwd search(input_sequence_range range, input_sequence_range range2, BinPred op) { return std::search(range.first, range.second, range2.first, range2.second, op); } template Fwd find_end(input_sequence_range range, input_sequence_range range2) { return std::find_end(range.first, range.second, range2.first, range2.second); } template Fwd find_end(input_sequence_range range, input_sequence_range range2, BinPred op) { return std::find_end(range.first, range.second, range2.first, range2.second, op); } template Fwd search_n(input_sequence_range range, Size n, const V& val) { return std::search_n(range.first, range.second, n, val); } template Fwd search_n(input_sequence_range range, Size n, const V& val, BinPred op) { return std::search(range.first, range.second, n, val, op); } template Out copy(input_sequence_range range, Out result) { return std::copy(range.first, range.second, result); } template Bi2 copy_backward(input_sequence_range range, Bi2 result) { return std::copy_backward(range.first, range.second, result); } template Out transform(input_sequence_range range, Out res, Op op) { return std::transform(range.first, range.second, res, op); } template Out transform(input_sequence_range range, input_sequence_range range2, Out res, Op op) { return std::transform(range.first, range.second, range2.first, range2.second, res, op); } template Fwd unique(input_sequence_range range) { return std::unique(range.first, range.second); } template Fwd unique(input_sequence_range range, BinPred op) { return std::unique(range.first, range.second, op); } template Out unique_copy(input_sequence_range range, Out res) { return std::unique_copy(range.first, range.second, res); } template Out unique_copy(input_sequence_range range, Out res, BinPred op) { return std::unique_copy(range.first, range.second, res, op); } template void replace(input_sequence_range range, const V& val, const V& new_val) { std::replace(range.first, range.second, val, new_val); } template void replace_if(input_sequence_range range, Pred op, const V& new_val) { std::replace_if(range.first, range.second, op, new_val); } template void replace_copy(input_sequence_range range, Out res, const V& val, const V& new_val) { std::replace_copy(range.first, range.second, res, val, new_val); } template void replace_copy_if(input_sequence_range range, Out res, Pred op, const V& new_val) { std::replace_copy_if(range.first, range.second, res, op, new_val); } template Fwd remove(input_sequence_range range, const V& val) { return std::remove(range.first, range.second, val); } template Fwd remove_if(input_sequence_range range, Pred op) { return std::remove_if(range.first, range.second, op); } template Out remove_copy(input_sequence_range range, Out res, const V& val) { return std::remove_copy(range.first, range.second, res, val); } template Out remove_copy_if(input_sequence_range range, Out res, Pred op) { return std::remove_copy_if(range.first, range.second, res, op); } template void fill(input_sequence_range range, const V& val) { std::fill(range.first, range.second, val); } template void generate(input_sequence_range range, Gen g) { std::generate(range.first, range.second, g); } template void reverse(input_sequence_range range) { std::reverse(range.first, range.second); } template Out reverse_copy(input_sequence_range range, Out res) { return std::reverse_copy(range.first, range.second, res); } template void rotate(input_sequence_range range, Fwd middle) { std::rotate(range.first, middle, range.second); } template Out rotate_copy(input_sequence_range range, Fwd middle, Out res) { return std::rotate_copy(range.first, middle, range.second, res); } template void random_shuffle(input_sequence_range range) { std::random_shuffle(range.first, range.second); } template void random_shuffle(input_sequence_range range, Gen& g) { std::random_shuffle(range.first, range.second, g); } template Fwd2 swap_ranges(input_sequence_range range, Fwd2 first2) { return std::swap_ranges(range.first, range.second, first2); } template void sort(input_sequence_range range) { std::sort(range.first, range.second); } template void sort(input_sequence_range range, Cmp c) { std::sort(range.first, range.second, c); } template void stable_sort(input_sequence_range range) { std::sort(range.first, range.second); } template void stable_sort(input_sequence_range range, Cmp c) { std::sort(range.first, range.second, c); } template void partial_sort(input_sequence_range range, Ran middle) { std::partial_sort(range.first, middle, range.second); } template void partial_sort(input_sequence_range range, Ran middle, Cmp c) { std::partial_sort(range.first, middle, range.second, c); } template Ran partial_sort_copy(input_sequence_range range, input_sequence_range range2) { return std::partial_sort(range.first, range.second, range2.first, range2.second); } template Ran partial_sort_copy(input_sequence_range range, input_sequence_range range2, Cmp c) { return std::partial_sort(range.first, range.second, range2.first, range2.second, c); } template void nth_element(input_sequence_range range, Ran nth) { std::nth_element(range.first, nth, range.second); } template void nth_element(input_sequence_range range, Ran nth, Cmp c) { std::nth_element(range.first, nth, range.second, c); } template bool binary_search(input_sequence_range range, const V& val) { return std::binary_search(range.first, range.second, val); } template bool binary_search(input_sequence_range range, const V& val, Cmp c) { return std::binary_search(range.first, range.second, val, c); } template Fwd lower_bound(input_sequence_range range, const V& val) { return std::lower_bound(range.first, range.second, val); } template Fwd lower_bound(input_sequence_range range, const V& val, Cmp c) { return std::lower_bound(range.first, range.second, val, c); } template Fwd upper_bound(input_sequence_range range, const V& val) { return std::upper_bound(range.first, range.second, val); } template Fwd upper_bound(input_sequence_range range, const V& val, Cmp c) { return std::upper_bound(range.first, range.second, val, c); } template std::pair equal_range(input_sequence_range range, const V& val) { return std::equal_range(range.first, range.second, val); } template std::pair equal_range(input_sequence_range range, const V& val, Cmp c) { return std::equal_range(range.first, range.second, val, c); } template Out merge(input_sequence_range range, input_sequence_range range2, Out res) { return std::merge(range.first, range.second, range2.first, range2.second, res); } template Out merge(input_sequence_range range, input_sequence_range range2, Out res, Cmp c) { return std::merge(range.first, range.second, range2.first, range2.second, res, c); } template void inplace_merge(input_sequence_range range, Bi middle) { std::inplace_merge(range.first, middle, range.second); } template void inplace_merge(input_sequence_range range, Bi middle, Cmp c) { std::inplace_merge(range.first, middle, range.second, c); } template Bi partition(input_sequence_range range, Pred op) { return std::partition(range.first, range.second, op); } template Bi stable_partition(input_sequence_range range, Pred op) { return std::stable_partition(range.first, range.second, op); } template bool includes(input_sequence_range range, input_sequence_range range2) { return std::includes(range.first, range.second, range2.first, range2.second); } template bool includes(input_sequence_range range, input_sequence_range range2, Cmp c) { return std::includes(range.first, range.second, range2.first, range2.second, c); } template Out set_union(input_sequence_range range, input_sequence_range range2, Out res) { return std::set_union(range.first, range.second, range.first, range.second, res); } template Out set_union(input_sequence_range range, input_sequence_range range2, Out res, Cmp c) { return std::set_union(range.first, range.second, range.first, range.second, res, c); } template Out set_intersection(input_sequence_range range, input_sequence_range range2, Out res) { return std::set_intersection(range.first, range.second, range.first, range.second, res); } template Out set_intersection(input_sequence_range range, input_sequence_range range2, Out res, Cmp c) { return std::set_intersection(range.first, range.second, range.first, range.second, res, c); } template Out set_difference(input_sequence_range range, input_sequence_range range2, Out res) { return std::set_difference(range.first, range.second, range.first, range.second, res); } template Out set_difference(input_sequence_range range, input_sequence_range range2, Out res, Cmp c) { return std::set_difference(range.first, range.second, range.first, range.second, res, c); } template Out set_symmetric_difference(input_sequence_range range, input_sequence_range range2, Out res) { return std::set_symmetric_difference(range.first, range.second, range.first, range.second, res); } template Out set_symmetric_difference(input_sequence_range range, input_sequence_range range2, Out res, Cmp c) { return std::set_symmetric_difference(range.first, range.second, range.first, range.second, res, c); } template void push_heap(input_sequence_range range) { std::push_heap(range.first, range.second); } template void push_heap(input_sequence_range range, Cmp c) { std::push_heap(range.first, range.second, c); } template void pop_heap(input_sequence_range range) { std::pop_heap(range.first, range.second); } template void pop_heap(input_sequence_range range, Cmp c) { std::pop_heap(range.first, range.second, c); } template void make_heap(input_sequence_range range) { std::make_heap(range.first, range.second); } template void make_heap(input_sequence_range range, Cmp c) { std::make_heap(range.first, range.second, c); } template void sort_heap(input_sequence_range range) { std::sort_heap(range.first, range.second); } template void sort_heap(input_sequence_range range, Cmp c) { std::sort_heap(range.first, range.second, c); } template Fwd min_element(input_sequence_range range) { return std::min_element(range.first, range.second); } template Fwd min_element(input_sequence_range range, Cmp c) { return std::min_element(range.first, range.second, c); } template Fwd max_element(input_sequence_range range) { return std::max_element(range.first, range.second); } template Fwd max_element(input_sequence_range range, Cmp c) { return std::max_element(range.first, range.second, c); } template bool lexicographical_compare(input_sequence_range range, input_sequence_range range2) { return std::lexicographical_compare(range.first, range.second, range2.first, range2.second); } template bool lexicographical_compare(input_sequence_range range, input_sequence_range range2, Cmp c) { return std::lexicographical_compare(range.first, range.second, range2.first, range2.second, c); } template bool next_permutation(input_sequence_range range) { return std::next_permutation(range.first, range.second); } template bool next_permutation(input_sequence_range range, Cmp c) { return std::next_permutation(range.first, range.second, c); } template bool prev_permutation(input_sequence_range range) { return std::prev_permutation(range.first, range.second); } template bool prev_permutation(input_sequence_range range, Cmp c) { return std::prev_permutation(range.first, range.second, c); } // WRAPPERS FOR EXTENSION ALGORITHMS template Out copy_if(input_sequence_range range, Out res, Pred op) { return copy_if(range.first, range.second, res, op); } template std::pair match(input_sequence_range range, input_sequence_range range2) { return match(range.first, range.second, range2.first, range2.second); } template std::pair match(input_sequence_range range, input_sequence_range range2, BinPred op) { return match(range.first, range.second, range2.first, range2.second, op); } template In find_first_not_of(input_sequence_range range, input_sequence_range range2) { return find_first_not_of(range.first, range.second, range2.first, range2.second); } template In find_first_not_of(input_sequence_range range, input_sequence_range range2, BinPred op) { return find_first_not_of(range.first, range.second, range2.first, range2.second, op); } } // namespace wt #endif // ALGORITHM_ISEQ_HH_