-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Issue 4999 - Add Kenji Hara's adaptTo() to Phobos #1265
Conversation
|
Could you indent predicates so they're like this: template T()
if (...)
{
}It makes it easier to distinguish a template/function definition to a regular |
|
I like the functionality but |
|
My attitude for the indentation of template constraint part is not determined. In past days, I used the same style that you suggested (std.conv and std.format is mostly based on the style). But after a while, I noticed that the style has the problem with complex template constraints. template T()
if (... && ... &&
... && ...) // 8 indentation
{
}If the constraint needs more than one line, the second line needs 8 space indentation. I feel it is "too far" from the left edge. |
Originally that was named |
| ((FA0 ^ FA1) & (FA.ref_ | FA.property)) == 0) | ||
| { | ||
| alias R = Select!(is(R0 : R1), R0, R1); | ||
| alias R FX(P0); |
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.
What does this code do? It looks really weird.
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 makes a function type FX that has a return type R and parameter types P0.
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.
C function type syntax. Eww…
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.
I'm pretty sure that's slated for deprecation, no?
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.
Yeah I think it will be. Seems like alias FX = R function(P0); would do here.
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.
In here, FX should be a function type, not function pointer type. So, alias FX = R function(P0); is not correct.
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.
Couldn't you just use FunctionTypeOf!(R function(P0)) or something like that? I think that would make the code much more readable.
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.
It's good idea. Fixed.
|
Concerning names: How about and extend it to work on structs? Haven't tried it, just based on what David wrote. |
|
I think we need short, memorable, single-word names like |
+1 |
Add structuralCast and structuralDownCast in std.typecons
|
Renamed function names to |
| @@ -2602,6 +2602,623 @@ template generateAssertTrap(C, func.../+[BUG 4217]+/) | |||
| } | |||
|
|
|||
| /** | |||
| * Supports structural based typesafe conversion. | |||
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.
Great. We'd need some links and expanded documentation and examples. (One simple reference would be e.g. http://en.wikipedia.org/wiki/Structural_type_system).
Issue 4999 - Add Kenji Hara's adaptTo() to Phobos
|
This will be a very influential piece of work, thanks @9rnsr, There are quite a few ways in which we can expand on this idea, will flesh them out later. |
|
I'm a little confused about this, since I thought interface Interface
{
int foo();
int bar(int);
}
struct Pluggable // note that it's a struct
{
int opDispatch(string name, A...)(A args) { return 100; }
}
Interface i = wrap!Interface(Pluggable());This currently errors inside of phobos with: If the wrap function is only supposed to be used with objects it should be constrained to disallow non-class types, and it should also be properly documented. |
|
@AndrejMitrovic It's a current implementation limitation which I had not recognized. For |
|
Ok, great to hear. |
http://d.puremagic.com/issues/show_bug.cgi?id=4999
Changes:
structuralCastandstructuralDownCastinstd.typeconsmodulestructuralCastwhich was instd.exception.