D - static_cast
- Vathix (25/25) Aug 10 2003 It might be good to have a static_cast for classes when you know the cas...
- Matthew Wilson (7/32) Aug 10 2003 I have no opinion on the merits of this, but I would say that the last t...
- Ilya Minkov (9/13) Aug 11 2003 When parsing from left to right per recursive descend, it predicts
- Mike Wynn (15/19) Aug 11 2003 thing
It might be good to have a static_cast for classes when you know the cast is valid. It could still make sure in debug mode and assert it. class Foo { protected Foo[] foos; } class Bar: Foo { void addBar(Bar bar) { foos.length = foos.length + 1; foos[foos.length - 1] = bar; } void something() { uint i; for(i = 0; i != foos.length; i++) { /* I know all these foos are (at the) Bar */ (static_cast(Bar)foos[i]).something(); } } }
Aug 10 2003
I have no opinion on the merits of this, but I would say that the last thing D needs is another place for round brackets. Talk about hard to parse! (I'm talking about code inspectors here, I have no expertise in compiler writing) There's a reason C++ uses cast_name<type> "Vathix" <vathix dprogramming.com> wrote in message news:bh7bc2$6j0$1 digitaldaemon.com...It might be good to have a static_cast for classes when you know the castisvalid. It could still make sure in debug mode and assert it. class Foo { protected Foo[] foos; } class Bar: Foo { void addBar(Bar bar) { foos.length = foos.length + 1; foos[foos.length - 1] = bar; } void something() { uint i; for(i = 0; i != foos.length; i++) { /* I know all these foos are (at the) Bar */ (static_cast(Bar)foos[i]).something(); } } }
Aug 10 2003
Matthew Wilson wrote:I have no opinion on the merits of this, but I would say that the last thing D needs is another place for round brackets. Talk about hard to parse! (I'm talking about code inspectors here, I have no expertise in compiler writing)When parsing from left to right per recursive descend, it predicts perfectly well - the first token tells you what comes next. At least, not at all worse than the current cast syntax. And both do *much* better than C-like cast, which i'd prefer to see deprecated. As to the merit of this, i don't think there is much sense. I can imagine utility for that in a language without templates.There's a reason C++ uses cast_name<type>This form doesn't make it any better. -i.
Aug 11 2003
"Matthew Wilson" <matthew stlsoft.org> wrote in message news:bh7cqv$7v3$2 digitaldaemon.com...I have no opinion on the merits of this, but I would say that the lastthingD needs is another place for round brackets. Talk about hard to parse!(I'mtalking about code inspectors here, I have no expertise in compilerwriting)(static_cast(Bar)foos[i]).something();not that I think static_cast is needed, but its no different from cast(type) I think you are confusing the precidence forcing brackets with those used for the cast! D (cast(Bar)foos[i]).something(); C ((Bar)foos[i]).something(); can't remember if D does cast(Bar)foos[i].something(); like C ((Bar)foos[i]).something(); or Java (Bar)(foos[i].something());
Aug 11 2003