-
-
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
Introduce package level lvalueInit
#2172
Conversation
|
For Pete's sake... why isn't this linking... I hate the Darwin release :/ Anybody have any ideas? I'll try to reduce and reproduce tomorrow :( |
| static if (is(T == immutable(T))) | ||
| static lvalueInit = T.init; | ||
| else | ||
| alias lvalueInit = .lvalueInit!(immutable(T)); |
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.
alias? Shouldn't this be static or enum?
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.
The "instance proper" is instanciated inside the immutable(T) template. If T is not immutable, then the template aliases to the immutable version.
I'll try removing the code, just as a test in regards to the link problem, but it should be valid (and necessary to guarantee consistency).
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... that didn't help :/
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.
Shame.. It smells like a compiler bug. Maybe ping Kenji about it.
Reduced and filed: https://issues.dlang.org/show_bug.cgi?id=12754
I'll try pinging both @WalterBright and @9rnsr , though it seems like a Darwin-linker specific issue. |
|
ping |
Not really, and there's nothing I can really do on my end, except ping @WalterBright and/or @9rnsr again. |
|
This is still blocked, but I think I found a |
|
Is this worth it? What's the benefit? |
|
It also avoids either of:
The benefits are not huge, but there's no real downside either (and its internal), so worth it, yes, IMO. It just needs to pass Darwin though... |
|
OK I think this comes up often enough to deserve a place in the stdlib. But let's call it |
| // static lvalueInit = T.init; | ||
| //else | ||
| // alias lvalueInit = .lvalueInit!(immutable(T)); | ||
| static lvalueInit = immutable(T).init; |
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 think it should be an undefined function, a la:
ref T lvalueof(T)();True it can't be applied everywhere but it's a better template constraint that's impossible to misuse (e.g. write to).
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.
If you want something that is only for template constraints, we already have lvalueof in std.traits (http://dlang.org/phobos/std_traits.html#lvalueOf). It has the exact signature you propose (give or take an "inout") workaround.
However, I see this as different concepts, since the idea here is to specifically be able to grab a value. You say "impossible to misuse " but:
lvalueInitis immutable, so can't be written too anyways.- Using a function (I also objected to this with
lvalueof) means operator & has a surprising effect, in that it doesn't give you the address of your lvalue, which, IMO, kind of breaks the intent of the damn thing.
|
@monarchdodra is it still blocked? Are you around to try to continue this? |
Honestly, I'm not sure it was ever blocked. Just no one thought it was important enough to merge. I was planning to use it in future code, but I don't think that's going to happen anymore. Let's just close it. |
|
Can we at least get that as an internal helper? |
In that case it might be best to keep on using the |
This is a library solution for of my original "WONTFIX" request:
"Make const(T).init and immutable(T).init lvalues"
https://issues.dlang.org/show_bug.cgi?id=11307
It is currently used in 3 places, but I have plans to add it to 2 other places too (
initializeAlland amoveOverrequired for emplacing rvalues with disabled postblit).It also fixes a bug where
movecould not be used with elaborate types that have a disabled default initialization.Overall, it's just a little convenience that avoids bloat.