Results for “thread”
Small, practical examples. Search by task or narrow things down below.
Find the insertion position for a sorted value
C++: lower_bound returns the first position whose value is not less than the search key.
C++✓ Tested
Find the least common multiple with the standard library
C++: std::lcm combines positive integer periods into a common cycle.
C++✓ Tested
Find what remains after division
C++: Use the remainder operator to count items left after forming complete groups.
C++✓ Tested
Format an integer into a caller-owned buffer
C++: to_chars avoids allocation and reports whether the buffer was large enough.
C++✓ Tested
Group matching values while preserving their order
C++: stable_partition keeps the relative order within both predicate groups.
C++✓ Tested
Handle a failed file open through stream state
C++: An unopened input stream is not an empty successful file read.
C++✓ Tested
Handle a failed string-to-integer conversion
C++: stoi throws invalid_argument when no conversion can be performed.
C++✓ Tested
Handle three possible outcomes
C++: Check high, normal and low values with an ordered conditional chain.
C++✓ Tested
Increment a shared counter safely
C++: Atomic increments prevent lost updates when two threads change the same counter.
C++✓ Tested
Insert a map value only when a key is absent
C++: try_emplace preserves the old value when insertion does not take place.
C++✓ Tested
Inspect a substring without allocating a copy
C++: A string_view refers to existing storage and must not outlive that storage.
C++✓ Tested
Iterate over all regular-expression matches
C++: A regex iterator yields successive matches without manually updating an offset.
C++✓ Tested