GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - DoctorLai/cpp-coding-exercise: C++ Coding Exercise

BranchesTags
Open more actions menu

Latest commit

 

History

100 Commits
100 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
fold-left-fold-right
fold-left-fold-right
 
 
integer-factorization
integer-factorization
 
 
map-with-unknown-key
map-with-unknown-key
 
 
multithread-sum
multithread-sum
 
 
oop-with-exception
oop-with-exception
 
 
parallel-integral-pi
parallel-integral-pi
 
 
parallel-transform
parallel-transform
 
 
pi-monte-carlo
pi-monte-carlo
 
 
pi
pi
 
 
prefix-sum
prefix-sum
 
 
ranges-find-in-vector-string
ranges-find-in-vector-string
 
 
rot47
rot47
 
 
smart-ptr
smart-ptr
 
 
sudoku-solver
sudoku-solver
 
 
thread-safe-queue
thread-safe-queue
 
 
unique-ptr-basics
unique-ptr-basics
 
 
views-zip-enumerate
views-zip-enumerate
 
 
virtual-interface
virtual-interface
 
 
.clang-format
.clang-format
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
PRIVACY.md
PRIVACY.md
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
SUPPORT.md
SUPPORT.md
 
 
clang-check.sh
clang-check.sh
 
 
common.mk
common.mk
 
 

Repository files navigation

cpp-coding-exercise

C++ Build Last Commit License Stars Code Style Commit Activity Watchers PRs Welcome Repo Size Top Language Open PRs Forks Open Issues Ask DeepWiki

A collection of modern C++ coding examples and small exercises focused on correctness, clarity, and real-world patterns.

This repository is intended as:

  • An interview-preparation playground
  • A reference for concurrency, synchronization, low-level, and modern C++ techniques
  • A growing set of self-contained, buildable examples
  • A collection of practical examples and CLI tools rather than puzzle-only solutions

Current examples include:

  • Multithreading
    • thread-safe-queue
    • multithread-sum
  • Smart pointers
    • unique-ptr-basics
    • smart-ptr
  • Views
    • views-zip-enumerate
  • Folding
    • fold-left-fold-right
  • Parallelism
    • parallel-transform
    • parallel-integral-pi
  • STL and ranges:
    • ranges-find-in-vector-string
  • Algorithms
    • integer-factorization
    • Encoding
      • rot47
    • prefix-sum
    • sudoku-solver
    • pi-monte-carlo
    • pi
  • Data Structures
    • map-with-unknown-key
  • OOP
    • virtual-interface
    • oop-with-exception

Repository Structure

cpp-coding-exercise/
├── Makefile              # top-level dispatcher
├── common.mk             # shared compiler flags
├── <example>/
│   ├── Makefile
│   ├── main.cpp
│   └── tests.sh           # optional behavior tests
└── .github/workflows/
    ├── ci.yml             # builds, sanitizers, tests, and coverage
    └── coverage-comment.yml

Design principles

  • Each example is self-contained
  • Each folder has its own Makefile
  • The top-level Makefile automatically discovers and builds all examples
  • No central list to maintain when adding new folders

Prerequisites

sudo apt update
sudo apt install g++-14 make clang-format gcovr jq libtbb-dev

The examples target C++23 and are tested on Ubuntu with GCC 14.

Building

Build everything

make

This will recursively build every directory that contains a Makefile.

Build a single example

cd thread-safe-queue
make

Running examples

Runnable examples expose a run target:

make run

Top-level make run runs all built targets and each available tests.sh script.

Project commands

make build             # Build every example with the selected sanitizer
make test              # Build as needed, run examples, and execute test scripts
make format            # Format all C and C++ source files
make lint              # Check formatting without modifying files
make coverage          # Generate HTML, XML, JSON, and text coverage reports
make check             # Run formatting and supported sanitizer builds/tests
make clean             # Remove binaries, objects, and coverage artifacts

make coverage enforces at least 80% line coverage, 80% function coverage, and 70% branch coverage by default. Override local thresholds with COVERAGE_MIN, COVERAGE_FUNCTION_MIN, and COVERAGE_BRANCH_MIN.


Cleaning

Clean everything:

make clean

Or clean a single example:

cd thread-safe-queue
make clean

Shared build configuration

Common compiler settings live in common.mk:

CXX      := g++-14
CXXFLAGS := -std=c++23 -Wall -Wextra -Werror

Individual examples may extend this, e.g.:

CXXFLAGS += -pthread

Sanitizers

AddressSanitizer is enabled by default to detect memory safety problems and leaks.

# Builds with AddressSanitizer automatically
make

# ThreadSanitizer
make SANITIZE=thread

# UndefinedBehaviorSanitizer
make SANITIZE=undefined

# Select the sanitizer matrix used by make check
make check SANITIZERS="address thread undefined"

# No sanitizers
make SANITIZE=

GCC ThreadSanitizer cannot reliably reserve its shadow-memory layout under WSL2 and may terminate before an example starts with FATAL: ThreadSanitizer: unexpected memory mapping. On WSL2, make check therefore runs ASan and UBSan by default. Native Linux runs ASan, TSan, and UBSan. SANITIZERS can override either default.

The parallel-transform example uses libstdc++'s parallel STL backend, which delegates to oneTBB. TSan requires oneTBB itself to be sanitizer-aware so that its internal synchronization is visible. The dedicated CI TSan job therefore builds the pinned oneTBB release with TBB_SANITIZE=thread instead of using Ubuntu's ordinary runtime library.


Clang Format

clang-format enforces the repository's C++ style.

make format            # Apply formatting
make lint              # Check all example directories
./clang-check.sh       # Equivalent recursive standalone check

Each example also exposes make check-format from its own directory.


Continuous Integration

GitHub Actions builds all examples on:

  • Pushes to main
  • Pull requests targeting main

The CI setup requires no updates when new example folders are added.

CI runs ASan and UBSan in one job and TSan with a sanitizer-aware oneTBB build in another. It also enforces the documented coverage floors, uploads an HTML coverage report, and posts a coverage summary on pull requests. Each sanitizer configuration starts from a clean build so compiler flags cannot be silently reused from a previous configuration.


Toolchain

  • C++23
  • GNU Make
  • GCC 14
  • clang-format
  • gcovr
  • Linux (Ubuntu)

Goals (non-goals)

  • ✔ Correctness over cleverness

  • ✔ Explicit concurrency semantics

  • ✔ Minimal dependencies

  • ✘ No frameworks

  • ✘ No large abstractions

  • ✘ No header‑only meta‑programming for its own sake


Contributing and support

See CONTRIBUTING.md before submitting a change. For help, use the channels in SUPPORT.md. Report security concerns privately as described in SECURITY.md.

Project changes are recorded in CHANGELOG.md, and the repository's data practices are documented in PRIVACY.md.

License

MIT (unless otherwise stated in a specific example).


Notes

Many examples intentionally focus on edge cases and failure modes such as data races, lifetime issues, and ordering bugs. They are meant to be read, built, and experimented with.

Contributions and discussions are welcome.

About

C++ Coding Exercise

Topics

coding-examplescpluspluscplusplus-20cplusplus-23cpp

Resources

Readme
MIT license

Contributing

Contributing

Security policy

Security policy
Activity

Stars

3 stars

Watchers

0 watching

Forks

3 forks
Report repository

Releases

Sponsor this project

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.