digitalmars.D - Feature Request: make void a value type
- downs (11/11) Dec 03 2007 Proposal: to allow us to treat void as a value type.
- Matti Niemenmaa (5/9) Dec 03 2007 I've been wanting this for a while and I'd love to see it happen.
- downs (3/14) Dec 03 2007 Yay! :D
- Jarrett Billingsley (13/17) Dec 03 2007 This is already possible. Return statements with expressions in functio...
- downs (4/14) Dec 03 2007 [snip example]
- Jarrett Billingsley (16/32) Dec 03 2007 You need to try things!
- downs (4/25) Dec 03 2007 OMGSQUEE!!!!!
- Oskar Linde (4/11) Dec 03 2007 It was added in D 0.91 in 2004.
- Christopher Wright (7/21) Dec 03 2007 I did have completely separate ways of proxying void methods versus
- downs (4/11) Dec 03 2007 .init is broken in interesting ways for several cases (ever tried typeof...
- Jarrett Billingsley (5/17) Dec 03 2007 That's not actually broken -- the init of a fixed array is the init of i...
Proposal: to allow us to treat void as a value type. What this would allow: * simplifying templates that differ between return type, i.e. static if (is(ReturnType!(C)==void)) param(); else return param(); I write code like that all the time :( * Allowing sets, i.e. void[int] .. this is something many newcomers intuitively expect to work; and by rights, it should. Problems: * With void.sizeof being 0, void is the only type where an array has completely different properties than the original type. I'm not sure whether this really is a problem. Code this breaks: * None that I can see; it only seems to affect situations that would be illegal under the current spec. What do you think? --downs
Dec 03 2007
downs wrote:Problems: * With void.sizeof being 0, void is the only type where an array has completely different properties than the original type. I'm not sure whether this really is a problem.void.sizeof is 1, so there's even less of a problem than you think.What do you think?I've been wanting this for a while and I'd love to see it happen. -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Dec 03 2007
Matti Niemenmaa wrote:downs wrote:Okay, but the thing is, I wouldn't want a void variable or parameter or AA entry to take up any space at all. So void.sizeof probably would have to be zero for this to be consistent. Not sure.Problems: * With void.sizeof being 0, void is the only type where an array has completely different properties than the original type. I'm not sure whether this really is a problem.void.sizeof is 1, so there's even less of a problem than you think.Yay! :DWhat do you think?I've been wanting this for a while and I'd love to see it happen.
Dec 03 2007
"downs" <default_357-line yahoo.de> wrote in message news:fj1cc2$13c3$1 digitalmars.com...Proposal: to allow us to treat void as a value type. What this would allow: * simplifying templates that differ between return type, i.e. static if (is(ReturnType!(C)==void)) param(); else return param();This is already possible. Return statements with expressions in functions that return void will be evaluated and their results thrown away. void foo() { return writefln("hi!"); } is the same as: void foo() { { writefln("hi!"); return; } }
Dec 03 2007
Jarrett Billingsley wrote:"downs" <default_357-line yahoo.de> wrote in message news:fj1cc2$13c3$1 digitalmars.com...[snip example] Yes, but what I want is actually being able to _return an expression that *evaluates to void*_. Not the same. --downsProposal: to allow us to treat void as a value type. What this would allow: * simplifying templates that differ between return type, i.e. static if (is(ReturnType!(C)==void)) param(); else return param();This is already possible. Return statements with expressions in functions that return void will be evaluated and their results thrown away.
Dec 03 2007
"downs" <default_357-line yahoo.de> wrote in message news:fj1das$150r$1 digitalmars.com...Jarrett Billingsley wrote:You need to try things! void f() { writefln("f!"); } void g() { return f(); } void main() { g(); } Works just fine."downs" <default_357-line yahoo.de> wrote in message news:fj1cc2$13c3$1 digitalmars.com...[snip example] Yes, but what I want is actually being able to _return an expression that *evaluates to void*_. Not the same. --downsProposal: to allow us to treat void as a value type. What this would allow: * simplifying templates that differ between return type, i.e. static if (is(ReturnType!(C)==void)) param(); else return param();This is already possible. Return statements with expressions in functions that return void will be evaluated and their results thrown away.
Dec 03 2007
Jarrett Billingsley wrote:You need to try things! void f() { writefln("f!"); } void g() { return f(); } void main() { g(); } Works just fine.OMGSQUEE!!!!! Thanks! I think this used to not work at some point and then got fixed or so but anyway it works! HAPPIES!! --happydowns
Dec 03 2007
downs wrote:Jarrett Billingsley wrote:You need to try things!void g() { return f(); }Thanks! I think this used to not work at some point and then got fixed or so but anyway it works! HAPPIES!!It was added in D 0.91 in 2004. -- Oskar
Dec 03 2007
downs wrote:Proposal: to allow us to treat void as a value type. What this would allow: * simplifying templates that differ between return type, i.e. static if (is(ReturnType!(C)==void)) param(); else return param(); I write code like that all the time :( * Allowing sets, i.e. void[int] .. this is something many newcomers intuitively expect to work; and by rights, it should. Problems: * With void.sizeof being 0, void is the only type where an array has completely different properties than the original type. I'm not sure whether this really is a problem. Code this breaks: * None that I can see; it only seems to affect situations that would be illegal under the current spec. What do you think? --downsI did have completely separate ways of proxying void methods versus returning methods, and it was a mess. Ugliness to the core. Right now, I'm replacing it with static ifs, which is bulky and ugly, but it avoids rampant code duplication. Your suggestion would simplify my code even more. I could eliminate almost all the static ifs, as long as void.init worked.
Dec 03 2007
Christopher Wright wrote:I did have completely separate ways of proxying void methods versus returning methods, and it was a mess. Ugliness to the core. Right now, I'm replacing it with static ifs, which is bulky and ugly, but it avoids rampant code duplication. Your suggestion would simplify my code even more. I could eliminate almost all the static ifs, as long as void.init worked..init is broken in interesting ways for several cases (ever tried typeof((int[4]).init)?) Try template Init(T) { T Init; } instead. :) --downs
Dec 03 2007
"downs" <default_357-line yahoo.de> wrote in message news:fj1j9d$1elr$1 digitalmars.com...Christopher Wright wrote:That's not actually broken -- the init of a fixed array is the init of its element types. std.traits actually uses this bizarre inconsistency to determine isStaticArray.I did have completely separate ways of proxying void methods versus returning methods, and it was a mess. Ugliness to the core. Right now, I'm replacing it with static ifs, which is bulky and ugly, but it avoids rampant code duplication. Your suggestion would simplify my code even more. I could eliminate almost all the static ifs, as long as void.init worked..init is broken in interesting ways for several cases (ever tried typeof((int[4]).init)?) Try template Init(T) { T Init; } instead. :) --downs
Dec 03 2007