-
-
Notifications
You must be signed in to change notification settings - Fork 22.8k
Remove dependency of variant.h
in print_string.h
#107721
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is definitely worth doing.
But instead of std::initializer_list
, it should use Span
, I think. initializer_list
is more meant for actual initialization, so it feels out-of-domain here.
You should also be able to simplify to just one templated function, by using something like this:
Variant variants[sizeof...(args)] = { args... };
__print_line(stringify_variants(Span(variants))
Changed and simplified. There is one more copy for one argument situation, but the overhead should be negiligible (actually I think compiler can optimize this away). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me.
Co-authored-by: Lukas Tenbrink <[email protected]> Co-authored-by: A Thousand Ships <[email protected]>
print_string.h
isn’t the lightweight header its name suggests—concerned only withString
—but a fairly heavy one, because it includesvariant.h
internally. The only place it actually needsVariant
is instringfy_variants()
. I changed that function to a non-template version and moved it intoprint_string.cpp
, so nowprint_string.h
only depends onustring.h
.std::initializer_list
may incur some overhead, but these functions don't seem to be particularly performance-sensitive, so I opted for the most straightforward implementation.