CPP Examples
Aligned plain-text table for terminal output
Renders rows as a padded plain-text table with computed column widths and a dashed header rule.
Base64 encode and validating decode
Base64-encodes bytes and decodes text while rejecting bad lengths and characters outside the alphabet.
Field-level input validation error collector
Validates fields independently and returns every error message keyed by field name instead of one.
JSON parse errors with byte offsets
Wraps nlohmann::json parse failures in an exception that reports the byte offset and reason.
Percent-encode and parse URL query pairs
Percent-encodes values and splits an &-separated query string into a key/value map.
Fixed thread pool collecting results and errors
Runs tasks across a fixed number of threads and returns each result or exception message by index.
HTTP GET JSON with libcurl timeout
Fetches a URL with libcurl under a hard timeout, then parses the body with nlohmann/json.
Environment config reader with typed validation
Reads environment variables with typed defaults and throws naming the variable when a value is bad.
Token bucket limiter with burst capacity
Limits work to an average rate per second while allowing a configurable burst from the bucket.
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.
Stable sort with optional scores last
Stable-sorts records by optional score descending and name, placing records without a score last.
Chunk a std::vector into fixed-size batches
Splits a vector into consecutive vectors of at most n elements, keeping the final shorter batch.
Deep clone and recursive merge for owned trees
Deep-copies a tree of unique_ptr children, then merges another tree recursively with override wins.
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.
C++ retry helper with capped backoff
Retries a callable with capped exponential backoff and random jitter so transient failures can recover.