Add a dedicated examples/ directory with small, standalone, copy-pasteable C++ programs demonstrating each libdecimal representation and common use cases.
Motivation:
The documentation already contains embedded snippets, but there is no examples/ folder with standalone programs that a user can build and run immediately. This is a gap for onboarding and for verifying that find_package(libdecimal) works end-to-end.
Proposed scope:
Create examples/ with one program per representation plus a CMake integration example:
examples/bid_example.cpp — IEEE 754-2008 BID: construction, UDLs, transcendentals, formatting
examples/fixed_example.cpp — compile-time fixed-point: currency-style arithmetic, constexpr, decompose
examples/bcd_example.cpp — BCD: string construction, digit-level access, str()
examples/scaled_example.cpp — scaled integer pair: wire-format style, as_pair(), checksum
examples/CMakeLists.txt — optional target libdecimal_examples built when libdecimal_BUILD_EXAMPLES=ON
Build integration:
Add a top-level option:
option(libdecimal_BUILD_EXAMPLES "Build example programs" OFF)
When ON, add the examples/ subdirectory and build each example linked against libdecimal::libdecimal.
Acceptance criteria:
Add a dedicated
examples/directory with small, standalone, copy-pasteable C++ programs demonstrating each libdecimal representation and common use cases.Motivation:
The documentation already contains embedded snippets, but there is no
examples/folder with standalone programs that a user can build and run immediately. This is a gap for onboarding and for verifying thatfind_package(libdecimal)works end-to-end.Proposed scope:
Create
examples/with one program per representation plus a CMake integration example:examples/bid_example.cpp— IEEE 754-2008 BID: construction, UDLs, transcendentals, formattingexamples/fixed_example.cpp— compile-time fixed-point: currency-style arithmetic,constexpr, decomposeexamples/bcd_example.cpp— BCD: string construction, digit-level access,str()examples/scaled_example.cpp— scaled integer pair: wire-format style,as_pair(), checksumexamples/CMakeLists.txt— optional targetlibdecimal_examplesbuilt whenlibdecimal_BUILD_EXAMPLES=ONBuild integration:
Add a top-level option:
When
ON, add theexamples/subdirectory and build each example linked againstlibdecimal::libdecimal.Acceptance criteria:
examples/directory exists with the four example programs listed above.cmake -Dlibdecimal_BUILD_EXAMPLES=ON ... && cmake --build ...compiles all examples.libdecimal_BUILD_EXAMPLES=OFF) does not build examples.