diff --git a/docs/standard-library/algorithm-functions.md b/docs/standard-library/algorithm-functions.md index b243d2c1ebb..65b150d64e8 100644 --- a/docs/standard-library/algorithm-functions.md +++ b/docs/standard-library/algorithm-functions.md @@ -595,7 +595,7 @@ An output iterator addressing the position that is one past the final element in The source range must be valid and there must be sufficient space at the destination to hold all the elements being copied. -The `copy_backward` algorithm imposes more stringent requirements than that the `copy` algorithm. Both its input and output iterators must be bidirectional. +The `copy_backward` algorithm imposes more stringent requirements than the `copy` algorithm. Both its input and output iterators must be bidirectional. The `copy_backward` and [`move_backward`](algorithm-functions.md#move_backward) algorithms are the only C++ Standard Library algorithms designating the output range with an iterator pointing to the end of the destination range. @@ -908,13 +908,13 @@ int main() vector::iterator::difference_type result; result = count(v1.begin(), v1.end(), 10); - cout << "The number of 10s in v2 is: " << result << "." << endl; + cout << "The number of 10s in v1 is: " << result << "." << endl; } ``` ```Output v1 = ( 10 20 10 40 10 ) -The number of 10s in v2 is: 3. +The number of 10s in v1 is: 3. ``` ## `count_if` @@ -2149,7 +2149,7 @@ public: { } - // The function call to process the next elment + // The function call to process the next element void operator( ) ( int elem ) { num++; // Increment the element count @@ -2292,7 +2292,7 @@ public: } }; -// Utility to display the contents of a vector +// Utility to display the contents of a vector template void print_vector(const std::vector &vec) { std::cout << "( "; @@ -2686,7 +2686,7 @@ int main() cout << *Iter3b << " "; cout << ")." << endl; - // To test for inclusion under an asscending order + // To test for inclusion under an ascending order // with the default binary predicate less( ) bool Result1; Result1 = includes ( v1a.begin( ), v1a.end( ), @@ -2892,7 +2892,7 @@ int main() // Applying a user defined (UD) binary predicate mod_lesser inplace_merge ( v3.begin( ), break3, v3.end( ), mod_lesser ); cout << "Merged inplace with binary predicate mod_lesser specified,\n " - << "vector v3mod = ( " ; ; + << "vector v3mod = ( " ; for ( Iter3 = v3.begin( ) ; Iter3 != v3.end( ) ; Iter3++ ) cout << *Iter3 << " "; cout << ")" << endl; @@ -4424,7 +4424,7 @@ int main() { merge ( v3a.begin( ), v3a.end( ), v3b.begin( ), v3b.end( ), v3.begin( ), mod_lesser ); cout << "Merged inplace with binary predicate mod_lesser specified,\n " - << "vector v3mod = ( " ; ; + << "vector v3mod = ( " ; for ( Iter3 = v3.begin( ) ; Iter3 != v3.end( ) ; Iter3++ ) cout << *Iter3 << " "; cout << ")." << endl; @@ -4949,13 +4949,14 @@ Use the dual-range overloads in C++14 code because the overloads that only take ```cpp template -pair> +pair mismatch( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2 ); -template pair> +template +pair mismatch( InputIterator1 first1, InputIterator1 last1, @@ -4964,14 +4965,15 @@ mismatch( //C++14 template -pair> +pair mismatch( InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2 ); -template pair> +template +pair mismatch( InputIterator1 first1, InputIterator1 last1, @@ -5933,7 +5935,7 @@ int main() cout << *Iter1 << " "; cout << ")." << endl; - // Partition the range with predicate greater10 + // Partition the range with predicate greater5 partition ( v1.begin( ), v1.end( ), greater5 ); cout << "The partitioned set of elements in v1 is: ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) @@ -6660,7 +6662,7 @@ Vector v2 is a copy of v1 with the value 7 removed: ## `remove_copy_if` -Copies elements from a source range to a destination range, except for elements that satisfy a predicate. Elements are copied without disturbing the order of the remaining elements. Returns the end of a new destination range. +Copies elements from a source range to a destination range, except for elements that satisfy a predicate. Elements are copied without disturbing the order of the remaining elements. Returns the end of a new destination range. ```cpp template @@ -6694,7 +6696,7 @@ An input iterator addressing the position one past the final element in the rang An output iterator addressing the position of the first element in the destination range to which elements are being removed. *`pred`*\ -The unary predicate that must be satisfied is the value of an element is to be replaced. +The unary predicate that must be satisfied if the value of an element is to be replaced. ### Return value @@ -6751,7 +6753,7 @@ int main() new_end = remove_copy_if ( v1.begin( ), v1.end( ), v2.begin( ), greater6 ); - cout << "After the appliation of remove_copy_if to v1,\n " + cout << "After the application of remove_copy_if to v1,\n " << "vector v1 is left unchanged as ( " ; for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ ) cout << *Iter1 << " "; @@ -6767,7 +6769,7 @@ int main() ```Output The original vector v1 is: ( 4 7 7 7 0 5 7 1 6 9 3 7 8 2 ). -After the appliation of remove_copy_if to v1, +After the application of remove_copy_if to v1, vector v1 is left unchanged as ( 4 7 7 7 0 5 7 1 6 9 3 7 8 2 ). Vector v2 is a copy of v1 with values greater than 6 removed: ( 4 0 5 1 6 3 2 ). @@ -6804,7 +6806,7 @@ A forward iterator pointing to the position of the first element in the range fr A forward iterator pointing to the position one past the final element in the range from which elements are being removed. *`pred`*\ -The unary predicate that must be satisfied is the value of an element is to be replaced. +The unary predicate that must be satisfied if the value of an element is to be replaced. ### Return value @@ -7148,7 +7150,7 @@ An input iterator pointing to the position one past the final element in the ran An output iterator pointing to the position of the first element in the destination range to which elements are being copied. *`pred`*\ -The unary predicate that must be satisfied is the value of an element is to be replaced. +The unary predicate that must be satisfied if the value of an element is to be replaced. *`value`*\ The new value being assigned to the elements whose old value satisfies the predicate. @@ -7277,7 +7279,7 @@ A forward iterator pointing to the position of the first element in the range fr An iterator pointing to the position one past the final element in the range from which elements are being replaced. *`pred`*\ -The unary predicate that must be satisfied is the value of an element is to be replaced. +The unary predicate that must be satisfied if the value of an element is to be replaced. *`value`*\ The new value being assigned to the elements whose old value satisfies the predicate. @@ -8269,7 +8271,7 @@ int main() cout << *Iter3b << " "; cout << ")." << endl; - // To combine into a difference in asscending + // To combine into a difference in ascending // order with the default binary predicate less( ) Result1 = set_difference ( v1a.begin( ), v1a.end( ), v1b.begin( ), v1b.end( ), v1.begin( ) ); @@ -8294,7 +8296,7 @@ int main() Result3 = set_difference ( v3a.begin( ), v3a.end( ), v3b.begin( ), v3b.end( ), v3.begin( ), mod_lesser ); cout << "Set_difference of source ranges with binary " - << "predicate mod_lesser specified,\n vector v3mod = ( " ; ; + << "predicate mod_lesser specified,\n vector v3mod = ( " ; for ( Iter3 = v3.begin( ) ; Iter3 != Result3 ; Iter3++ ) cout << *Iter3 << " "; cout << ")." << endl; @@ -8488,7 +8490,7 @@ int main() cout << *Iter3b << " "; cout << ")." << endl; - // To combine into an intersection in asscending order with the + // To combine into an intersection in ascending order with the // default binary predicate less( ) Result1 = set_intersection ( v1a.begin( ), v1a.end( ), v1b.begin( ), v1b.end( ), v1.begin( ) ); @@ -8513,7 +8515,7 @@ int main() Result3 = set_intersection ( v3a.begin( ), v3a.end( ), v3b.begin( ), v3b.end( ), v3.begin( ), mod_lesser ); cout << "Intersection of source ranges with binary predicate " - << "mod_lesser specified,\n vector v3mod = ( " ; ; + << "mod_lesser specified,\n vector v3mod = ( " ; for ( Iter3 = v3.begin( ) ; Iter3 != Result3 ; ++Iter3 ) cout << *Iter3 << " "; cout << ")." << endl; @@ -8736,7 +8738,7 @@ int main() Result3 = set_symmetric_difference ( v3a.begin( ), v3a.end( ), v3b.begin( ), v3b.end( ), v3.begin( ), mod_lesser ); cout << "Set_symmetric_difference of source ranges with binary " - << "predicate mod_lesser specified,\n vector v3mod = ( " ; ; + << "predicate mod_lesser specified,\n vector v3mod = ( " ; for ( Iter3 = v3.begin( ) ; Iter3 != Result3 ; Iter3++ ) cout << *Iter3 << " "; cout << ")." << endl; @@ -8959,7 +8961,7 @@ int main() Result3 = set_union ( v3a.begin( ), v3a.end( ), v3b.begin( ), v3b.end( ), v3.begin( ), mod_lesser ); cout << "Union of source ranges with binary predicate " - << "mod_lesser specified,\n vector v3mod = ( " ; ; + << "mod_lesser specified,\n vector v3mod = ( " ; for ( Iter3 = v3.begin( ) ; Iter3 != Result3 ; Iter3++ ) cout << *Iter3 << " "; cout << ")." << endl; @@ -9170,7 +9172,7 @@ Heaps have two properties: - Elements may be added or removed in logarithmic time. -After the application if this algorithm, the range it was applied to is no longer a heap. +After the application of this algorithm, the range it was applied to is no longer a heap. `sort_heap` isn't a stable sort because the relative order of equivalent elements isn't necessarily preserved. @@ -9585,7 +9587,7 @@ A forward iterator pointing to one past the final position of the second range w The ranges referenced must be valid; all pointers must be dereferenceable and within each sequence the last position is reachable from the first by incrementation. The second range has to be as large as the first range. -The complexity is linear with *last1* - *first1* swaps performed. If elements from containers of the same type are being swapped, them the `swap` member function from that container should be used, because the member function typically has constant complexity. +The complexity is linear with *last1* - *first1* swaps performed. If elements from containers of the same type are being swapped, then the `swap` member function from that container should be used, because the member function typically has constant complexity. ### Example @@ -9922,7 +9924,7 @@ int main() cout << *v1_Iter1 << " "; cout << ")." << endl; - // Remove consecutive duplicates under the binary prediate mod_equals + // Remove consecutive duplicates under the binary predicate mod_equals v1_NewEnd2 = unique ( v1.begin( ), v1_NewEnd1 , mod_equal ); cout << "Removing adjacent duplicates from vector v1 under the\n " @@ -10078,7 +10080,7 @@ int main() { for ( iv = 0 ; iv <= 7 ; iv++ ) v1.push_back( 10 ); - // Remove consecutive duplicates under the binary prediate mod_equals + // Remove consecutive duplicates under the binary predicate mod_equals v1_NewEnd2 = unique_copy ( v1.begin( ), v1.begin( ) + 14, v1.begin( ) + 14 , mod_equal );