Skip to content

feat: Add stream insertion operator and unit symbols for various quan…#1

Merged
VPRamon merged 5 commits intomainfrom
impl-cout
Feb 23, 2026
Merged

feat: Add stream insertion operator and unit symbols for various quan…#1
VPRamon merged 5 commits intomainfrom
impl-cout

Conversation

@VPRamon
Copy link
Member

@VPRamon VPRamon commented Feb 23, 2026

This pull request introduces a streamlined and user-friendly way to print quantities with their unit symbols, making output more readable and intuitive. The core changes revolve around adding a stream insertion (operator<<) for quantities and ensuring every unit type provides a symbol for display. The demo and code generation are updated to leverage this new feature.

Key changes include:

Printing and Display Enhancements

  • Added a generic operator<< for Quantity types in ffi_core.hpp, allowing quantities to be printed directly with their unit symbols (e.g., 1500 m, 42.5 km). This significantly simplifies and improves output formatting.
  • Updated the demo (demo.cpp) to use the new operator<< for all quantity outputs, replacing manual .value() and string concatenations. [1] [2]

Unit Trait Improvements

  • Added a static symbol() method to all UnitTraits specializations for angular, length, and mass units, providing a string representation for each unit (e.g., "m", "kg", "°"). [1] [2] [3]

Code Generation

  • Updated code generation in gen_cpp_units.py to automatically emit the symbol() method for each unit trait, ensuring consistency and reducing manual errors.

Core Library Includes

  • Added necessary includes (<iostream>, <string_view>) in ffi_core.hpp to support the new stream insertion and symbol functionality.…tities

@VPRamon VPRamon self-assigned this Feb 23, 2026
@VPRamon VPRamon merged commit b2e7b08 into main Feb 23, 2026
3 checks passed
@VPRamon VPRamon deleted the impl-cout branch February 23, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant