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

Add URL macro to create valid non-optional URLs. #21

Merged
merged 1 commit into from
Mar 15, 2023

Conversation

NikolaiRuhe
Copy link
Contributor

@NikolaiRuhe NikolaiRuhe commented Mar 11, 2023

Add a #URL macro that provides compile time checked URL literals.

Motivation:

This is similar in spirit to compile time checked regular expressions. For a literal Regex the compiler makes sure that the regex has no syntactic errors by parsing it at compile time. In case of a syntax error the compiler emits an error (and does not produce any code).

When the regex parses without error a non-optional, non-throwing initializer is inserted. During runtime the Regex has to be parsed again to create the actual instance but it is known to not throw an error.

This behavior, where the compiler checks the validity of an initializer's arguments would be helpful for many other types, for example a SemVer type that checks for a valid semantic version.

In these cases macros seem like a good workaround (until we get statically checked arguments).

Copy link
Owner

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

Very cool, thank you!

@DougGregor DougGregor merged commit f90db20 into DougGregor:main Mar 15, 2023
@NikolaiRuhe NikolaiRuhe deleted the url-macro branch March 15, 2023 19:39
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.

None yet

2 participants