Skip to content

feature, add standalone examples directory #39

Description

@steven-varga

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:

  • examples/ directory exists with the four example programs listed above.
  • cmake -Dlibdecimal_BUILD_EXAMPLES=ON ... && cmake --build ... compiles all examples.
  • Each example runs successfully and prints clear output.
  • Default build (libdecimal_BUILD_EXAMPLES=OFF) does not build examples.
  • Examples use the same coding style as the rest of the project (C++23, project naming conventions).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions