### C++ iota Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/iota.html Demonstrates how to use the iota function to fill a vector with sequentially increasing integers starting from a specified value. It then prints the vector's contents to standard output. ```C++ int main() { vector V(10); iota(V.begin(), V.end(), 7); copy(V.begin(), V.end(), ostream_iterator(cout, " ")); cout << endl; } ``` -------------------------------- ### Example Usage of return_temporary_buffer Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/return_temporary_buffer.html Demonstrates allocating memory with get_temporary_buffer, filling it, searching it, and then deallocating it with return_temporary_buffer. This example shows the typical lifecycle of temporary buffer usage. ```C++ int main() { pair P = get_temporary_buffer(10000, (int*) 0); int* buf = P.first; ptrdiff_t N = P.second; uninitialized_fill_n(buf, N, 42); int* result = find_if(buf, buf + N, binder2nd(not_equal_to(), 42)); assert(result == buf + N); return_temporary_buffer(buf); } ``` -------------------------------- ### C++ Example Using destroy and construct Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/destroy.html Demonstrates the usage of the destroy function to deconstruct objects in an array and the construct function to reinitialize them. This example highlights the separation of destruction and deallocation. ```C++ int main() { Int A[] = { Int(1), Int(2), Int(3), Int(4) }; destroy(A, A + 4); construct(A, Int(10)); construct(A + 1, Int(11)); construct(A + 2, Int(12)); construct(A + 3, Int(13)); } ``` -------------------------------- ### Copy Constructor Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/assignable.html Demonstrates the syntax for copy constructors, used for creating objects as copies of existing ones. ```C++ X(x) ``` ```C++ X x(y); X x = y; ``` -------------------------------- ### C++ make_heap Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/make_heap.html Demonstrates using make_heap to create a heap from an array and then sorting it. Requires the and headers. ```cpp int main() { int A[] = {1, 4, 2, 8, 5, 7}; const int N = sizeof(A) / sizeof(int); make_heap(A, A+N); copy(A, A+N, ostream_iterator(cout, " ")); cout << endl; sort_heap(A, A+N); copy(A, A+N, ostream_iterator(cout, " ")); cout << endl; } ``` -------------------------------- ### C++ Search Function Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/search.html Demonstrates how to use the search function to find a character subsequence within a C-style string. The example prints the found subsequence and its position. ```cpp const char S1[] = "Hello, world!"; const char S2[] = "world"; const int N1 = sizeof(S1) - 1; const int N2 = sizeof(S2) - 1; const char* p = search(S1, S1 + N1, S2, S2 + N2); printf("Found subsequence \"%s\" at character %d of sequence \"%s\".\n", S2, p - S1, S1); ``` -------------------------------- ### hash_multiset Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/hash_multiset.html Demonstrates the usage of hash_multiset with custom equality comparison for C-style strings. It shows insertion of elements and lookup of element counts. ```C++ struct eqstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; } }; void lookup(const hash_multiset, eqstr>& Set, const char* word) { int n_found = Set.count(word); cout << word << ": " << n_found << " " << (n_found == 1 ? "instance" : "instances") << endl; } int main() { hash_multiset, eqstr> Set; Set.insert("mango"); Set.insert("kiwi"); Set.insert("apple"); Set.insert("kiwi"); Set.insert("mango"); Set.insert("mango"); Set.insert("apricot"); Set.insert("banana"); Set.insert("mango"); lookup(Set, "mango"); lookup(Set, "apple"); lookup(Set, "durian"); } ``` -------------------------------- ### C++ copy_n Algorithm Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/copy_n.html This example demonstrates how to use the copy_n algorithm to copy elements from a vector to a list. It initializes a vector with sequential integers and then copies its contents to a list using copy_n. An assertion verifies that the contents of the vector and list are equal. ```cpp vector V(5); iota(V.begin(), V.end(), 1); list L(V.size()); copy_n(V.begin(), V.size(), L.begin()); assert(equal(V.begin(), V.end(), L.begin())); ``` -------------------------------- ### Advance Iterator Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/advance.html This example demonstrates how to use the 'advance' function to move an iterator to the end of an STL list. It requires the header and assumes the list is populated. ```C++ #include #include #include int main() { std::list L; L.push_back(0); L.push_back(1); std::list::iterator i = L.begin(); advance(i, 2); assert(i == L.end()); return 0; } ``` -------------------------------- ### Forward Iteration Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/reverseiterator.html Demonstrates standard forward iteration through a vector using an iterator. Elements are accessed in the order they appear. ```C++ template void forw(const vector& V) { vector::iterator first = V.begin(); vector::iterator last = V.end(); while (first != last) cout << *first++ << endl; } ``` -------------------------------- ### Using fabs with transform Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/pointer_to_unary_function.html This example demonstrates using the standard library function fabs directly with the transform algorithm. No pointer_to_unary_function adaptor is needed here. ```C++ transform(first, last, first, fabs); ``` -------------------------------- ### Reverse Iteration Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/reverseiterator.html Demonstrates reverse iteration through a vector using the reverse_iterator adaptor. Elements are accessed in reverse order. ```C++ template void rev(const vector& V) { typedef reverse_iterator::iterator, T, vector::reference_type, vector::difference_type> reverse_iterator; reverse_iterator rfirst(V.end()); reverse_iterator rlast(V.begin()); while (rfirst != rlast) cout << *rfirst++ << endl; } ``` -------------------------------- ### C++ fill_n Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/fill_n.html Demonstrates how to use fill_n to fill a vector with a specific value. Requires the , , and headers. ```C++ #include #include #include int main() { std::vector V; fill_n(std::back_inserter(V), 4, 137); assert(V.size() == 4 && V[0] == 137 && V[1] == 137 && V[2] == 137 && V[3] == 137); return 0; } ``` -------------------------------- ### Example Usage of uninitialized_fill_n Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/uninitialized_fill_n.html Demonstrates how to use uninitialized_fill_n to fill a block of memory allocated with malloc with instances of a custom class. ```cpp class Int { public: Int(int x) : val(x) {} int get() { return val; } private: int val; }; int main() { const int N = 137; Int val(46); Int* A = (Int*) malloc(N * sizeof(Int)); uninitialized_fill_n(A, N, val); } ``` -------------------------------- ### C++ Class Definition for Int Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/destroy.html Defines a simple integer class with a constructor and a get method. This class is used in the destroy example. ```C++ class Int { public: Int(int x) : val(x) {} int get() { return val; } private: int val; }; ``` -------------------------------- ### C++ Equal Function Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/equal.html Demonstrates the usage of the 'equal' function to compare two integer arrays for element-wise equality. It checks if the first range is identical to the second range starting from its beginning. ```C++ int A1[] = { 3, 1, 4, 1, 5, 9, 3 }; int A2[] = { 3, 1, 4, 2, 8, 5, 7 }; const int N = sizeof(A1) / sizeof(int); cout << "Result of comparison: " << equal(A1, A1 + N, A2) << endl; ``` -------------------------------- ### C++ replace_if Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/replace_if.html Replaces all negative numbers in a vector with 0. This example uses a lambda function with bind2nd and less to define the predicate. ```C++ template void replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value) { for (; first != last; ++first) if (pred(*first)) *first = new_value; } ``` ```C++ #include #include #include #include int main() { std::vector V; V.push_back(1); V.push_back(-3); V.push_back(2); V.push_back(-1); replace_if(V.begin(), V.end(), std::bind2nd(std::less(), 0), -1); assert(V[1] == 0 && V[3] == 0); return 0; } ``` -------------------------------- ### Replace n elements starting at index with a character range Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Replaces 'n' elements starting from the 'i'th element with characters from the range [f, l). ```C++ void replace(size_t i, size_t n, const charT* f, const charT* l) ``` ```C++ void replace(size_t i, size_t n, const const_iterator& f, const const_iterator& l) ``` ```C++ void replace(size_t i, size_t n, const iterator& f, const iterator& l) ``` -------------------------------- ### C++ Bitset Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/bitset.html Demonstrates creating, initializing, and performing bitwise operations on a C++ bitset. It shows inputting a bitset, converting it to an unsigned long, and applying bitwise AND and OR operations with a mask. ```C++ #include #include using namespace std; int main() { const bitset<12> mask(2730ul); cout << "mask = " << mask << endl; bitset<12> x; cout << "Enter a 12-bit bitset in binary: " << flush; if (cin >> x) { cout << "x = " << x << endl; cout << "As ulong: " << x.to_ulong() << endl; cout << "And with mask: " << (x & mask) << endl; cout << "Or with mask: " << (x | mask) << endl; } } ``` -------------------------------- ### C++ Set Example with Set Operations Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/set.html Demonstrates the creation and manipulation of sets using standard set algorithms like union, intersection, and difference. Requires the `` and `` headers. ```C++ #include #include #include #include #include struct ltstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; } }; int main() { const int N = 6; const char* a[N] = {"isomer", "ephemeral", "prosaic", "nugatory", "artichoke", "serif"}; const char* b[N] = {"flat", "this", "artichoke", "frigate", "prosaic", "isomer"}; set A(a, a + N); set B(b, b + N); set C; cout << "Set A: "; copy(A.begin(), A.end(), ostream_iterator(cout, " ")); cout << endl; cout << "Set B: "; copy(B.begin(), B.end(), ostream_iterator(cout, " ")); cout << endl; cout << "Union: "; set_union(A.begin(), A.end(), B.begin(), B.end(), ostream_iterator(cout, " "), ltstr()); cout << endl; cout << "Intersection: "; set_intersection(A.begin(), A.end(), B.begin(), B.end(), ostream_iterator(cout, " "), ltstr()); cout << endl; set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(C, C.begin()), ltstr()); cout << "Set C (difference of A and B): "; copy(C.begin(), C.end(), ostream_iterator(cout, " ")); cout << endl; } ``` -------------------------------- ### C++ Queue Basic Usage Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/queue.html Demonstrates the basic usage of a C++ queue, including pushing elements, checking size and back element, accessing and popping front elements, and verifying if the queue is empty. ```C++ int main() { queue Q; Q.push(8); Q.push(7); Q.push(6); Q.push(2); assert(Q.size() == 4); assert(Q.back() == 2); assert(Q.front() == 8); Q.pop(); assert(Q.front() == 7); Q.pop(); assert(Q.front() == 6); Q.pop(); assert(Q.front() == 2); Q.pop(); assert(Q.empty()); } ``` -------------------------------- ### Replace n elements starting at index with a range from a C string Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Replaces 'n1' elements starting from the 'i'th element with 'n2' elements from the C string 's'. ```C++ void replace(size_t i, size_t n1, const charT* s, size_t n2) ``` -------------------------------- ### C++ push_heap Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/push_heap.html Demonstrates the usage of push_heap to add an element to a heap. It first creates a heap using make_heap and then uses push_heap to insert an additional element. ```cpp int main() { int A[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; make_heap(A, A + 9); cout << "[A, A + 9) = "; copy(A, A + 9, ostream_iterator(cout, " ")); push_heap(A, A + 10); cout << endl << "[A, A + 10) = "; copy(A, A + 10, ostream_iterator(cout, " ")); cout << endl; } ``` -------------------------------- ### C++ list Example: Initialization and Insertion Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/list.html Demonstrates the initialization of a list and insertion of elements at the front, back, and middle. This snippet requires including the `` and `` headers, and `` for output. ```C++ list L; L.push_back(0); L.push_front(1); L.insert(++L.begin(), 2); copy(L.begin(), L.end(), ostream_iterator(cout, " ")); // The values that are printed are 1 2 0 ``` -------------------------------- ### C++ hash_map Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/hash_map.html Demonstrates the usage of hash_map to store and access integer values associated with string keys. This example uses a custom equality predicate for C-style strings. ```C++ struct eqstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; } }; int main() { hash_map, eqstr> months; months["january"] = 31; months["february"] = 28; months["march"] = 31; months["april"] = 30; months["may"] = 31; months["june"] = 30; months["july"] = 31; months["august"] = 31; months["september"] = 30; months["october"] = 31; months["november"] = 30; months["december"] = 31; cout << "september -> " << months["september"] << endl; cout << "april -> " << months["april"] << endl; cout << "june -> " << months["june"] << endl; cout << "november -> " << months["november"] << endl; } ``` -------------------------------- ### C++ Multimap Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/multimap.html Demonstrates the usage of a C++ multimap with custom key comparison. It shows how to insert elements, count elements by key, and iterate through the multimap. ```C++ struct ltstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; } }; int main() { multimap m; m.insert(pair("a", 1)); m.insert(pair("c", 2)); m.insert(pair("b", 3)); m.insert(pair("b", 4)); m.insert(pair("a", 5)); m.insert(pair("b", 6)); cout << "Number of elements with key a: " << m.count("a") << endl; cout << "Number of elements with key b: " << m.count("b") << endl; cout << "Number of elements with key c: " << m.count("c") << endl; cout << "Elements in m: " << endl; for (multimap::iterator it = m.begin(); it != m.end(); ++it) cout << " [" << (*it).first << ", " << (*it).second << "]" << endl; } ``` -------------------------------- ### Example Usage of bind2nd with greater Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/binder2nd.html This example demonstrates how to use bind2nd with the greater function object to find the first positive number in a list. It utilizes the find_if algorithm to search within the list's iterators. ```C++ #include #include #include #include int main() { std::list L; L.push_back(-2); L.push_back(0); L.push_back(5); L.push_back(3); std::list::iterator first_positive = std::find_if(L.begin(), L.end(), std::bind2nd(std::greater(), 0)); assert(first_positive == L.end() || *first_positive > 0); return 0; } ``` -------------------------------- ### C++ Hash Set Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/hash_set.html Demonstrates the usage of hash_set with custom hash and equality functions for string keys. It shows insertion, lookup, and handling of elements not present in the set. ```C++ struct eqstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; } }; void lookup(const hash_set, eqstr>& Set, const char* word) { hash_set, eqstr>::const_iterator it = Set.find(word); cout << word << ": " << (it != Set.end() ? "present" : "not present") << endl; } int main() { hash_set, eqstr> Set; Set.insert("kiwi"); Set.insert("plum"); Set.insert("apple"); Set.insert("mango"); Set.insert("apricot"); Set.insert("banana"); lookup(Set, "mango"); lookup(Set, "apple"); lookup(Set, "durian"); } ``` -------------------------------- ### unique_copy Example: Printing Unique Consecutive Numbers Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/unique_copy.html This example demonstrates how to use unique_copy to print numbers from an array, ensuring that only the first occurrence of any consecutive duplicate number is printed. It uses an ostream_iterator to output the results to the console. ```cpp const int A[] = {2, 7, 7, 7, 1, 1, 8, 8, 8, 2, 8, 8}; unique_copy(A, A + sizeof(A) / sizeof(int), std::ostream_iterator(cout, " ")); // The output is "2 7 1 8 2 8". ``` -------------------------------- ### C++ Multiset Example with Set Algorithms Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/multiset.html Demonstrates the usage of multiset with standard set algorithms including union, intersection, and difference. It initializes two multisets from arrays and performs these operations, outputting the results. ```C++ int main() { const int N = 10; int a[N] = {4, 1, 1, 1, 1, 1, 0, 5, 1, 0}; int b[N] = {4, 4, 2, 4, 2, 4, 0, 1, 5, 5}; multiset A(a, a + N); multiset B(b, b + N); multiset C; cout << "Set A: "; copy(A.begin(), A.end(), ostream_iterator(cout, " ")); cout << endl; cout << "Set B: "; copy(B.begin(), B.end(), ostream_iterator(cout, " ")); cout << endl; cout << "Union: "; set_union(A.begin(), A.end(), B.begin(), B.end(), ostream_iterator(cout, " ")); cout << endl; cout << "Intersection: "; set_intersection(A.begin(), A.end(), B.begin(), B.end(), ostream_iterator(cout, " ")); cout << endl; set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(C, C.begin())); cout << "Set C (difference of A and B): "; copy(C.begin(), C.end(), ostream_iterator(cout, " ")); cout << endl; } ``` -------------------------------- ### C++ Example: Find First Non-Positive Element Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/less_equal.html This example demonstrates how to use less_equal with std::bind2nd to find the first element in a list that is less than or equal to 0. It requires the , , and headers. ```C++ [list](List.html) L; ... [list](List.html)::iterator first_nonpositive = [find_if](find_if.html)(L.begin(), L.end(), [bind2nd](binder2nd.html)(less_equal(), 0)); assert(first_nonpositive == L.end() || *first_nonpositive <= 0); ``` -------------------------------- ### C++ stable_partition Example: Even Numbers Before Odd Numbers Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/stable_partition.html Reorders an array so that all even numbers precede all odd numbers, preserving the relative order within the even and odd groups. This example uses function objects and binders for the predicate. ```C++ int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const int N = sizeof(A)/sizeof(int); stable_partition(A, A + N, [compose1](unary_compose.html)([bind2nd](binder2nd.html)([equal_to](equal_to.html)(), 0), [bind2nd](binder2nd.html)([modulus](modulus.html)(), 2))); [copy](copy.html)(A, A + N, [ostream_iterator](ostream_iterator.html)(cout, " ")); // The output is "2 4 6 8 10 1 3 5 7 9". [1] ``` -------------------------------- ### C++ Stack Basic Usage Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/stack.html Demonstrates the basic usage of the C++ stack, including pushing elements, checking size, accessing the top element, popping elements, and verifying if the stack is empty. ```C++ int main() { stack S; S.push(8); S.push(7); S.push(4); assert(S.size() == 3); assert(S.top() == 4); S.pop(); assert(S.top() == 7); S.pop(); assert(S.top() == 8); S.pop(); assert(S.empty()); } ``` -------------------------------- ### C++ Priority Queue Basic Usage Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/priority_queue.html Demonstrates the basic usage of a C++ priority_queue, including pushing elements, checking size, accessing the top element, and popping elements until empty. Asserts are used to verify expected behavior. ```cpp int main() { priority_queue Q; Q.push(1); Q.push(4); Q.push(2); Q.push(8); Q.push(5); Q.push(7); assert(Q.size() == 6); assert(Q.top() == 8); Q.pop(); assert(Q.top() == 7); Q.pop(); assert(Q.top() == 5); Q.pop(); assert(Q.top() == 4); Q.pop(); assert(Q.top() == 2); Q.pop(); assert(Q.top() == 1); Q.pop(); assert(Q.empty()); } ``` -------------------------------- ### C++ equal_range Usage Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/equal_range.html This example demonstrates how to use std::equal_range to find the range of elements equivalent to a given value in a sorted integer array. It shows how to interpret the returned iterators to determine the first and last positions where the value could be inserted. ```cpp int main() { int A[] = { 1, 2, 3, 3, 3, 5, 8 }; const int N = sizeof(A) / sizeof(int); for (int i = 2; i <= 4; ++i) { pair result = equal_range(A, A + N, i); cout << endl; cout << " Searching for " << i << endl; cout << " First position where " << i << " could be inserted: " << result.first - A << endl; cout << " Last position where " << i << " could be inserted: " << result.second - A << endl; if (result.first < A + N) cout << " *result.first = " << *result.first << endl; if (result.second < A + N) cout << " *result.second = " << *result.second << endl; } } ``` -------------------------------- ### Deque Initialization and Manipulation Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/deque.html Demonstrates basic deque operations including adding elements to the front and back, inserting in the middle, and modifying elements. It also shows how to print the deque's contents. ```C++ deque Q; Q.push_back(3); Q.push_front(1); Q.insert(Q.begin() + 1, 2); Q[2] = 0; copy(Q.begin(), Q.end(), ostream_iterator(cout, " ")); // The values that are printed are 1 2 0 ``` -------------------------------- ### Get Rope Length Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Returns the length of the rope. Synonym for size. ```C++ size_type length() const ``` -------------------------------- ### Slist Example: Insertion and Traversal Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/slist.html Demonstrates basic usage of slist, including pushing elements to the front, inserting after a specific iterator, and traversing the list to print elements. It also shows how to insert multiple elements after a specific position. ```cpp int main() { slist L; L.push_front(0); L.push_front(1); L.insert_after(L.begin(), 2); [copy](copy.html)(L.begin(), L.end(), // The output is 1 2 0 [ostream_iterator](ostream_iterator.html)(cout, " ")); cout << endl; slist::iterator back = L.previous(L.end()); back = L.insert_after(back, 3); back = L.insert_after(back, 4); back = L.insert_after(back, 5); [copy](copy.html)(L.begin(), L.end(), // The output is 1 2 0 3 4 5 [ostream_iterator](ostream_iterator.html)(cout, " ")); cout << endl; } ``` -------------------------------- ### Get Mutable Begin Iterator Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Returns a mutable iterator to the beginning of the rope. ```C++ iterator mutable_begin() ``` -------------------------------- ### Basic String Operations Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/basic_string.html Demonstrates creating, concatenating, accessing, and manipulating a C++ string. Includes initialization with a size and character, appending a C-style string, accessing characters by index, and reversing the string. ```C++ int main() { string s(10u, ' '); // Create a string of ten blanks. const char* A = "this is a test"; s += A; cout << "s = " << (s + '\n'); cout << "As a null-terminated sequence: " << s.c_str() << endl; cout << "The sixteenth character is " << s[15] << endl; reverse(s.begin(), s.end()); s.push_back('\n'); cout << s; } ``` -------------------------------- ### Get C-String Representation Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Returns a pointer to a null-terminated C-string representation of the rope. ```C++ const charT* c_str() const ``` -------------------------------- ### Basic min Function Usage Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/min.html Demonstrates the basic usage of the `min` function with integer arguments. It requires the `` header. ```cpp const int x = min(3, 9); assert(x == 3); ``` -------------------------------- ### Substring from Iterator Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Returns a new rope containing the substring starting from iterator f. ```C++ rope substr(iterator f) const ``` -------------------------------- ### C++ is_sorted Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/is_sorted.html Demonstrates how to use the is_sorted function to check if an array is sorted before and after sorting it. ```cpp int A[] = {1, 4, 2, 8, 5, 7}; const int N = sizeof(A) / sizeof(int); assert(!is_sorted(A, A + N)); [sort](sort.html)(A, A + N); assert(is_sorted(A, A + N)); ``` -------------------------------- ### Rope Construction and Operations Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Demonstrates the construction of ropes with characters, concatenation, substring extraction, and reversing using mutable iterators. Note that reversing a large rope can be slow. ```cpp crope r(1000000, 'x'); // crope is rope. wrope is rope // Builds a rope containing a million 'x's. // Takes much less than a MB, since the // different pieces are shared. crope r2 = r + "abc" + r; // concatenation; takes on the order of 100s // of machine instructions; fast crope r3 = r2.substr(1000000, 3); // yields "abc"; fast. crope r4 = r2.substr(1000000, 1000000); // also fast. reverse(r2.mutable_begin(), r2.mutable_end()); // correct, but slow; may take a // minute or more. ``` -------------------------------- ### C++ partition Algorithm Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/partition.html Reorders a sequence so that even numbers precede odd numbers. The relative order of elements within the even and odd groups is not preserved. ```cpp int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; const int N = sizeof(A)/sizeof(int); partition(A, A + N, [compose1](unary_compose.html)([bind2nd](binder2nd.html)([equal_to](equal_to.html)(), 0), [bind2nd](binder2nd.html)([modulus](modulus.html)(), 2))); [copy](copy.html)(A, A + N, [ostream_iterator](ostream_iterator.html)(cout, " ")); // The output is "10 2 8 4 6 5 7 3 9 1". [1] ``` -------------------------------- ### Substring from Const Iterator Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Returns a new rope containing the substring starting from const_iterator f. ```C++ rope substr(const_iterator f) const ``` -------------------------------- ### Replace Substring with Character Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Replaces the substring starting at index i with length n with character c. ```C++ void replace(size_t i, size_t n, charT c) ``` -------------------------------- ### C++ search_n Example with Equality Operator Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/search_n.html Demonstrates the usage of the search_n algorithm to find a subsequence of identical elements using the default equality operator. It shows how to search for sequences of varying lengths and values. ```C++ bool eq_nosign(int x, int y) { return abs(x) == abs(y); } void lookup(int* first, int* last, size_t count, int val) { cout << "Searching for a sequence of " << count << " '" << val << "'" << (count != 1 ? "s: " : ": "); int* result = search_n(first, last, count, val); if (result == last) cout << "Not found" << endl; else cout << "Index = " << result - first << endl; } void lookup_nosign(int* first, int* last, size_t count, int val) { cout << "Searching for a (sign-insensitive) sequence of " << count << " '" << val << "'" << (count != 1 ? "s: " : ": "); int* result = search_n(first, last, count, val, eq_nosign); if (result == last) cout << "Not found" << endl; else cout << "Index = " << result - first << endl; } int main() { const int N = 10; int A[N] = {1, 2, 1, 1, 3, -3, 1, 1, 1, 1}; lookup(A, A+N, 1, 4); lookup(A, A+N, 0, 4); lookup(A, A+N, 1, 1); lookup(A, A+N, 2, 1); lookup(A, A+N, 3, 1); lookup(A, A+N, 4, 1); lookup(A, A+N, 1, 3); lookup(A, A+N, 2, 3); lookup_nosign(A, A+N, 1, 3); lookup_nosign(A, A+N, 2, 3); } ``` -------------------------------- ### Rope Iterators Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Provides methods to get iterators for mutable access to the rope's elements. ```APIDOC ## mutable_begin ### Description Returns an iterator pointing to the beginning of the rope for mutable access. ### Method `iterator mutable_begin()` ### Endpoint N/A (Member function) ## mutable_end ### Description Returns an iterator pointing to the end of the rope for mutable access. ### Method `iterator mutable_end()` ### Endpoint N/A (Member function) ## mutable_rbegin ### Description Returns a reverse_iterator pointing to the beginning of the reversed rope for mutable access. ### Method `iterator mutable_rbegin()` ### Endpoint N/A (Member function) ## mutable_rend ### Description Returns a reverse_iterator pointing to the end of the reversed rope for mutable access. ### Method `iterator mutable_rend()` ### Endpoint N/A (Member function) ``` -------------------------------- ### C++ partial_sum Example Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/partial_sum.html Demonstrates the usage of the partial_sum function to compute running sums of elements in an array. It initializes an array with ones, prints the array, and then computes and prints its partial sums. ```C++ int main() { const int N = 10; int A[N]; fill(A, A+N, 1); cout << "A: "; copy(A, A+N, ostream_iterator(cout, " ")); cout << endl; cout << "Partial sums of A: "; partial_sum(A, A+N, ostream_iterator(cout, " ")); cout << endl; } ``` -------------------------------- ### Replace Substring with C-String Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Replaces the substring starting at index i with length n with the contents of C-string s. ```C++ void replace(size_t i, size_t n, const charT* s) ``` -------------------------------- ### Replace Substring with Rope Source: https://github.com/coderserdar/documents/blob/main/Programming Languages/C++/Borland C++ Builder Help Content/English/Help/rope.html Replaces the substring starting at index i with length n with the contents of rope x. ```C++ void replace(size_t i, size_t n, const rope& x) ```