Results for “extra”
Small, practical examples. Search by task or narrow things down below.
Swap two integers
Use a temporary value to swap C integers without arithmetic overflow.
C✓ Tested
Test any and all elements with predicates
C++: These algorithms stop as soon as their result is known.
C++✓ Tested
Test whether an unsigned value is a power of two
C: A nonzero power of two has exactly one set bit.
C✓ Tested
Track which union member is currently valid
C: An explicit tag tells callers which overlaid union value to read.
C✓ Tested
Transfer unique ownership with move
C++: Moving a unique_ptr leaves the source empty and gives ownership to the destination.
C++✓ Tested
Transform a vector into a separate result
C++: Pre-size the output before writing through its iterator.
C++✓ Tested
Trim surrounding ASCII whitespace
C++: Find the first and last non-whitespace bytes before taking a substring.
C++✓ Tested
Unpack a tuple with structured bindings
C++: Structured bindings give names to the parts of a returned compound value.
C++✓ Tested
Update a running count
C++: Change a variable after its initial value has been assigned.
C++✓ Tested
Update a running count
C: Change a variable after its initial value has been assigned.
C✓ Tested
Use a fixed-size container with bounds checking
C++: std::array retains its element count and supports checked access through at.
C++✓ Tested
Use a hash map for direct key lookup
C++: unordered_map provides key lookup without promising iteration order.
C++✓ Tested