This is a clone of the Unix command line tool wc. See https://codingchallenges.fyi/challenges/challenge-wc/
I Tried to use Modern c++ with C++23 features, like
- std::expected for error handling
- ranges and views to iterate over input stream in one pass
- std::variant for the different counting options
For the part of locale I tried using https://en.cppreference.com/w/c/string/multibyte/mbrtowc, but I could not make it work like wc -m; it gave a different count; so I had to ask chatgpt for help; so CharCounter implementation credit goes to chatgpt.
- CMake 3.20 or newer (presets are used to drive the build)
- A C++23-capable compiler (tested with GCC 13+)
- Ninja or another CMake-supported generator (the presets default to Ninja)
# Generate the debug build tree (only needed once or after changing presets)
cmake --preset debug
# Compile the project (incremental by default)
cmake --build --preset debugFor an optimized binary, switch the preset to release in both commands.
cmake --build --preset debug # ensure the tests are up to date
ctest --preset debug --output-on-failure # run the suite with verbose failurescmake --preset release
cmake --build --preset release # builds ccwc_bench (downloads Google Benchmark the first time)
build/release/ccwc_bench --benchmark_min_time=100msAdjust the --benchmark_min_time value to stabilize results on your machine.