Skip to content

makes most operators hidden friends #471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 23, 2025
Merged

Conversation

cjdb
Copy link
Contributor

@cjdb cjdb commented Apr 30, 2025

This ensures that they're not placed in their function names' respective overload sets, which has a considerable impact on build times and on compiler diagnostics (as they're not listed as failed candidates when overload resolution fails).

cjdb added 5 commits April 30, 2025 19:58
This ensures that they're not placed in their function names' respecitve
overload sets, which has a considerable impact on build times and on
compiler diagnostics (as they're not listed as failed candidates when
overload resolution fails).
Running an include tracer indicated that placing `size_hint_impl.h` in
this header should prevent link-time errors when attempting to
incidentally format `SizeHint`.
@cjdb cjdb force-pushed the hidden-friend-operators branch from c8fe86b to 438c023 Compare May 1, 2025 23:25
Copy link
Collaborator

@danakj danakj left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Comment on lines +64 to +73
/// The `U` template type parameter allows `_sus_format_to_stream` to be a
/// hidden friend when `Type` is not a class template. Directly using `Type`
/// means that the function is immediately instantiated, and we'll get a
/// compile-time error unless `fmt::formatter` is specialised before `Type`'s
/// definition, since `fmt::is_formattable` doesn't know it's a formattable type
/// at this point in the code. This isn't a problem for primary class templates,
/// but it is problematic for regular classes and full specialisations. Using a
/// dependent type `U` defers instantiation until `operator<<` is first used.
/// We need to constrain `U` to be the same type as `Type`, otherwise it will
/// be ambiguous as to which overload we want.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is some wild and wonderful compiler hijacking lol. Thanks for explaining it well.

@danakj danakj merged commit 06ae338 into chromium:main May 23, 2025
10 checks passed
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