container.h
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 //
00015 // -----------------------------------------------------------------------------
00016 // File: container.h
00017 // -----------------------------------------------------------------------------
00018 //
00019 // This header file provides Container-based versions of algorithmic functions
00020 // within the C++ standard library. The following standard library sets of
00021 // functions are covered within this file:
00022 //
00023 //   * Algorithmic <iterator> functions
00024 //   * Algorithmic <numeric> functions
00025 //   * <algorithm> functions
00026 //
00027 // The standard library functions operate on iterator ranges; the functions
00028 // within this API operate on containers, though many return iterator ranges.
00029 //
00030 // All functions within this API are named with a `c_` prefix. Calls such as
00031 // `absl::c_xx(container, ...) are equivalent to std:: functions such as
00032 // `std::xx(std::begin(cont), std::end(cont), ...)`. Functions that act on
00033 // iterators but not conceptually on iterator ranges (e.g. `std::iter_swap`)
00034 // have no equivalent here.
00035 //
00036 // For template parameter and variable naming, `C` indicates the container type
00037 // to which the function is applied, `Pred` indicates the predicate object type
00038 // to be used by the function and `T` indicates the applicable element type.
00039 
00040 #ifndef ABSL_ALGORITHM_CONTAINER_H_
00041 #define ABSL_ALGORITHM_CONTAINER_H_
00042 
00043 #include <algorithm>
00044 #include <cassert>
00045 #include <iterator>
00046 #include <numeric>
00047 #include <type_traits>
00048 #include <unordered_map>
00049 #include <unordered_set>
00050 #include <utility>
00051 #include <vector>
00052 
00053 #include "absl/algorithm/algorithm.h"
00054 #include "absl/base/macros.h"
00055 #include "absl/meta/type_traits.h"
00056 
00057 namespace absl {
00058 namespace container_algorithm_internal {
00059 
00060 // NOTE: it is important to defer to ADL lookup for building with C++ modules,
00061 // especially for headers like <valarray> which are not visible from this file
00062 // but specialize std::begin and std::end.
00063 using std::begin;
00064 using std::end;
00065 
00066 // The type of the iterator given by begin(c) (possibly std::begin(c)).
00067 // ContainerIter<const vector<T>> gives vector<T>::const_iterator,
00068 // while ContainerIter<vector<T>> gives vector<T>::iterator.
00069 template <typename C>
00070 using ContainerIter = decltype(begin(std::declval<C&>()));
00071 
00072 // An MSVC bug involving template parameter substitution requires us to use
00073 // decltype() here instead of just std::pair.
00074 template <typename C1, typename C2>
00075 using ContainerIterPairType =
00076     decltype(std::make_pair(ContainerIter<C1>(), ContainerIter<C2>()));
00077 
00078 template <typename C>
00079 using ContainerDifferenceType =
00080     decltype(std::distance(std::declval<ContainerIter<C>>(),
00081                            std::declval<ContainerIter<C>>()));
00082 
00083 template <typename C>
00084 using ContainerPointerType =
00085     typename std::iterator_traits<ContainerIter<C>>::pointer;
00086 
00087 // container_algorithm_internal::c_begin and
00088 // container_algorithm_internal::c_end are abbreviations for proper ADL
00089 // lookup of std::begin and std::end, i.e.
00090 //   using std::begin;
00091 //   using std::end;
00092 //   std::foo(begin(c), end(c);
00093 // becomes
00094 //   std::foo(container_algorithm_internal::begin(c),
00095 //   container_algorithm_internal::end(c));
00096 // These are meant for internal use only.
00097 
00098 template <typename C>
00099 ContainerIter<C> c_begin(C& c) { return begin(c); }
00100 
00101 template <typename C>
00102 ContainerIter<C> c_end(C& c) { return end(c); }
00103 
00104 template <typename T>
00105 struct IsUnorderedContainer : std::false_type {};
00106 
00107 template <class Key, class T, class Hash, class KeyEqual, class Allocator>
00108 struct IsUnorderedContainer<
00109     std::unordered_map<Key, T, Hash, KeyEqual, Allocator>> : std::true_type {};
00110 
00111 template <class Key, class Hash, class KeyEqual, class Allocator>
00112 struct IsUnorderedContainer<std::unordered_set<Key, Hash, KeyEqual, Allocator>>
00113     : std::true_type {};
00114 
00115 }  // namespace container_algorithm_internal
00116 
00117 // PUBLIC API
00118 
00119 //------------------------------------------------------------------------------
00120 // Abseil algorithm.h functions
00121 //------------------------------------------------------------------------------
00122 
00123 // c_linear_search()
00124 //
00125 // Container-based version of absl::linear_search() for performing a linear
00126 // search within a container.
00127 template <typename C, typename EqualityComparable>
00128 bool c_linear_search(const C& c, EqualityComparable&& value) {
00129   return linear_search(container_algorithm_internal::c_begin(c),
00130                        container_algorithm_internal::c_end(c),
00131                        std::forward<EqualityComparable>(value));
00132 }
00133 
00134 //------------------------------------------------------------------------------
00135 // <iterator> algorithms
00136 //------------------------------------------------------------------------------
00137 
00138 // c_distance()
00139 //
00140 // Container-based version of the <iterator> `std::distance()` function to
00141 // return the number of elements within a container.
00142 template <typename C>
00143 container_algorithm_internal::ContainerDifferenceType<const C> c_distance(
00144     const C& c) {
00145   return std::distance(container_algorithm_internal::c_begin(c),
00146                        container_algorithm_internal::c_end(c));
00147 }
00148 
00149 //------------------------------------------------------------------------------
00150 // <algorithm> Non-modifying sequence operations
00151 //------------------------------------------------------------------------------
00152 
00153 // c_all_of()
00154 //
00155 // Container-based version of the <algorithm> `std::all_of()` function to
00156 // test a condition on all elements within a container.
00157 template <typename C, typename Pred>
00158 bool c_all_of(const C& c, Pred&& pred) {
00159   return std::all_of(container_algorithm_internal::c_begin(c),
00160                      container_algorithm_internal::c_end(c),
00161                      std::forward<Pred>(pred));
00162 }
00163 
00164 // c_any_of()
00165 //
00166 // Container-based version of the <algorithm> `std::any_of()` function to
00167 // test if any element in a container fulfills a condition.
00168 template <typename C, typename Pred>
00169 bool c_any_of(const C& c, Pred&& pred) {
00170   return std::any_of(container_algorithm_internal::c_begin(c),
00171                      container_algorithm_internal::c_end(c),
00172                      std::forward<Pred>(pred));
00173 }
00174 
00175 // c_none_of()
00176 //
00177 // Container-based version of the <algorithm> `std::none_of()` function to
00178 // test if no elements in a container fulfil a condition.
00179 template <typename C, typename Pred>
00180 bool c_none_of(const C& c, Pred&& pred) {
00181   return std::none_of(container_algorithm_internal::c_begin(c),
00182                       container_algorithm_internal::c_end(c),
00183                       std::forward<Pred>(pred));
00184 }
00185 
00186 // c_for_each()
00187 //
00188 // Container-based version of the <algorithm> `std::for_each()` function to
00189 // apply a function to a container's elements.
00190 template <typename C, typename Function>
00191 decay_t<Function> c_for_each(C&& c, Function&& f) {
00192   return std::for_each(container_algorithm_internal::c_begin(c),
00193                        container_algorithm_internal::c_end(c),
00194                        std::forward<Function>(f));
00195 }
00196 
00197 // c_find()
00198 //
00199 // Container-based version of the <algorithm> `std::find()` function to find
00200 // the first element containing the passed value within a container value.
00201 template <typename C, typename T>
00202 container_algorithm_internal::ContainerIter<C> c_find(C& c, T&& value) {
00203   return std::find(container_algorithm_internal::c_begin(c),
00204                    container_algorithm_internal::c_end(c),
00205                    std::forward<T>(value));
00206 }
00207 
00208 // c_find_if()
00209 //
00210 // Container-based version of the <algorithm> `std::find_if()` function to find
00211 // the first element in a container matching the given condition.
00212 template <typename C, typename Pred>
00213 container_algorithm_internal::ContainerIter<C> c_find_if(C& c, Pred&& pred) {
00214   return std::find_if(container_algorithm_internal::c_begin(c),
00215                       container_algorithm_internal::c_end(c),
00216                       std::forward<Pred>(pred));
00217 }
00218 
00219 // c_find_if_not()
00220 //
00221 // Container-based version of the <algorithm> `std::find_if_not()` function to
00222 // find the first element in a container not matching the given condition.
00223 template <typename C, typename Pred>
00224 container_algorithm_internal::ContainerIter<C> c_find_if_not(C& c,
00225                                                              Pred&& pred) {
00226   return std::find_if_not(container_algorithm_internal::c_begin(c),
00227                           container_algorithm_internal::c_end(c),
00228                           std::forward<Pred>(pred));
00229 }
00230 
00231 // c_find_end()
00232 //
00233 // Container-based version of the <algorithm> `std::find_end()` function to
00234 // find the last subsequence within a container.
00235 template <typename Sequence1, typename Sequence2>
00236 container_algorithm_internal::ContainerIter<Sequence1> c_find_end(
00237     Sequence1& sequence, Sequence2& subsequence) {
00238   return std::find_end(container_algorithm_internal::c_begin(sequence),
00239                        container_algorithm_internal::c_end(sequence),
00240                        container_algorithm_internal::c_begin(subsequence),
00241                        container_algorithm_internal::c_end(subsequence));
00242 }
00243 
00244 // Overload of c_find_end() for using a predicate evaluation other than `==` as
00245 // the function's test condition.
00246 template <typename Sequence1, typename Sequence2, typename BinaryPredicate>
00247 container_algorithm_internal::ContainerIter<Sequence1> c_find_end(
00248     Sequence1& sequence, Sequence2& subsequence, BinaryPredicate&& pred) {
00249   return std::find_end(container_algorithm_internal::c_begin(sequence),
00250                        container_algorithm_internal::c_end(sequence),
00251                        container_algorithm_internal::c_begin(subsequence),
00252                        container_algorithm_internal::c_end(subsequence),
00253                        std::forward<BinaryPredicate>(pred));
00254 }
00255 
00256 // c_find_first_of()
00257 //
00258 // Container-based version of the <algorithm> `std::find_first_of()` function to
00259 // find the first elements in an ordered set within a container.
00260 template <typename C1, typename C2>
00261 container_algorithm_internal::ContainerIter<C1> c_find_first_of(C1& container,
00262                                                                 C2& options) {
00263   return std::find_first_of(container_algorithm_internal::c_begin(container),
00264                             container_algorithm_internal::c_end(container),
00265                             container_algorithm_internal::c_begin(options),
00266                             container_algorithm_internal::c_end(options));
00267 }
00268 
00269 // Overload of c_find_first_of() for using a predicate evaluation other than
00270 // `==` as the function's test condition.
00271 template <typename C1, typename C2, typename BinaryPredicate>
00272 container_algorithm_internal::ContainerIter<C1> c_find_first_of(
00273     C1& container, C2& options, BinaryPredicate&& pred) {
00274   return std::find_first_of(container_algorithm_internal::c_begin(container),
00275                             container_algorithm_internal::c_end(container),
00276                             container_algorithm_internal::c_begin(options),
00277                             container_algorithm_internal::c_end(options),
00278                             std::forward<BinaryPredicate>(pred));
00279 }
00280 
00281 // c_adjacent_find()
00282 //
00283 // Container-based version of the <algorithm> `std::adjacent_find()` function to
00284 // find equal adjacent elements within a container.
00285 template <typename Sequence>
00286 container_algorithm_internal::ContainerIter<Sequence> c_adjacent_find(
00287     Sequence& sequence) {
00288   return std::adjacent_find(container_algorithm_internal::c_begin(sequence),
00289                             container_algorithm_internal::c_end(sequence));
00290 }
00291 
00292 // Overload of c_adjacent_find() for using a predicate evaluation other than
00293 // `==` as the function's test condition.
00294 template <typename Sequence, typename BinaryPredicate>
00295 container_algorithm_internal::ContainerIter<Sequence> c_adjacent_find(
00296     Sequence& sequence, BinaryPredicate&& pred) {
00297   return std::adjacent_find(container_algorithm_internal::c_begin(sequence),
00298                             container_algorithm_internal::c_end(sequence),
00299                             std::forward<BinaryPredicate>(pred));
00300 }
00301 
00302 // c_count()
00303 //
00304 // Container-based version of the <algorithm> `std::count()` function to count
00305 // values that match within a container.
00306 template <typename C, typename T>
00307 container_algorithm_internal::ContainerDifferenceType<const C> c_count(
00308     const C& c, T&& value) {
00309   return std::count(container_algorithm_internal::c_begin(c),
00310                     container_algorithm_internal::c_end(c),
00311                     std::forward<T>(value));
00312 }
00313 
00314 // c_count_if()
00315 //
00316 // Container-based version of the <algorithm> `std::count_if()` function to
00317 // count values matching a condition within a container.
00318 template <typename C, typename Pred>
00319 container_algorithm_internal::ContainerDifferenceType<const C> c_count_if(
00320     const C& c, Pred&& pred) {
00321   return std::count_if(container_algorithm_internal::c_begin(c),
00322                        container_algorithm_internal::c_end(c),
00323                        std::forward<Pred>(pred));
00324 }
00325 
00326 // c_mismatch()
00327 //
00328 // Container-based version of the <algorithm> `std::mismatch()` function to
00329 // return the first element where two ordered containers differ.
00330 template <typename C1, typename C2>
00331 container_algorithm_internal::ContainerIterPairType<C1, C2>
00332 c_mismatch(C1& c1, C2& c2) {
00333   return std::mismatch(container_algorithm_internal::c_begin(c1),
00334                        container_algorithm_internal::c_end(c1),
00335                        container_algorithm_internal::c_begin(c2));
00336 }
00337 
00338 // Overload of c_mismatch() for using a predicate evaluation other than `==` as
00339 // the function's test condition.
00340 template <typename C1, typename C2, typename BinaryPredicate>
00341 container_algorithm_internal::ContainerIterPairType<C1, C2>
00342 c_mismatch(C1& c1, C2& c2, BinaryPredicate&& pred) {
00343   return std::mismatch(container_algorithm_internal::c_begin(c1),
00344                        container_algorithm_internal::c_end(c1),
00345                        container_algorithm_internal::c_begin(c2),
00346                        std::forward<BinaryPredicate>(pred));
00347 }
00348 
00349 // c_equal()
00350 //
00351 // Container-based version of the <algorithm> `std::equal()` function to
00352 // test whether two containers are equal.
00353 //
00354 // NOTE: the semantics of c_equal() are slightly different than those of
00355 // equal(): while the latter iterates over the second container only up to the
00356 // size of the first container, c_equal() also checks whether the container
00357 // sizes are equal.  This better matches expectations about c_equal() based on
00358 // its signature.
00359 //
00360 // Example:
00361 //   vector v1 = <1, 2, 3>;
00362 //   vector v2 = <1, 2, 3, 4>;
00363 //   equal(std::begin(v1), std::end(v1), std::begin(v2)) returns true
00364 //   c_equal(v1, v2) returns false
00365 
00366 template <typename C1, typename C2>
00367 bool c_equal(const C1& c1, const C2& c2) {
00368   return ((c1.size() == c2.size()) &&
00369           std::equal(container_algorithm_internal::c_begin(c1),
00370                      container_algorithm_internal::c_end(c1),
00371                      container_algorithm_internal::c_begin(c2)));
00372 }
00373 
00374 // Overload of c_equal() for using a predicate evaluation other than `==` as
00375 // the function's test condition.
00376 template <typename C1, typename C2, typename BinaryPredicate>
00377 bool c_equal(const C1& c1, const C2& c2, BinaryPredicate&& pred) {
00378   return ((c1.size() == c2.size()) &&
00379           std::equal(container_algorithm_internal::c_begin(c1),
00380                      container_algorithm_internal::c_end(c1),
00381                      container_algorithm_internal::c_begin(c2),
00382                      std::forward<BinaryPredicate>(pred)));
00383 }
00384 
00385 // c_is_permutation()
00386 //
00387 // Container-based version of the <algorithm> `std::is_permutation()` function
00388 // to test whether a container is a permutation of another.
00389 template <typename C1, typename C2>
00390 bool c_is_permutation(const C1& c1, const C2& c2) {
00391   using std::begin;
00392   using std::end;
00393   return c1.size() == c2.size() &&
00394          std::is_permutation(begin(c1), end(c1), begin(c2));
00395 }
00396 
00397 // Overload of c_is_permutation() for using a predicate evaluation other than
00398 // `==` as the function's test condition.
00399 template <typename C1, typename C2, typename BinaryPredicate>
00400 bool c_is_permutation(const C1& c1, const C2& c2, BinaryPredicate&& pred) {
00401   using std::begin;
00402   using std::end;
00403   return c1.size() == c2.size() &&
00404          std::is_permutation(begin(c1), end(c1), begin(c2),
00405                              std::forward<BinaryPredicate>(pred));
00406 }
00407 
00408 // c_search()
00409 //
00410 // Container-based version of the <algorithm> `std::search()` function to search
00411 // a container for a subsequence.
00412 template <typename Sequence1, typename Sequence2>
00413 container_algorithm_internal::ContainerIter<Sequence1> c_search(
00414     Sequence1& sequence, Sequence2& subsequence) {
00415   return std::search(container_algorithm_internal::c_begin(sequence),
00416                      container_algorithm_internal::c_end(sequence),
00417                      container_algorithm_internal::c_begin(subsequence),
00418                      container_algorithm_internal::c_end(subsequence));
00419 }
00420 
00421 // Overload of c_search() for using a predicate evaluation other than
00422 // `==` as the function's test condition.
00423 template <typename Sequence1, typename Sequence2, typename BinaryPredicate>
00424 container_algorithm_internal::ContainerIter<Sequence1> c_search(
00425     Sequence1& sequence, Sequence2& subsequence, BinaryPredicate&& pred) {
00426   return std::search(container_algorithm_internal::c_begin(sequence),
00427                      container_algorithm_internal::c_end(sequence),
00428                      container_algorithm_internal::c_begin(subsequence),
00429                      container_algorithm_internal::c_end(subsequence),
00430                      std::forward<BinaryPredicate>(pred));
00431 }
00432 
00433 // c_search_n()
00434 //
00435 // Container-based version of the <algorithm> `std::search_n()` function to
00436 // search a container for the first sequence of N elements.
00437 template <typename Sequence, typename Size, typename T>
00438 container_algorithm_internal::ContainerIter<Sequence> c_search_n(
00439     Sequence& sequence, Size count, T&& value) {
00440   return std::search_n(container_algorithm_internal::c_begin(sequence),
00441                        container_algorithm_internal::c_end(sequence), count,
00442                        std::forward<T>(value));
00443 }
00444 
00445 // Overload of c_search_n() for using a predicate evaluation other than
00446 // `==` as the function's test condition.
00447 template <typename Sequence, typename Size, typename T,
00448           typename BinaryPredicate>
00449 container_algorithm_internal::ContainerIter<Sequence> c_search_n(
00450     Sequence& sequence, Size count, T&& value, BinaryPredicate&& pred) {
00451   return std::search_n(container_algorithm_internal::c_begin(sequence),
00452                        container_algorithm_internal::c_end(sequence), count,
00453                        std::forward<T>(value),
00454                        std::forward<BinaryPredicate>(pred));
00455 }
00456 
00457 //------------------------------------------------------------------------------
00458 // <algorithm> Modifying sequence operations
00459 //------------------------------------------------------------------------------
00460 
00461 // c_copy()
00462 //
00463 // Container-based version of the <algorithm> `std::copy()` function to copy a
00464 // container's elements into an iterator.
00465 template <typename InputSequence, typename OutputIterator>
00466 OutputIterator c_copy(const InputSequence& input, OutputIterator output) {
00467   return std::copy(container_algorithm_internal::c_begin(input),
00468                    container_algorithm_internal::c_end(input), output);
00469 }
00470 
00471 // c_copy_n()
00472 //
00473 // Container-based version of the <algorithm> `std::copy_n()` function to copy a
00474 // container's first N elements into an iterator.
00475 template <typename C, typename Size, typename OutputIterator>
00476 OutputIterator c_copy_n(const C& input, Size n, OutputIterator output) {
00477   return std::copy_n(container_algorithm_internal::c_begin(input), n, output);
00478 }
00479 
00480 // c_copy_if()
00481 //
00482 // Container-based version of the <algorithm> `std::copy_if()` function to copy
00483 // a container's elements satisfying some condition into an iterator.
00484 template <typename InputSequence, typename OutputIterator, typename Pred>
00485 OutputIterator c_copy_if(const InputSequence& input, OutputIterator output,
00486                          Pred&& pred) {
00487   return std::copy_if(container_algorithm_internal::c_begin(input),
00488                       container_algorithm_internal::c_end(input), output,
00489                       std::forward<Pred>(pred));
00490 }
00491 
00492 // c_copy_backward()
00493 //
00494 // Container-based version of the <algorithm> `std::copy_backward()` function to
00495 // copy a container's elements in reverse order into an iterator.
00496 template <typename C, typename BidirectionalIterator>
00497 BidirectionalIterator c_copy_backward(const C& src,
00498                                       BidirectionalIterator dest) {
00499   return std::copy_backward(container_algorithm_internal::c_begin(src),
00500                             container_algorithm_internal::c_end(src), dest);
00501 }
00502 
00503 // c_move()
00504 //
00505 // Container-based version of the <algorithm> `std::move()` function to move
00506 // a container's elements into an iterator.
00507 template <typename C, typename OutputIterator>
00508 OutputIterator c_move(C&& src, OutputIterator dest) {
00509   return std::move(container_algorithm_internal::c_begin(src),
00510                    container_algorithm_internal::c_end(src), dest);
00511 }
00512 
00513 // c_swap_ranges()
00514 //
00515 // Container-based version of the <algorithm> `std::swap_ranges()` function to
00516 // swap a container's elements with another container's elements.
00517 template <typename C1, typename C2>
00518 container_algorithm_internal::ContainerIter<C2> c_swap_ranges(C1& c1, C2& c2) {
00519   return std::swap_ranges(container_algorithm_internal::c_begin(c1),
00520                           container_algorithm_internal::c_end(c1),
00521                           container_algorithm_internal::c_begin(c2));
00522 }
00523 
00524 // c_transform()
00525 //
00526 // Container-based version of the <algorithm> `std::transform()` function to
00527 // transform a container's elements using the unary operation, storing the
00528 // result in an iterator pointing to the last transformed element in the output
00529 // range.
00530 template <typename InputSequence, typename OutputIterator, typename UnaryOp>
00531 OutputIterator c_transform(const InputSequence& input, OutputIterator output,
00532                            UnaryOp&& unary_op) {
00533   return std::transform(container_algorithm_internal::c_begin(input),
00534                         container_algorithm_internal::c_end(input), output,
00535                         std::forward<UnaryOp>(unary_op));
00536 }
00537 
00538 // Overload of c_transform() for performing a transformation using a binary
00539 // predicate.
00540 template <typename InputSequence1, typename InputSequence2,
00541           typename OutputIterator, typename BinaryOp>
00542 OutputIterator c_transform(const InputSequence1& input1,
00543                            const InputSequence2& input2, OutputIterator output,
00544                            BinaryOp&& binary_op) {
00545   return std::transform(container_algorithm_internal::c_begin(input1),
00546                         container_algorithm_internal::c_end(input1),
00547                         container_algorithm_internal::c_begin(input2), output,
00548                         std::forward<BinaryOp>(binary_op));
00549 }
00550 
00551 // c_replace()
00552 //
00553 // Container-based version of the <algorithm> `std::replace()` function to
00554 // replace a container's elements of some value with a new value. The container
00555 // is modified in place.
00556 template <typename Sequence, typename T>
00557 void c_replace(Sequence& sequence, const T& old_value, const T& new_value) {
00558   std::replace(container_algorithm_internal::c_begin(sequence),
00559                container_algorithm_internal::c_end(sequence), old_value,
00560                new_value);
00561 }
00562 
00563 // c_replace_if()
00564 //
00565 // Container-based version of the <algorithm> `std::replace_if()` function to
00566 // replace a container's elements of some value with a new value based on some
00567 // condition. The container is modified in place.
00568 template <typename C, typename Pred, typename T>
00569 void c_replace_if(C& c, Pred&& pred, T&& new_value) {
00570   std::replace_if(container_algorithm_internal::c_begin(c),
00571                   container_algorithm_internal::c_end(c),
00572                   std::forward<Pred>(pred), std::forward<T>(new_value));
00573 }
00574 
00575 // c_replace_copy()
00576 //
00577 // Container-based version of the <algorithm> `std::replace_copy()` function to
00578 // replace a container's elements of some value with a new value  and return the
00579 // results within an iterator.
00580 template <typename C, typename OutputIterator, typename T>
00581 OutputIterator c_replace_copy(const C& c, OutputIterator result, T&& old_value,
00582                               T&& new_value) {
00583   return std::replace_copy(container_algorithm_internal::c_begin(c),
00584                            container_algorithm_internal::c_end(c), result,
00585                            std::forward<T>(old_value),
00586                            std::forward<T>(new_value));
00587 }
00588 
00589 // c_replace_copy_if()
00590 //
00591 // Container-based version of the <algorithm> `std::replace_copy_if()` function
00592 // to replace a container's elements of some value with a new value based on
00593 // some condition, and return the results within an iterator.
00594 template <typename C, typename OutputIterator, typename Pred, typename T>
00595 OutputIterator c_replace_copy_if(const C& c, OutputIterator result, Pred&& pred,
00596                                  T&& new_value) {
00597   return std::replace_copy_if(container_algorithm_internal::c_begin(c),
00598                               container_algorithm_internal::c_end(c), result,
00599                               std::forward<Pred>(pred),
00600                               std::forward<T>(new_value));
00601 }
00602 
00603 // c_fill()
00604 //
00605 // Container-based version of the <algorithm> `std::fill()` function to fill a
00606 // container with some value.
00607 template <typename C, typename T>
00608 void c_fill(C& c, T&& value) {
00609   std::fill(container_algorithm_internal::c_begin(c),
00610             container_algorithm_internal::c_end(c), std::forward<T>(value));
00611 }
00612 
00613 // c_fill_n()
00614 //
00615 // Container-based version of the <algorithm> `std::fill_n()` function to fill
00616 // the first N elements in a container with some value.
00617 template <typename C, typename Size, typename T>
00618 void c_fill_n(C& c, Size n, T&& value) {
00619   std::fill_n(container_algorithm_internal::c_begin(c), n,
00620               std::forward<T>(value));
00621 }
00622 
00623 // c_generate()
00624 //
00625 // Container-based version of the <algorithm> `std::generate()` function to
00626 // assign a container's elements to the values provided by the given generator.
00627 template <typename C, typename Generator>
00628 void c_generate(C& c, Generator&& gen) {
00629   std::generate(container_algorithm_internal::c_begin(c),
00630                 container_algorithm_internal::c_end(c),
00631                 std::forward<Generator>(gen));
00632 }
00633 
00634 // c_generate_n()
00635 //
00636 // Container-based version of the <algorithm> `std::generate_n()` function to
00637 // assign a container's first N elements to the values provided by the given
00638 // generator.
00639 template <typename C, typename Size, typename Generator>
00640 container_algorithm_internal::ContainerIter<C> c_generate_n(C& c, Size n,
00641                                                             Generator&& gen) {
00642   return std::generate_n(container_algorithm_internal::c_begin(c), n,
00643                          std::forward<Generator>(gen));
00644 }
00645 
00646 // Note: `c_xx()` <algorithm> container versions for `remove()`, `remove_if()`,
00647 // and `unique()` are omitted, because it's not clear whether or not such
00648 // functions should call erase on their supplied sequences afterwards. Either
00649 // behavior would be surprising for a different set of users.
00650 
00651 // c_remove_copy()
00652 //
00653 // Container-based version of the <algorithm> `std::remove_copy()` function to
00654 // copy a container's elements while removing any elements matching the given
00655 // `value`.
00656 template <typename C, typename OutputIterator, typename T>
00657 OutputIterator c_remove_copy(const C& c, OutputIterator result, T&& value) {
00658   return std::remove_copy(container_algorithm_internal::c_begin(c),
00659                           container_algorithm_internal::c_end(c), result,
00660                           std::forward<T>(value));
00661 }
00662 
00663 // c_remove_copy_if()
00664 //
00665 // Container-based version of the <algorithm> `std::remove_copy_if()` function
00666 // to copy a container's elements while removing any elements matching the given
00667 // condition.
00668 template <typename C, typename OutputIterator, typename Pred>
00669 OutputIterator c_remove_copy_if(const C& c, OutputIterator result,
00670                                 Pred&& pred) {
00671   return std::remove_copy_if(container_algorithm_internal::c_begin(c),
00672                              container_algorithm_internal::c_end(c), result,
00673                              std::forward<Pred>(pred));
00674 }
00675 
00676 // c_unique_copy()
00677 //
00678 // Container-based version of the <algorithm> `std::unique_copy()` function to
00679 // copy a container's elements while removing any elements containing duplicate
00680 // values.
00681 template <typename C, typename OutputIterator>
00682 OutputIterator c_unique_copy(const C& c, OutputIterator result) {
00683   return std::unique_copy(container_algorithm_internal::c_begin(c),
00684                           container_algorithm_internal::c_end(c), result);
00685 }
00686 
00687 // Overload of c_unique_copy() for using a predicate evaluation other than
00688 // `==` for comparing uniqueness of the element values.
00689 template <typename C, typename OutputIterator, typename BinaryPredicate>
00690 OutputIterator c_unique_copy(const C& c, OutputIterator result,
00691                              BinaryPredicate&& pred) {
00692   return std::unique_copy(container_algorithm_internal::c_begin(c),
00693                           container_algorithm_internal::c_end(c), result,
00694                           std::forward<BinaryPredicate>(pred));
00695 }
00696 
00697 // c_reverse()
00698 //
00699 // Container-based version of the <algorithm> `std::reverse()` function to
00700 // reverse a container's elements.
00701 template <typename Sequence>
00702 void c_reverse(Sequence& sequence) {
00703   std::reverse(container_algorithm_internal::c_begin(sequence),
00704                container_algorithm_internal::c_end(sequence));
00705 }
00706 
00707 // c_reverse_copy()
00708 //
00709 // Container-based version of the <algorithm> `std::reverse()` function to
00710 // reverse a container's elements and write them to an iterator range.
00711 template <typename C, typename OutputIterator>
00712 OutputIterator c_reverse_copy(const C& sequence, OutputIterator result) {
00713   return std::reverse_copy(container_algorithm_internal::c_begin(sequence),
00714                            container_algorithm_internal::c_end(sequence),
00715                            result);
00716 }
00717 
00718 // c_rotate()
00719 //
00720 // Container-based version of the <algorithm> `std::rotate()` function to
00721 // shift a container's elements leftward such that the `middle` element becomes
00722 // the first element in the container.
00723 template <typename C,
00724           typename Iterator = container_algorithm_internal::ContainerIter<C>>
00725 Iterator c_rotate(C& sequence, Iterator middle) {
00726   return absl::rotate(container_algorithm_internal::c_begin(sequence), middle,
00727                       container_algorithm_internal::c_end(sequence));
00728 }
00729 
00730 // c_rotate_copy()
00731 //
00732 // Container-based version of the <algorithm> `std::rotate_copy()` function to
00733 // shift a container's elements leftward such that the `middle` element becomes
00734 // the first element in a new iterator range.
00735 template <typename C, typename OutputIterator>
00736 OutputIterator c_rotate_copy(
00737     const C& sequence,
00738     container_algorithm_internal::ContainerIter<const C> middle,
00739     OutputIterator result) {
00740   return std::rotate_copy(container_algorithm_internal::c_begin(sequence),
00741                           middle, container_algorithm_internal::c_end(sequence),
00742                           result);
00743 }
00744 
00745 // c_shuffle()
00746 //
00747 // Container-based version of the <algorithm> `std::shuffle()` function to
00748 // randomly shuffle elements within the container using a `gen()` uniform random
00749 // number generator.
00750 template <typename RandomAccessContainer, typename UniformRandomBitGenerator>
00751 void c_shuffle(RandomAccessContainer& c, UniformRandomBitGenerator&& gen) {
00752   std::shuffle(container_algorithm_internal::c_begin(c),
00753                container_algorithm_internal::c_end(c),
00754                std::forward<UniformRandomBitGenerator>(gen));
00755 }
00756 
00757 //------------------------------------------------------------------------------
00758 // <algorithm> Partition functions
00759 //------------------------------------------------------------------------------
00760 
00761 // c_is_partitioned()
00762 //
00763 // Container-based version of the <algorithm> `std::is_partitioned()` function
00764 // to test whether all elements in the container for which `pred` returns `true`
00765 // precede those for which `pred` is `false`.
00766 template <typename C, typename Pred>
00767 bool c_is_partitioned(const C& c, Pred&& pred) {
00768   return std::is_partitioned(container_algorithm_internal::c_begin(c),
00769                              container_algorithm_internal::c_end(c),
00770                              std::forward<Pred>(pred));
00771 }
00772 
00773 // c_partition()
00774 //
00775 // Container-based version of the <algorithm> `std::partition()` function
00776 // to rearrange all elements in a container in such a way that all elements for
00777 // which `pred` returns `true` precede all those for which it returns `false`,
00778 // returning an iterator to the first element of the second group.
00779 template <typename C, typename Pred>
00780 container_algorithm_internal::ContainerIter<C> c_partition(C& c, Pred&& pred) {
00781   return std::partition(container_algorithm_internal::c_begin(c),
00782                         container_algorithm_internal::c_end(c),
00783                         std::forward<Pred>(pred));
00784 }
00785 
00786 // c_stable_partition()
00787 //
00788 // Container-based version of the <algorithm> `std::stable_partition()` function
00789 // to rearrange all elements in a container in such a way that all elements for
00790 // which `pred` returns `true` precede all those for which it returns `false`,
00791 // preserving the relative ordering between the two groups. The function returns
00792 // an iterator to the first element of the second group.
00793 template <typename C, typename Pred>
00794 container_algorithm_internal::ContainerIter<C> c_stable_partition(C& c,
00795                                                                   Pred&& pred) {
00796   return std::stable_partition(container_algorithm_internal::c_begin(c),
00797                                container_algorithm_internal::c_end(c),
00798                                std::forward<Pred>(pred));
00799 }
00800 
00801 // c_partition_copy()
00802 //
00803 // Container-based version of the <algorithm> `std::partition_copy()` function
00804 // to partition a container's elements and return them into two iterators: one
00805 // for which `pred` returns `true`, and one for which `pred` returns `false.`
00806 
00807 template <typename C, typename OutputIterator1, typename OutputIterator2,
00808           typename Pred>
00809 std::pair<OutputIterator1, OutputIterator2> c_partition_copy(
00810     const C& c, OutputIterator1 out_true, OutputIterator2 out_false,
00811     Pred&& pred) {
00812   return std::partition_copy(container_algorithm_internal::c_begin(c),
00813                              container_algorithm_internal::c_end(c), out_true,
00814                              out_false, std::forward<Pred>(pred));
00815 }
00816 
00817 // c_partition_point()
00818 //
00819 // Container-based version of the <algorithm> `std::partition_point()` function
00820 // to return the first element of an already partitioned container for which
00821 // the given `pred` is not `true`.
00822 template <typename C, typename Pred>
00823 container_algorithm_internal::ContainerIter<C> c_partition_point(C& c,
00824                                                                  Pred&& pred) {
00825   return std::partition_point(container_algorithm_internal::c_begin(c),
00826                               container_algorithm_internal::c_end(c),
00827                               std::forward<Pred>(pred));
00828 }
00829 
00830 //------------------------------------------------------------------------------
00831 // <algorithm> Sorting functions
00832 //------------------------------------------------------------------------------
00833 
00834 // c_sort()
00835 //
00836 // Container-based version of the <algorithm> `std::sort()` function
00837 // to sort elements in ascending order of their values.
00838 template <typename C>
00839 void c_sort(C& c) {
00840   std::sort(container_algorithm_internal::c_begin(c),
00841             container_algorithm_internal::c_end(c));
00842 }
00843 
00844 // Overload of c_sort() for performing a `comp` comparison other than the
00845 // default `operator<`.
00846 template <typename C, typename Compare>
00847 void c_sort(C& c, Compare&& comp) {
00848   std::sort(container_algorithm_internal::c_begin(c),
00849             container_algorithm_internal::c_end(c),
00850             std::forward<Compare>(comp));
00851 }
00852 
00853 // c_stable_sort()
00854 //
00855 // Container-based version of the <algorithm> `std::stable_sort()` function
00856 // to sort elements in ascending order of their values, preserving the order
00857 // of equivalents.
00858 template <typename C>
00859 void c_stable_sort(C& c) {
00860   std::stable_sort(container_algorithm_internal::c_begin(c),
00861                    container_algorithm_internal::c_end(c));
00862 }
00863 
00864 // Overload of c_stable_sort() for performing a `comp` comparison other than the
00865 // default `operator<`.
00866 template <typename C, typename Compare>
00867 void c_stable_sort(C& c, Compare&& comp) {
00868   std::stable_sort(container_algorithm_internal::c_begin(c),
00869                    container_algorithm_internal::c_end(c),
00870                    std::forward<Compare>(comp));
00871 }
00872 
00873 // c_is_sorted()
00874 //
00875 // Container-based version of the <algorithm> `std::is_sorted()` function
00876 // to evaluate whether the given container is sorted in ascending order.
00877 template <typename C>
00878 bool c_is_sorted(const C& c) {
00879   return std::is_sorted(container_algorithm_internal::c_begin(c),
00880                         container_algorithm_internal::c_end(c));
00881 }
00882 
00883 // c_is_sorted() overload for performing a `comp` comparison other than the
00884 // default `operator<`.
00885 template <typename C, typename Compare>
00886 bool c_is_sorted(const C& c, Compare&& comp) {
00887   return std::is_sorted(container_algorithm_internal::c_begin(c),
00888                         container_algorithm_internal::c_end(c),
00889                         std::forward<Compare>(comp));
00890 }
00891 
00892 // c_partial_sort()
00893 //
00894 // Container-based version of the <algorithm> `std::partial_sort()` function
00895 // to rearrange elements within a container such that elements before `middle`
00896 // are sorted in ascending order.
00897 template <typename RandomAccessContainer>
00898 void c_partial_sort(
00899     RandomAccessContainer& sequence,
00900     container_algorithm_internal::ContainerIter<RandomAccessContainer> middle) {
00901   std::partial_sort(container_algorithm_internal::c_begin(sequence), middle,
00902                     container_algorithm_internal::c_end(sequence));
00903 }
00904 
00905 // Overload of c_partial_sort() for performing a `comp` comparison other than
00906 // the default `operator<`.
00907 template <typename RandomAccessContainer, typename Compare>
00908 void c_partial_sort(
00909     RandomAccessContainer& sequence,
00910     container_algorithm_internal::ContainerIter<RandomAccessContainer> middle,
00911     Compare&& comp) {
00912   std::partial_sort(container_algorithm_internal::c_begin(sequence), middle,
00913                     container_algorithm_internal::c_end(sequence),
00914                     std::forward<Compare>(comp));
00915 }
00916 
00917 // c_partial_sort_copy()
00918 //
00919 // Container-based version of the <algorithm> `std::partial_sort_copy()`
00920 // function to sort elements within a container such that elements before
00921 // `middle` are sorted in ascending order, and return the result within an
00922 // iterator.
00923 template <typename C, typename RandomAccessContainer>
00924 container_algorithm_internal::ContainerIter<RandomAccessContainer>
00925 c_partial_sort_copy(const C& sequence, RandomAccessContainer& result) {
00926   return std::partial_sort_copy(container_algorithm_internal::c_begin(sequence),
00927                                 container_algorithm_internal::c_end(sequence),
00928                                 container_algorithm_internal::c_begin(result),
00929                                 container_algorithm_internal::c_end(result));
00930 }
00931 
00932 // Overload of c_partial_sort_copy() for performing a `comp` comparison other
00933 // than the default `operator<`.
00934 template <typename C, typename RandomAccessContainer, typename Compare>
00935 container_algorithm_internal::ContainerIter<RandomAccessContainer>
00936 c_partial_sort_copy(const C& sequence, RandomAccessContainer& result,
00937                     Compare&& comp) {
00938   return std::partial_sort_copy(container_algorithm_internal::c_begin(sequence),
00939                                 container_algorithm_internal::c_end(sequence),
00940                                 container_algorithm_internal::c_begin(result),
00941                                 container_algorithm_internal::c_end(result),
00942                                 std::forward<Compare>(comp));
00943 }
00944 
00945 // c_is_sorted_until()
00946 //
00947 // Container-based version of the <algorithm> `std::is_sorted_until()` function
00948 // to return the first element within a container that is not sorted in
00949 // ascending order as an iterator.
00950 template <typename C>
00951 container_algorithm_internal::ContainerIter<C> c_is_sorted_until(C& c) {
00952   return std::is_sorted_until(container_algorithm_internal::c_begin(c),
00953                               container_algorithm_internal::c_end(c));
00954 }
00955 
00956 // Overload of c_is_sorted_until() for performing a `comp` comparison other than
00957 // the default `operator<`.
00958 template <typename C, typename Compare>
00959 container_algorithm_internal::ContainerIter<C> c_is_sorted_until(
00960     C& c, Compare&& comp) {
00961   return std::is_sorted_until(container_algorithm_internal::c_begin(c),
00962                               container_algorithm_internal::c_end(c),
00963                               std::forward<Compare>(comp));
00964 }
00965 
00966 // c_nth_element()
00967 //
00968 // Container-based version of the <algorithm> `std::nth_element()` function
00969 // to rearrange the elements within a container such that the `nth` element
00970 // would be in that position in an ordered sequence; other elements may be in
00971 // any order, except that all preceding `nth` will be less than that element,
00972 // and all following `nth` will be greater than that element.
00973 template <typename RandomAccessContainer>
00974 void c_nth_element(
00975     RandomAccessContainer& sequence,
00976     container_algorithm_internal::ContainerIter<RandomAccessContainer> nth) {
00977   std::nth_element(container_algorithm_internal::c_begin(sequence), nth,
00978                    container_algorithm_internal::c_end(sequence));
00979 }
00980 
00981 // Overload of c_nth_element() for performing a `comp` comparison other than
00982 // the default `operator<`.
00983 template <typename RandomAccessContainer, typename Compare>
00984 void c_nth_element(
00985     RandomAccessContainer& sequence,
00986     container_algorithm_internal::ContainerIter<RandomAccessContainer> nth,
00987     Compare&& comp) {
00988   std::nth_element(container_algorithm_internal::c_begin(sequence), nth,
00989                    container_algorithm_internal::c_end(sequence),
00990                    std::forward<Compare>(comp));
00991 }
00992 
00993 //------------------------------------------------------------------------------
00994 // <algorithm> Binary Search
00995 //------------------------------------------------------------------------------
00996 
00997 // c_lower_bound()
00998 //
00999 // Container-based version of the <algorithm> `std::lower_bound()` function
01000 // to return an iterator pointing to the first element in a sorted container
01001 // which does not compare less than `value`.
01002 template <typename Sequence, typename T>
01003 container_algorithm_internal::ContainerIter<Sequence> c_lower_bound(
01004     Sequence& sequence, T&& value) {
01005   return std::lower_bound(container_algorithm_internal::c_begin(sequence),
01006                           container_algorithm_internal::c_end(sequence),
01007                           std::forward<T>(value));
01008 }
01009 
01010 // Overload of c_lower_bound() for performing a `comp` comparison other than
01011 // the default `operator<`.
01012 template <typename Sequence, typename T, typename Compare>
01013 container_algorithm_internal::ContainerIter<Sequence> c_lower_bound(
01014     Sequence& sequence, T&& value, Compare&& comp) {
01015   return std::lower_bound(container_algorithm_internal::c_begin(sequence),
01016                           container_algorithm_internal::c_end(sequence),
01017                           std::forward<T>(value), std::forward<Compare>(comp));
01018 }
01019 
01020 // c_upper_bound()
01021 //
01022 // Container-based version of the <algorithm> `std::upper_bound()` function
01023 // to return an iterator pointing to the first element in a sorted container
01024 // which is greater than `value`.
01025 template <typename Sequence, typename T>
01026 container_algorithm_internal::ContainerIter<Sequence> c_upper_bound(
01027     Sequence& sequence, T&& value) {
01028   return std::upper_bound(container_algorithm_internal::c_begin(sequence),
01029                           container_algorithm_internal::c_end(sequence),
01030                           std::forward<T>(value));
01031 }
01032 
01033 // Overload of c_upper_bound() for performing a `comp` comparison other than
01034 // the default `operator<`.
01035 template <typename Sequence, typename T, typename Compare>
01036 container_algorithm_internal::ContainerIter<Sequence> c_upper_bound(
01037     Sequence& sequence, T&& value, Compare&& comp) {
01038   return std::upper_bound(container_algorithm_internal::c_begin(sequence),
01039                           container_algorithm_internal::c_end(sequence),
01040                           std::forward<T>(value), std::forward<Compare>(comp));
01041 }
01042 
01043 // c_equal_range()
01044 //
01045 // Container-based version of the <algorithm> `std::equal_range()` function
01046 // to return an iterator pair pointing to the first and last elements in a
01047 // sorted container which compare equal to `value`.
01048 template <typename Sequence, typename T>
01049 container_algorithm_internal::ContainerIterPairType<Sequence, Sequence>
01050 c_equal_range(Sequence& sequence, T&& value) {
01051   return std::equal_range(container_algorithm_internal::c_begin(sequence),
01052                           container_algorithm_internal::c_end(sequence),
01053                           std::forward<T>(value));
01054 }
01055 
01056 // Overload of c_equal_range() for performing a `comp` comparison other than
01057 // the default `operator<`.
01058 template <typename Sequence, typename T, typename Compare>
01059 container_algorithm_internal::ContainerIterPairType<Sequence, Sequence>
01060 c_equal_range(Sequence& sequence, T&& value, Compare&& comp) {
01061   return std::equal_range(container_algorithm_internal::c_begin(sequence),
01062                           container_algorithm_internal::c_end(sequence),
01063                           std::forward<T>(value), std::forward<Compare>(comp));
01064 }
01065 
01066 // c_binary_search()
01067 //
01068 // Container-based version of the <algorithm> `std::binary_search()` function
01069 // to test if any element in the sorted container contains a value equivalent to
01070 // 'value'.
01071 template <typename Sequence, typename T>
01072 bool c_binary_search(Sequence&& sequence, T&& value) {
01073   return std::binary_search(container_algorithm_internal::c_begin(sequence),
01074                             container_algorithm_internal::c_end(sequence),
01075                             std::forward<T>(value));
01076 }
01077 
01078 // Overload of c_binary_search() for performing a `comp` comparison other than
01079 // the default `operator<`.
01080 template <typename Sequence, typename T, typename Compare>
01081 bool c_binary_search(Sequence&& sequence, T&& value, Compare&& comp) {
01082   return std::binary_search(container_algorithm_internal::c_begin(sequence),
01083                             container_algorithm_internal::c_end(sequence),
01084                             std::forward<T>(value),
01085                             std::forward<Compare>(comp));
01086 }
01087 
01088 //------------------------------------------------------------------------------
01089 // <algorithm> Merge functions
01090 //------------------------------------------------------------------------------
01091 
01092 // c_merge()
01093 //
01094 // Container-based version of the <algorithm> `std::merge()` function
01095 // to merge two sorted containers into a single sorted iterator.
01096 template <typename C1, typename C2, typename OutputIterator>
01097 OutputIterator c_merge(const C1& c1, const C2& c2, OutputIterator result) {
01098   return std::merge(container_algorithm_internal::c_begin(c1),
01099                     container_algorithm_internal::c_end(c1),
01100                     container_algorithm_internal::c_begin(c2),
01101                     container_algorithm_internal::c_end(c2), result);
01102 }
01103 
01104 // Overload of c_merge() for performing a `comp` comparison other than
01105 // the default `operator<`.
01106 template <typename C1, typename C2, typename OutputIterator, typename Compare>
01107 OutputIterator c_merge(const C1& c1, const C2& c2, OutputIterator result,
01108                        Compare&& comp) {
01109   return std::merge(container_algorithm_internal::c_begin(c1),
01110                     container_algorithm_internal::c_end(c1),
01111                     container_algorithm_internal::c_begin(c2),
01112                     container_algorithm_internal::c_end(c2), result,
01113                     std::forward<Compare>(comp));
01114 }
01115 
01116 // c_inplace_merge()
01117 //
01118 // Container-based version of the <algorithm> `std::inplace_merge()` function
01119 // to merge a supplied iterator `middle` into a container.
01120 template <typename C>
01121 void c_inplace_merge(C& c,
01122                      container_algorithm_internal::ContainerIter<C> middle) {
01123   std::inplace_merge(container_algorithm_internal::c_begin(c), middle,
01124                      container_algorithm_internal::c_end(c));
01125 }
01126 
01127 // Overload of c_inplace_merge() for performing a merge using a `comp` other
01128 // than `operator<`.
01129 template <typename C, typename Compare>
01130 void c_inplace_merge(C& c,
01131                      container_algorithm_internal::ContainerIter<C> middle,
01132                      Compare&& comp) {
01133   std::inplace_merge(container_algorithm_internal::c_begin(c), middle,
01134                      container_algorithm_internal::c_end(c),
01135                      std::forward<Compare>(comp));
01136 }
01137 
01138 // c_includes()
01139 //
01140 // Container-based version of the <algorithm> `std::includes()` function
01141 // to test whether a sorted container `c1` entirely contains another sorted
01142 // container `c2`.
01143 template <typename C1, typename C2>
01144 bool c_includes(const C1& c1, const C2& c2) {
01145   return std::includes(container_algorithm_internal::c_begin(c1),
01146                        container_algorithm_internal::c_end(c1),
01147                        container_algorithm_internal::c_begin(c2),
01148                        container_algorithm_internal::c_end(c2));
01149 }
01150 
01151 // Overload of c_includes() for performing a merge using a `comp` other than
01152 // `operator<`.
01153 template <typename C1, typename C2, typename Compare>
01154 bool c_includes(const C1& c1, const C2& c2, Compare&& comp) {
01155   return std::includes(container_algorithm_internal::c_begin(c1),
01156                        container_algorithm_internal::c_end(c1),
01157                        container_algorithm_internal::c_begin(c2),
01158                        container_algorithm_internal::c_end(c2),
01159                        std::forward<Compare>(comp));
01160 }
01161 
01162 // c_set_union()
01163 //
01164 // Container-based version of the <algorithm> `std::set_union()` function
01165 // to return an iterator containing the union of two containers; duplicate
01166 // values are not copied into the output.
01167 template <typename C1, typename C2, typename OutputIterator,
01168           typename = typename std::enable_if<
01169               !container_algorithm_internal::IsUnorderedContainer<C1>::value,
01170               void>::type,
01171           typename = typename std::enable_if<
01172               !container_algorithm_internal::IsUnorderedContainer<C2>::value,
01173               void>::type>
01174 OutputIterator c_set_union(const C1& c1, const C2& c2, OutputIterator output) {
01175   return std::set_union(container_algorithm_internal::c_begin(c1),
01176                         container_algorithm_internal::c_end(c1),
01177                         container_algorithm_internal::c_begin(c2),
01178                         container_algorithm_internal::c_end(c2), output);
01179 }
01180 
01181 // Overload of c_set_union() for performing a merge using a `comp` other than
01182 // `operator<`.
01183 template <typename C1, typename C2, typename OutputIterator, typename Compare,
01184           typename = typename std::enable_if<
01185               !container_algorithm_internal::IsUnorderedContainer<C1>::value,
01186               void>::type,
01187           typename = typename std::enable_if<
01188               !container_algorithm_internal::IsUnorderedContainer<C2>::value,
01189               void>::type>
01190 OutputIterator c_set_union(const C1& c1, const C2& c2, OutputIterator output,
01191                            Compare&& comp) {
01192   return std::set_union(container_algorithm_internal::c_begin(c1),
01193                         container_algorithm_internal::c_end(c1),
01194                         container_algorithm_internal::c_begin(c2),
01195                         container_algorithm_internal::c_end(c2), output,
01196                         std::forward<Compare>(comp));
01197 }
01198 
01199 // c_set_intersection()
01200 //
01201 // Container-based version of the <algorithm> `std::set_intersection()` function
01202 // to return an iterator containing the intersection of two containers.
01203 template <typename C1, typename C2, typename OutputIterator,
01204           typename = typename std::enable_if<
01205               !container_algorithm_internal::IsUnorderedContainer<C1>::value,
01206               void>::type,
01207           typename = typename std::enable_if<
01208               !container_algorithm_internal::IsUnorderedContainer<C2>::value,
01209               void>::type>
01210 OutputIterator c_set_intersection(const C1& c1, const C2& c2,
01211                                   OutputIterator output) {
01212   return std::set_intersection(container_algorithm_internal::c_begin(c1),
01213                                container_algorithm_internal::c_end(c1),
01214                                container_algorithm_internal::c_begin(c2),
01215                                container_algorithm_internal::c_end(c2), output);
01216 }
01217 
01218 // Overload of c_set_intersection() for performing a merge using a `comp` other
01219 // than `operator<`.
01220 template <typename C1, typename C2, typename OutputIterator, typename Compare,
01221           typename = typename std::enable_if<
01222               !container_algorithm_internal::IsUnorderedContainer<C1>::value,
01223               void>::type,
01224           typename = typename std::enable_if<
01225               !container_algorithm_internal::IsUnorderedContainer<C2>::value,
01226               void>::type>
01227 OutputIterator c_set_intersection(const C1& c1, const C2& c2,
01228                                   OutputIterator output, Compare&& comp) {
01229   return std::set_intersection(container_algorithm_internal::c_begin(c1),
01230                                container_algorithm_internal::c_end(c1),
01231                                container_algorithm_internal::c_begin(c2),
01232                                container_algorithm_internal::c_end(c2), output,
01233                                std::forward<Compare>(comp));
01234 }
01235 
01236 // c_set_difference()
01237 //
01238 // Container-based version of the <algorithm> `std::set_difference()` function
01239 // to return an iterator containing elements present in the first container but
01240 // not in the second.
01241 template <typename C1, typename C2, typename OutputIterator,
01242           typename = typename std::enable_if<
01243               !container_algorithm_internal::IsUnorderedContainer<C1>::value,
01244               void>::type,
01245           typename = typename std::enable_if<
01246               !container_algorithm_internal::IsUnorderedContainer<C2>::value,
01247               void>::type>
01248 OutputIterator c_set_difference(const C1& c1, const C2& c2,
01249                                 OutputIterator output) {
01250   return std::set_difference(container_algorithm_internal::c_begin(c1),
01251                              container_algorithm_internal::c_end(c1),
01252                              container_algorithm_internal::c_begin(c2),
01253                              container_algorithm_internal::c_end(c2), output);
01254 }
01255 
01256 // Overload of c_set_difference() for performing a merge using a `comp` other
01257 // than `operator<`.
01258 template <typename C1, typename C2, typename OutputIterator, typename Compare,
01259           typename = typename std::enable_if<
01260               !container_algorithm_internal::IsUnorderedContainer<C1>::value,
01261               void>::type,
01262           typename = typename std::enable_if<
01263               !container_algorithm_internal::IsUnorderedContainer<C2>::value,
01264               void>::type>
01265 OutputIterator c_set_difference(const C1& c1, const C2& c2,
01266                                 OutputIterator output, Compare&& comp) {
01267   return std::set_difference(container_algorithm_internal::c_begin(c1),
01268                              container_algorithm_internal::c_end(c1),
01269                              container_algorithm_internal::c_begin(c2),
01270                              container_algorithm_internal::c_end(c2), output,
01271                              std::forward<Compare>(comp));
01272 }
01273 
01274 // c_set_symmetric_difference()
01275 //
01276 // Container-based version of the <algorithm> `std::set_symmetric_difference()`
01277 // function to return an iterator containing elements present in either one
01278 // container or the other, but not both.
01279 template <typename C1, typename C2, typename OutputIterator,
01280           typename = typename std::enable_if<
01281               !container_algorithm_internal::IsUnorderedContainer<C1>::value,
01282               void>::type,
01283           typename = typename std::enable_if<
01284               !container_algorithm_internal::IsUnorderedContainer<C2>::value,
01285               void>::type>
01286 OutputIterator c_set_symmetric_difference(const C1& c1, const C2& c2,
01287                                           OutputIterator output) {
01288   return std::set_symmetric_difference(
01289       container_algorithm_internal::c_begin(c1),
01290       container_algorithm_internal::c_end(c1),
01291       container_algorithm_internal::c_begin(c2),
01292       container_algorithm_internal::c_end(c2), output);
01293 }
01294 
01295 // Overload of c_set_symmetric_difference() for performing a merge using a
01296 // `comp` other than `operator<`.
01297 template <typename C1, typename C2, typename OutputIterator, typename Compare,
01298           typename = typename std::enable_if<
01299               !container_algorithm_internal::IsUnorderedContainer<C1>::value,
01300               void>::type,
01301           typename = typename std::enable_if<
01302               !container_algorithm_internal::IsUnorderedContainer<C2>::value,
01303               void>::type>
01304 OutputIterator c_set_symmetric_difference(const C1& c1, const C2& c2,
01305                                           OutputIterator output,
01306                                           Compare&& comp) {
01307   return std::set_symmetric_difference(
01308       container_algorithm_internal::c_begin(c1),
01309       container_algorithm_internal::c_end(c1),
01310       container_algorithm_internal::c_begin(c2),
01311       container_algorithm_internal::c_end(c2), output,
01312       std::forward<Compare>(comp));
01313 }
01314 
01315 //------------------------------------------------------------------------------
01316 // <algorithm> Heap functions
01317 //------------------------------------------------------------------------------
01318 
01319 // c_push_heap()
01320 //
01321 // Container-based version of the <algorithm> `std::push_heap()` function
01322 // to push a value onto a container heap.
01323 template <typename RandomAccessContainer>
01324 void c_push_heap(RandomAccessContainer& sequence) {
01325   std::push_heap(container_algorithm_internal::c_begin(sequence),
01326                  container_algorithm_internal::c_end(sequence));
01327 }
01328 
01329 // Overload of c_push_heap() for performing a push operation on a heap using a
01330 // `comp` other than `operator<`.
01331 template <typename RandomAccessContainer, typename Compare>
01332 void c_push_heap(RandomAccessContainer& sequence, Compare&& comp) {
01333   std::push_heap(container_algorithm_internal::c_begin(sequence),
01334                  container_algorithm_internal::c_end(sequence),
01335                  std::forward<Compare>(comp));
01336 }
01337 
01338 // c_pop_heap()
01339 //
01340 // Container-based version of the <algorithm> `std::pop_heap()` function
01341 // to pop a value from a heap container.
01342 template <typename RandomAccessContainer>
01343 void c_pop_heap(RandomAccessContainer& sequence) {
01344   std::pop_heap(container_algorithm_internal::c_begin(sequence),
01345                 container_algorithm_internal::c_end(sequence));
01346 }
01347 
01348 // Overload of c_pop_heap() for performing a pop operation on a heap using a
01349 // `comp` other than `operator<`.
01350 template <typename RandomAccessContainer, typename Compare>
01351 void c_pop_heap(RandomAccessContainer& sequence, Compare&& comp) {
01352   std::pop_heap(container_algorithm_internal::c_begin(sequence),
01353                 container_algorithm_internal::c_end(sequence),
01354                 std::forward<Compare>(comp));
01355 }
01356 
01357 // c_make_heap()
01358 //
01359 // Container-based version of the <algorithm> `std::make_heap()` function
01360 // to make a container a heap.
01361 template <typename RandomAccessContainer>
01362 void c_make_heap(RandomAccessContainer& sequence) {
01363   std::make_heap(container_algorithm_internal::c_begin(sequence),
01364                  container_algorithm_internal::c_end(sequence));
01365 }
01366 
01367 // Overload of c_make_heap() for performing heap comparisons using a
01368 // `comp` other than `operator<`
01369 template <typename RandomAccessContainer, typename Compare>
01370 void c_make_heap(RandomAccessContainer& sequence, Compare&& comp) {
01371   std::make_heap(container_algorithm_internal::c_begin(sequence),
01372                  container_algorithm_internal::c_end(sequence),
01373                  std::forward<Compare>(comp));
01374 }
01375 
01376 // c_sort_heap()
01377 //
01378 // Container-based version of the <algorithm> `std::sort_heap()` function
01379 // to sort a heap into ascending order (after which it is no longer a heap).
01380 template <typename RandomAccessContainer>
01381 void c_sort_heap(RandomAccessContainer& sequence) {
01382   std::sort_heap(container_algorithm_internal::c_begin(sequence),
01383                  container_algorithm_internal::c_end(sequence));
01384 }
01385 
01386 // Overload of c_sort_heap() for performing heap comparisons using a
01387 // `comp` other than `operator<`
01388 template <typename RandomAccessContainer, typename Compare>
01389 void c_sort_heap(RandomAccessContainer& sequence, Compare&& comp) {
01390   std::sort_heap(container_algorithm_internal::c_begin(sequence),
01391                  container_algorithm_internal::c_end(sequence),
01392                  std::forward<Compare>(comp));
01393 }
01394 
01395 // c_is_heap()
01396 //
01397 // Container-based version of the <algorithm> `std::is_heap()` function
01398 // to check whether the given container is a heap.
01399 template <typename RandomAccessContainer>
01400 bool c_is_heap(const RandomAccessContainer& sequence) {
01401   return std::is_heap(container_algorithm_internal::c_begin(sequence),
01402                       container_algorithm_internal::c_end(sequence));
01403 }
01404 
01405 // Overload of c_is_heap() for performing heap comparisons using a
01406 // `comp` other than `operator<`
01407 template <typename RandomAccessContainer, typename Compare>
01408 bool c_is_heap(const RandomAccessContainer& sequence, Compare&& comp) {
01409   return std::is_heap(container_algorithm_internal::c_begin(sequence),
01410                       container_algorithm_internal::c_end(sequence),
01411                       std::forward<Compare>(comp));
01412 }
01413 
01414 // c_is_heap_until()
01415 //
01416 // Container-based version of the <algorithm> `std::is_heap_until()` function
01417 // to find the first element in a given container which is not in heap order.
01418 template <typename RandomAccessContainer>
01419 container_algorithm_internal::ContainerIter<RandomAccessContainer>
01420 c_is_heap_until(RandomAccessContainer& sequence) {
01421   return std::is_heap_until(container_algorithm_internal::c_begin(sequence),
01422                             container_algorithm_internal::c_end(sequence));
01423 }
01424 
01425 // Overload of c_is_heap_until() for performing heap comparisons using a
01426 // `comp` other than `operator<`
01427 template <typename RandomAccessContainer, typename Compare>
01428 container_algorithm_internal::ContainerIter<RandomAccessContainer>
01429 c_is_heap_until(RandomAccessContainer& sequence, Compare&& comp) {
01430   return std::is_heap_until(container_algorithm_internal::c_begin(sequence),
01431                             container_algorithm_internal::c_end(sequence),
01432                             std::forward<Compare>(comp));
01433 }
01434 
01435 //------------------------------------------------------------------------------
01436 //  <algorithm> Min/max
01437 //------------------------------------------------------------------------------
01438 
01439 // c_min_element()
01440 //
01441 // Container-based version of the <algorithm> `std::min_element()` function
01442 // to return an iterator pointing to the element with the smallest value, using
01443 // `operator<` to make the comparisons.
01444 template <typename Sequence>
01445 container_algorithm_internal::ContainerIter<Sequence> c_min_element(
01446     Sequence& sequence) {
01447   return std::min_element(container_algorithm_internal::c_begin(sequence),
01448                           container_algorithm_internal::c_end(sequence));
01449 }
01450 
01451 // Overload of c_min_element() for performing a `comp` comparison other than
01452 // `operator<`.
01453 template <typename Sequence, typename Compare>
01454 container_algorithm_internal::ContainerIter<Sequence> c_min_element(
01455     Sequence& sequence, Compare&& comp) {
01456   return std::min_element(container_algorithm_internal::c_begin(sequence),
01457                           container_algorithm_internal::c_end(sequence),
01458                           std::forward<Compare>(comp));
01459 }
01460 
01461 // c_max_element()
01462 //
01463 // Container-based version of the <algorithm> `std::max_element()` function
01464 // to return an iterator pointing to the element with the largest value, using
01465 // `operator<` to make the comparisons.
01466 template <typename Sequence>
01467 container_algorithm_internal::ContainerIter<Sequence> c_max_element(
01468     Sequence& sequence) {
01469   return std::max_element(container_algorithm_internal::c_begin(sequence),
01470                           container_algorithm_internal::c_end(sequence));
01471 }
01472 
01473 // Overload of c_max_element() for performing a `comp` comparison other than
01474 // `operator<`.
01475 template <typename Sequence, typename Compare>
01476 container_algorithm_internal::ContainerIter<Sequence> c_max_element(
01477     Sequence& sequence, Compare&& comp) {
01478   return std::max_element(container_algorithm_internal::c_begin(sequence),
01479                           container_algorithm_internal::c_end(sequence),
01480                           std::forward<Compare>(comp));
01481 }
01482 
01483 // c_minmax_element()
01484 //
01485 // Container-based version of the <algorithm> `std::minmax_element()` function
01486 // to return a pair of iterators pointing to the elements containing the
01487 // smallest and largest values, respectively, using `operator<` to make the
01488 // comparisons.
01489 template <typename C>
01490 container_algorithm_internal::ContainerIterPairType<C, C>
01491 c_minmax_element(C& c) {
01492   return std::minmax_element(container_algorithm_internal::c_begin(c),
01493                              container_algorithm_internal::c_end(c));
01494 }
01495 
01496 // Overload of c_minmax_element() for performing `comp` comparisons other than
01497 // `operator<`.
01498 template <typename C, typename Compare>
01499 container_algorithm_internal::ContainerIterPairType<C, C>
01500 c_minmax_element(C& c, Compare&& comp) {
01501   return std::minmax_element(container_algorithm_internal::c_begin(c),
01502                              container_algorithm_internal::c_end(c),
01503                              std::forward<Compare>(comp));
01504 }
01505 
01506 //------------------------------------------------------------------------------
01507 //  <algorithm> Lexicographical Comparisons
01508 //------------------------------------------------------------------------------
01509 
01510 // c_lexicographical_compare()
01511 //
01512 // Container-based version of the <algorithm> `std::lexicographical_compare()`
01513 // function to lexicographically compare (e.g. sort words alphabetically) two
01514 // container sequences. The comparison is performed using `operator<`. Note
01515 // that capital letters ("A-Z") have ASCII values less than lowercase letters
01516 // ("a-z").
01517 template <typename Sequence1, typename Sequence2>
01518 bool c_lexicographical_compare(Sequence1&& sequence1, Sequence2&& sequence2) {
01519   return std::lexicographical_compare(
01520       container_algorithm_internal::c_begin(sequence1),
01521       container_algorithm_internal::c_end(sequence1),
01522       container_algorithm_internal::c_begin(sequence2),
01523       container_algorithm_internal::c_end(sequence2));
01524 }
01525 
01526 // Overload of c_lexicographical_compare() for performing a lexicographical
01527 // comparison using a `comp` operator instead of `operator<`.
01528 template <typename Sequence1, typename Sequence2, typename Compare>
01529 bool c_lexicographical_compare(Sequence1&& sequence1, Sequence2&& sequence2,
01530                                Compare&& comp) {
01531   return std::lexicographical_compare(
01532       container_algorithm_internal::c_begin(sequence1),
01533       container_algorithm_internal::c_end(sequence1),
01534       container_algorithm_internal::c_begin(sequence2),
01535       container_algorithm_internal::c_end(sequence2),
01536       std::forward<Compare>(comp));
01537 }
01538 
01539 // c_next_permutation()
01540 //
01541 // Container-based version of the <algorithm> `std::next_permutation()` function
01542 // to rearrange a container's elements into the next lexicographically greater
01543 // permutation.
01544 template <typename C>
01545 bool c_next_permutation(C& c) {
01546   return std::next_permutation(container_algorithm_internal::c_begin(c),
01547                                container_algorithm_internal::c_end(c));
01548 }
01549 
01550 // Overload of c_next_permutation() for performing a lexicographical
01551 // comparison using a `comp` operator instead of `operator<`.
01552 template <typename C, typename Compare>
01553 bool c_next_permutation(C& c, Compare&& comp) {
01554   return std::next_permutation(container_algorithm_internal::c_begin(c),
01555                                container_algorithm_internal::c_end(c),
01556                                std::forward<Compare>(comp));
01557 }
01558 
01559 // c_prev_permutation()
01560 //
01561 // Container-based version of the <algorithm> `std::prev_permutation()` function
01562 // to rearrange a container's elements into the next lexicographically lesser
01563 // permutation.
01564 template <typename C>
01565 bool c_prev_permutation(C& c) {
01566   return std::prev_permutation(container_algorithm_internal::c_begin(c),
01567                                container_algorithm_internal::c_end(c));
01568 }
01569 
01570 // Overload of c_prev_permutation() for performing a lexicographical
01571 // comparison using a `comp` operator instead of `operator<`.
01572 template <typename C, typename Compare>
01573 bool c_prev_permutation(C& c, Compare&& comp) {
01574   return std::prev_permutation(container_algorithm_internal::c_begin(c),
01575                                container_algorithm_internal::c_end(c),
01576                                std::forward<Compare>(comp));
01577 }
01578 
01579 //------------------------------------------------------------------------------
01580 // <numeric> algorithms
01581 //------------------------------------------------------------------------------
01582 
01583 // c_iota()
01584 //
01585 // Container-based version of the <algorithm> `std::iota()` function
01586 // to compute successive values of `value`, as if incremented with `++value`
01587 // after each element is written. and write them to the container.
01588 template <typename Sequence, typename T>
01589 void c_iota(Sequence& sequence, T&& value) {
01590   std::iota(container_algorithm_internal::c_begin(sequence),
01591             container_algorithm_internal::c_end(sequence),
01592             std::forward<T>(value));
01593 }
01594 // c_accumulate()
01595 //
01596 // Container-based version of the <algorithm> `std::accumulate()` function
01597 // to accumulate the element values of a container to `init` and return that
01598 // accumulation by value.
01599 //
01600 // Note: Due to a language technicality this function has return type
01601 // absl::decay_t<T>. As a user of this function you can casually read
01602 // this as "returns T by value" and assume it does the right thing.
01603 template <typename Sequence, typename T>
01604 decay_t<T> c_accumulate(const Sequence& sequence, T&& init) {
01605   return std::accumulate(container_algorithm_internal::c_begin(sequence),
01606                          container_algorithm_internal::c_end(sequence),
01607                          std::forward<T>(init));
01608 }
01609 
01610 // Overload of c_accumulate() for using a binary operations other than
01611 // addition for computing the accumulation.
01612 template <typename Sequence, typename T, typename BinaryOp>
01613 decay_t<T> c_accumulate(const Sequence& sequence, T&& init,
01614                         BinaryOp&& binary_op) {
01615   return std::accumulate(container_algorithm_internal::c_begin(sequence),
01616                          container_algorithm_internal::c_end(sequence),
01617                          std::forward<T>(init),
01618                          std::forward<BinaryOp>(binary_op));
01619 }
01620 
01621 // c_inner_product()
01622 //
01623 // Container-based version of the <algorithm> `std::inner_product()` function
01624 // to compute the cumulative inner product of container element pairs.
01625 //
01626 // Note: Due to a language technicality this function has return type
01627 // absl::decay_t<T>. As a user of this function you can casually read
01628 // this as "returns T by value" and assume it does the right thing.
01629 template <typename Sequence1, typename Sequence2, typename T>
01630 decay_t<T> c_inner_product(const Sequence1& factors1, const Sequence2& factors2,
01631                            T&& sum) {
01632   return std::inner_product(container_algorithm_internal::c_begin(factors1),
01633                             container_algorithm_internal::c_end(factors1),
01634                             container_algorithm_internal::c_begin(factors2),
01635                             std::forward<T>(sum));
01636 }
01637 
01638 // Overload of c_inner_product() for using binary operations other than
01639 // `operator+` (for computing the accumulation) and `operator*` (for computing
01640 // the product between the two container's element pair).
01641 template <typename Sequence1, typename Sequence2, typename T,
01642           typename BinaryOp1, typename BinaryOp2>
01643 decay_t<T> c_inner_product(const Sequence1& factors1, const Sequence2& factors2,
01644                            T&& sum, BinaryOp1&& op1, BinaryOp2&& op2) {
01645   return std::inner_product(container_algorithm_internal::c_begin(factors1),
01646                             container_algorithm_internal::c_end(factors1),
01647                             container_algorithm_internal::c_begin(factors2),
01648                             std::forward<T>(sum), std::forward<BinaryOp1>(op1),
01649                             std::forward<BinaryOp2>(op2));
01650 }
01651 
01652 // c_adjacent_difference()
01653 //
01654 // Container-based version of the <algorithm> `std::adjacent_difference()`
01655 // function to compute the difference between each element and the one preceding
01656 // it and write it to an iterator.
01657 template <typename InputSequence, typename OutputIt>
01658 OutputIt c_adjacent_difference(const InputSequence& input,
01659                                OutputIt output_first) {
01660   return std::adjacent_difference(container_algorithm_internal::c_begin(input),
01661                                   container_algorithm_internal::c_end(input),
01662                                   output_first);
01663 }
01664 
01665 // Overload of c_adjacent_difference() for using a binary operation other than
01666 // subtraction to compute the adjacent difference.
01667 template <typename InputSequence, typename OutputIt, typename BinaryOp>
01668 OutputIt c_adjacent_difference(const InputSequence& input,
01669                                OutputIt output_first, BinaryOp&& op) {
01670   return std::adjacent_difference(container_algorithm_internal::c_begin(input),
01671                                   container_algorithm_internal::c_end(input),
01672                                   output_first, std::forward<BinaryOp>(op));
01673 }
01674 
01675 // c_partial_sum()
01676 //
01677 // Container-based version of the <algorithm> `std::partial_sum()` function
01678 // to compute the partial sum of the elements in a sequence and write them
01679 // to an iterator. The partial sum is the sum of all element values so far in
01680 // the sequence.
01681 template <typename InputSequence, typename OutputIt>
01682 OutputIt c_partial_sum(const InputSequence& input, OutputIt output_first) {
01683   return std::partial_sum(container_algorithm_internal::c_begin(input),
01684                           container_algorithm_internal::c_end(input),
01685                           output_first);
01686 }
01687 
01688 // Overload of c_partial_sum() for using a binary operation other than addition
01689 // to compute the "partial sum".
01690 template <typename InputSequence, typename OutputIt, typename BinaryOp>
01691 OutputIt c_partial_sum(const InputSequence& input, OutputIt output_first,
01692                        BinaryOp&& op) {
01693   return std::partial_sum(container_algorithm_internal::c_begin(input),
01694                           container_algorithm_internal::c_end(input),
01695                           output_first, std::forward<BinaryOp>(op));
01696 }
01697 
01698 }  // namespace absl
01699 
01700 #endif  // ABSL_ALGORITHM_CONTAINER_H_


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:14