Better static assertion on template contraints with 'models'#3677
Better static assertion on template contraints with 'models'#3677atilaneves wants to merge 2 commits intodlang:masterfrom
Conversation
std/traits.d Outdated
There was a problem hiding this comment.
Can you add the Params and Returns sections.
std/traits.d Outdated
There was a problem hiding this comment.
Doesn't this entail massive code bloat as you're importing at least one module per check?
There was a problem hiding this comment.
Only if it was already going to fail to compile, so no.
| @JackStouffer Will do |
Looks cute. Will review later ... |
| It's ugly that in the UDA version you have to repeat the type's name... |
| @schuetzm I agree, but there's nothing I can do about that. |
There was a problem hiding this comment.
Adding in another ddoc-ed unit test in front of this with range type check examples would be helpful as that's the most common use case.
There was a problem hiding this comment.
I'd have to change isInputRange first and I wanted to make the changes orthogonal.
| @JackStouffer That's not possible since |
std/traits.d Outdated
| { | ||
| bool models() | ||
| { | ||
| import std.algorithm; |
There was a problem hiding this comment.
import std.algorithm.searching : countUntil;
| This sounds like something that would be good for a dub release. If it's popular and works then it can be reconsidered for Phobos. |
While I like the idea too, I am inclined to close this as there still seems to be no consensus after one year & going the DUB or DIP road make more sense than getting stalled here? @ others: What do you think? |
This is similar to the work done on this PR, which is now dependent on the current one.
The idea is to have compiler error messages when a type that was intended to satisfy a template constraint but doesn't. Currently, when a template contraint isn't satisfied by accident, it's hard to know why. This PR attempts to make that process easier, with a similar intent as C++ concepts.
Also, I wanted to add a static assert if
modelsis true butcheckXXXdoesn't compile; I didn't because I'd have to move theisFooandcheckFoofunctions used in the accompanying unit tests to global scope.