CPP Examples

C++Oct 23, 2026

Aligned plain-text table for terminal output

Renders rows as a padded plain-text table with computed column widths and a dashed header rule.

formattingtablecli
000
C++Oct 23, 2026

Base64 encode and validating decode

Base64-encodes bytes and decodes text while rejecting bad lengths and characters outside the alphabet.

decodingencodingbase64
000
C++Oct 23, 2026

Field-level input validation error collector

Validates fields independently and returns every error message keyed by field name instead of one.

fieldserrorsvalidation
000
C++Oct 23, 2026

JSON parse errors with byte offsets

Wraps nlohmann::json parse failures in an exception that reports the byte offset and reason.

parsingerrorsjson
000
C++Oct 23, 2026

Percent-encode and parse URL query pairs

Percent-encodes values and splits an &-separated query string into a key/value map.

query-stringurlencoding
000
C++Oct 23, 2026

Fixed thread pool collecting results and errors

Runs tasks across a fixed number of threads and returns each result or exception message by index.

concurrencyworker-poolthreads
000
C++Oct 23, 2026

HTTP GET JSON with libcurl timeout

Fetches a URL with libcurl under a hard timeout, then parses the body with nlohmann/json.

curlhttpjsontimeout
000
C++Oct 23, 2026

Environment config reader with typed validation

Reads environment variables with typed defaults and throws naming the variable when a value is bad.

configenvvalidation
000
C++Oct 23, 2026

Token bucket limiter with burst capacity

Limits work to an average rate per second while allowing a configurable burst from the bucket.

token-bucketrate-limitthrottle
000
C++Oct 23, 2026

Bounded LRU cache on std::list plus hash map

Caches int values by key with O(1) get/put and evicts the least recently used entry at capacity.

evictionlrucache
000
C++Oct 23, 2026

Stable sort with optional scores last

Stable-sorts records by optional score descending and name, placing records without a score last.

optionalstablesortcomparator
000
C++Oct 23, 2026

Chunk a std::vector into fixed-size batches

Splits a vector into consecutive vectors of at most n elements, keeping the final shorter batch.

chunkvectorbatch
000
C++Oct 23, 2026

Deep clone and recursive merge for owned trees

Deep-copies a tree of unique_ptr children, then merges another tree recursively with override wins.

unique-ptrmergerecursionclone
000
C++Oct 23, 2026

Stream a file line by line with std::getline

Opens a text file with RAII, passes each line to a callback, and trims trailing carriage returns.

getlinestreamingfile-io
000
C++Oct 23, 2026

C++ retry helper with capped backoff

Retries a callable with capped exponential backoff and random jitter so transient failures can recover.

sleepbackoffretryjitter
000