Skip to content
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

Remove special casing on primitive types by casting 0 to type. #3

Merged
merged 1 commit into from
Jan 22, 2024

Conversation

airblast-dev
Copy link
Contributor

@airblast-dev airblast-dev commented Jan 22, 2024

This change will allow using more primitive types with the macro by casting 0 to the provided type.

Types that can be casted from a zero include but are not limited to; All numeric types, char, *const T (raw pointer).
Meaning special casing for f32, f64 and char can be removed. Which were added after issue #2.

I have tested compile times in a small application, but noticed very little, to no difference.

One more very small thing this helps in is syntax highlighting in editors, since the macro takes a type rather than a literal type name it displays the correct color for it. See screenshots from the testing file below.

OLD:
image
NEW:
image

@airblast-dev
Copy link
Contributor Author

airblast-dev commented Jan 22, 2024

If using a null pointer (since 0 cast to a raw pointer, points to null) when storing raw pointers seems too dangerous even though it is just a placeholder, another branch could be added to the macro to explicitly disallow that type (by literal input matching), and then by using compile_error! We could give nice and helpful compile error. I don't think this is needed, since it should be impossible to happen, but I think it is worth mentioning.

@rossmacarthur rossmacarthur merged commit ae09191 into rossmacarthur:trunk Jan 22, 2024
3 checks passed
@rossmacarthur
Copy link
Owner

Thanks for the contribution :)

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