Support streaming and unit symbols for Eigen - #736
Open
chiphogg wants to merge 3 commits into
Open
Conversation
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
marked this pull request as ready for review
August 22, 2026 02:59
hoffbrinkle
approved these changes
Aug 24, 2026
| // 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{}); |
Member
There was a problem hiding this comment.
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?
Co-authored-by: Michael Hordijk <hordijk@aurora.tech>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 notevery rep necessarily supports unary plus. Therefore, we guard it
behind a utility called as
promote_for_streaming(x, 0), and SFINAE outthe 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 theauthoritative answer. So now we just use that consistently.