The snippet library.
Small, practical examples. Search by task or narrow things down below.
Rename a known file through filesystem
C++: filesystem::rename reports an error by exception when the operation fails.
C++✓ Tested
Repeat a fixed number of times
C++: Use a counted loop to print three numbered steps.
C++✓ Tested
Repeat while a condition holds
C++: Count down while a positive number remains, updating the loop variable on each iteration.
C++✓ Tested
Replace one collection element
C++: Update an existing element at a known valid index.
C++✓ Tested
Replace text using captured regex groups
C++: Numbered replacement groups can rearrange a known two-part name.
C++✓ Tested
Replace the first match
Find and replace one literal substring in C++.
C++✓ Tested
Represent an absent result with optional
C++: value_or supplies a default without requiring a sentinel inside the value domain.
C++✓ Tested
Require two conditions to be true
C++: Combine a lower and an upper bound to check whether a value is in range.
C++✓ Tested
Retrieve the result of an asynchronous task
C++: The explicit async launch policy requests asynchronous execution rather than deferred evaluation.
C++✓ Tested
Reverse a string
Reverse a byte string in place with std::reverse.
C++✓ Tested
Rotate a sequence around a selected position
C++: rotate places the element at the middle iterator first while preserving the two segment orders.
C++✓ Tested
Round halfway floating-point values away from zero
C++: std::round has an explicit halfway rule different from truncation.
C++✓ Tested