Tag: STL
33 posts
-
C++ std::reverse, reverse_copy and rotate: Reordering Ranges in Place
Reverse ranges in place or into a copy with std::reverse and reverse_copy; rotate segments with std::rotate — palindromes, string reversal, and array.
-
C++ Technical Interview
C++ technical interviews expect you to explain pointers, RAII, virtual functions, STL, and concurrency verbally.
-
vector vs list vs deque: Why Cache Locality Usually Beats Big-O
Choosing between C++ STL vector, list and deque: internal layouts, time complexity, real benchmarks showing cache effects, and a situation-by-situation selection guide.
-
std::set_union, set_intersection and set_difference on Sorted Ranges: Duplicates, Comparators and Silent Wrong Output
How the STL set algorithms merge two sorted ranges in one pass, how they treat duplicates, and why unsorted input or a mismatched comparator fails silently.
-
C++ stack, queue and priority_queue: How the Adapters Work and the Mistakes They Invite
std::stack, std::queue and std::priority_queue explained: why pop() returns void, choosing the underlying container, min-heaps and custom comparators, Dijkstra, BFS bugs, and thread safety.
-
set vs unordered_set in C++: Performance, Custom Comparators and Hashes, and Set Operations
set·unordered_set performance comparison, multiset, custom comparator·hash, practical set operations, iterator invalidation guide.
-
std::string Pitfalls: SSO, c_str() Lifetime, string_view Dangling and UTF-8
Practical std::string guide: concatenation, compare, substr, find, replace, SSO, string_view lifetime, reserve for +=, and c_str validity in modern C++.
-
std::vector in Practice: reserve vs resize, Iterator Invalidation and 2D Vectors
std::vector explained: why it beats raw arrays, reserve vs resize, iterator invalidation, algorithms, 2D vectors, and practical examples with pitfalls.
-
Tag Dispatching in C++: Overload Selection by Tag Types, vs if constexpr and Concepts
How tag dispatching picks a C++ overload at compile time with empty tag types, why iterator tags inherit from each other, and when if constexpr fits better.
-
C++ std::vector Basics: Initialization, Operations, Capacity and Iterator Safety
C++ std::vector fundamentals: init, access, insert/erase, size vs capacity, reserve vs resize, iterator safety, and production patterns.
-
C++ STL Algorithms Basics: Replacing Hand-Written Loops with sort, find_if, transform and accumulate
Replace hand-written loops with std::sort, find, find_if, count_if, transform, accumulate—iterator ranges, erase-remove, lower_bound on sorted data.
-
C++ Iterators: Categories, Operations, iterator_traits and Invalidation Bugs
C++ iterators explained: the five categories, iterator operations, iterator_traits, custom filter and transform iterators, and bugs like dereferencing end().
-
Preparing for C++ Coding Interviews: 7 Problem Types, Must-Know STL and a Day-Of Checklist
Preparing for C++ coding tests and interviews: seven common problem types, the STL you need, time complexity budgets, fast I/O, and the mistakes behind TLE, WA and MLE.
-
C++ Function Objects: Stateful Functors, Comparators, and std::function Overhead
What functors are, stateful vs function pointers, STL algorithms with predicates, comparison functors, and std::function overhead vs templates.
-
C++ Iterator Invalidation: “vector iterators incompatible”
Iterator invalidation rules for vector, deque, list, map and unordered_map, ten bugs behind 'vector iterators incompatible', and fixes using erase's return.
-
C++ map vs unordered_map: Complexity, Pitfalls, and When to Use Each
map vs unordered_map: sorted red-black tree vs hash table. Complexity, range queries, the operator[] insertion pitfall, erasing while iterating, iterator invalidation, and custom key hashing.
-
C++ vector reserve vs resize: When to Use Which
vector::reserve changes capacity only while resize changes size and constructs elements. Covers the v[i]-after-reserve bug, growth rules, and reserve-in-a-loop.
-
C++ emplace vs push: Performance and Move Semantics
When emplace_back really beats push_back: in-place construction, how move semantics narrow the gap, and traps with explicit constructors and exceptions.
-
C++ std::bitset: Flags, Bit Masks, Subset Enumeration, and vector<bool> Compared
Use std::bitset for flag sets and bit masks: setting, testing and counting bits, converting to strings and integers, enumerating subsets, and how it differs from vector<bool>.
-
Why std::remove Doesn't Shrink Your Vector: Erase-Remove, std::erase_if and the Moved-From Tail
How std::remove and remove_if really work, why size stays the same, what is left in the tail, and when to use C++20 std::erase_if, list::remove or unique.
-
std::replace, replace_if and replace_copy in C++: The v[0] Aliasing Bug, Type Deduction Errors and Substring Replacement
How std::replace, replace_if and replace_copy work, why passing v[0] as the old value stops replacing, the int/double deduction error, and substring replace.
-
C++ Search Algorithms: find, binary_search, lower_bound, and upper_bound
Choose between linear find and binary search on sorted ranges; use lower_bound, upper_bound, and equal_range for positions and equal-key runs in C++.
-
C++ Sorting: std::sort, stable_sort, partial_sort and nth_element
Compare C++ std::sort, stable_sort, partial_sort, and nth_element: custom comparators, partial sorts, median selection, and practical STL sorting patterns.
-
C++ Custom Allocators for STL Containers: Pool, Stack, Tracking Allocators and PMR
Default std::allocator, passing allocators to containers, custom pool and tracking allocators, PMR monotonic_buffer_resource.
-
C++ Copy Algorithms: std::copy, copy_if, copy_n
Copy and move ranges safely in C++ with std::copy, copy_if, copy_n, copy_backward, and remove_copy. Hand-written copy loops work, but the algorithm versions make intent explicit and avoid off-by-one and overlap bugs.
-
C++ count, count_if, all_of, any_of and none_of: Counting and Checking Conditions
Count matching values and predicates with std::count and count_if; learn all_of, any_of, none_of, empty ranges, and short-circuit behavior in C++.
-
C++ Generate Algorithms: std::fill and std::generate
Fill C++ containers with std::fill, std::generate, and std::iota, including fill_n/generate_n with back_inserter, indirect sorting with iota, proper C++11 random number generation, and common capture-by-value pitfalls.
-
C++ STL Algorithms: sort, find, transform, and the Mistakes That Give Wrong Results
C++ STL algorithm core summary. Frequently used functions like sort, search, transform, and tips to prevent mistakes and make selections.
-
C++ Heap Algorithms: make_heap, push_heap, pop_heap
How make_heap, push_heap, pop_heap and sort_heap keep a heap inside a vector, when priority_queue is simpler, and how comparators build a min-heap.
-
C++ MinMax Algorithms: std::min, max, minmax_element & clamp
Use std::min, max, minmax, min_element, max_element, minmax_element, and C++17 std::clamp — two-value vs range APIs, iterators, and performance notes.
-
C++ <numeric>: accumulate vs reduce, transform_reduce, Scans and the Init-Type Trap
How std::accumulate, reduce, transform_reduce, partial_sum and the scans differ: evaluation order, associativity, init value type, overflow, parallel policies.
-
C++ partition, stable_partition and partition_point: Splitting Ranges by a Predicate
std::partition, stable_partition, partition_point and partition_copy in C++: splitting ranges by a predicate, keeping order, finding the boundary, 3-way splits.
-
C++ next_permutation and prev_permutation: All Permutations, Duplicates and Combinations
How std::next_permutation works, why you sort first, how duplicates are handled, correct k-permutation and nCk loops, ranges versions and the k-th permutation.