Add ReturnType to phobos.sys.traits. #10907
Merged
+207
−0
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.
This is essentially the same as the one in std.traits except that it only works on types.
It wouldn't surprise me if some folks end up complaining that it requires a type, but it avoids the whole typeof expression vs typeof symbol issue that way. And really, in most situations, if the function can be used as a getter property, then using PropertyType is a better solution anyway (since then it works with variables as well), and if the function cannot be used as a getter property, then getting the type of the actual function call is often a better solution (since that automatically selects the correct overload). But there are still some situations where ReturnType is desirable, and if nothing else, it provides a good place to document what the better alternatives are and why they're better.
As a bonus, the fact that ReturnType only works on types simplifies its implementation.
functionAttributes is mentioned in the documentation for ReturnType, since it's relevant for functions which return by ref, but it's not part of these changes.