Skip to content

Support streaming and unit symbols for Eigen - #736

Open
chiphogg wants to merge 3 commits into
mainfrom
chiphogg/eigen-w-unit-symbols
Open

Support streaming and unit symbols for Eigen#736
chiphogg wants to merge 3 commits into
mainfrom
chiphogg/eigen-w-unit-symbols

Conversation

@chiphogg

Copy link
Copy Markdown
Member

I was working on an Eigen example, and found that some basic stuff
people would expect wasn't working yet. So I added tests and fixed it.

On streaming: we've been using the "unary plus" for a long time in order
to promote small integers that alias to char. The problem is that not
every rep necessarily supports unary plus. Therefore, we guard it
behind a utility called as promote_for_streaming(x, 0), and SFINAE out
the unary plus when it doesn't exist.

On unit symbols: apparently, we had been constraining them to arithmetic
types only. Well, we have a canonical trait for what's a valid rep:
IsValidRep. Even if it's not fully fleshed out yet, it's the
authoritative answer. So now we just use that consistently.

I was working on an Eigen example, and found that some basic stuff
people would expect wasn't working yet.  So I added tests and fixed it.

On streaming: we've been using the "unary plus" for a long time in order
to promote small integers that alias to `char`.  The problem is that not
every rep necessarily supports unary plus.  Therefore, we guard it
behind a utility called as `promote_for_streaming(x, 0)`, and SFINAE out
the unary plus when it doesn't exist.

On unit symbols: apparently, we had been constraining them to arithmetic
types only.  Well, we have a canonical trait for what's a valid rep:
`IsValidRep`.  Even if it's not fully fleshed out yet, it's the
authoritative answer.  So now we just use that consistently.
@chiphogg
chiphogg marked this pull request as ready for review August 22, 2026 02:59
@chiphogg
chiphogg requested a review from a team August 22, 2026 03:02
Comment thread au/io.hh
// the operand, which will then match an appropriate << operator that will
// output the integer representation.
out << +q.in(U{}) << " " << unit_label(U{});
out << detail::promote_for_streaming(q.in(U{}), 0) << " " << unit_label(U{});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's part of the detail API, so not critical, but the 0 for the second parameter is not-intuitive.

And really, the only type we're really worried about is the single byte integers which happen to be a char underneath, and char has this unfortunate ambiguity. I suppose there's no good way to select on that?

Comment thread au/quantity.hh Outdated
chiphogg and others added 2 commits August 24, 2026 13:45
Co-authored-by: Michael Hordijk <hordijk@aurora.tech>
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.

2 participants