Skip to content

Posts

C++ Basics: Update a Map Entry and Detect New Keys

Use std::map::insert_or_assign when an incoming value should replace an existing value or create a new entry.

Read more →

November 9, 2026

C++ Basics: Show Reverse Order Without Mutating the Source

Use std::reverse_copy to create a reverse-ordered report while keeping the original event sequence intact.

Read more →

November 9, 2026

C++ Basics: Search Using the Same Sort Rule

Use std::binary_search with the comparator that ordered the data. A descending range needs a descending comparison for the search too.

Read more →

November 9, 2026

C++ Basics: Reset Only the Used Prefix of a Buffer

Use std::fill_n when a buffer has a known number of entries to reset. The returned iterator marks the end of the written prefix.

Read more →

November 9, 2026

C++ Basics: Read Every Value for a Repeated Map Key

Use std::multimap::equal_range to read a whole group of entries sharing a key. A single find result cannot represent every matching record.

Read more →

November 9, 2026

C++ Basics: Probe a Type-Erased Value Without Throwing

Use the pointer overload of std::any_cast to inspect an optional runtime type match. A failed probe returns nullptr rather than converting the stored value.

Read more →

November 9, 2026

C++ Basics: Normalize Invalid Entries in Place

Use std::replace_if to substitute a fixed value for matching entries while keeping the sequence length and positions unchanged.

Read more →

November 9, 2026

C++ Basics: Make Empty-Input Validation Explicit

Use std::all_of for a per-record condition, and add a separate nonempty check when an empty batch must fail validation.

Read more →

November 9, 2026

C++ Basics: Insert After Existing Equal Values

Use std::upper_bound to find the position after an existing group of equal values in an ascending vector.

Read more →

November 9, 2026

C++ Basics: Generate Values with Local Callable State

Use std::generate_n to append a short sequence whose next value depends on local state. An insertion iterator grows the destination as values arrive.

Read more →

November 9, 2026