Bug reports [Was: Re: About Andrei's interview, part 3]
Andrej Mitrovic
andrej.mitrovich at gmail.com
Tue Aug 31 06:35:05 PDT 2010
Wouldn't it be better if we had some kind of compile-time block
statement instead of making separate compile-time keywords for every
run-time keyword?
For example, we could reuse static, and instead of code like this from
std.range:
private template MostDerivedInputRangeImpl(R) {
private alias ElementType!R E;
static if(isRandomAccessRange!R) {
static if(isInfinite!R) {
alias RandomAccessInfinite!E ret;
} else static if(hasAssignableElements!R) {
alias RandomFiniteAssignable!E ret;
} else {
alias RandomAccessFinite!E ret;
}
} else static if(isBidirectionalRange!R) {
static if(hasAssignableElements!R) {
alias BidirectionalAssignable!E ret;
} else {
alias BidirectionalRange!E ret;
}
} else static if(isForwardRange!R) {
static if(hasAssignableElements!R) {
alias ForwardAssignable!E ret;
} else {
alias ForwardRange!E ret;
}
} else {
static if(hasAssignableElements!R) {
alias InputAssignable!E ret;
} else {
alias InputRange!E ret;
}
}
}
We would have this:
private template MostDerivedInputRangeImpl(R) {
private alias ElementType!R E;
static {
if(isRandomAccessRange!R) {
if(isInfinite!R) {
alias RandomAccessInfinite!E ret;
} else if(hasAssignableElements!R) {
alias RandomFiniteAssignable!E ret;
} else {
alias RandomAccessFinite!E ret;
}
} else if(isBidirectionalRange!R) {
if(hasAssignableElements!R) {
alias BidirectionalAssignable!E ret;
} else {
alias BidirectionalRange!E ret;
}
} else if(isForwardRange!R) {
if(hasAssignableElements!R) {
alias ForwardAssignable!E ret;
} else {
alias ForwardRange!E ret;
}
} else {
if(hasAssignableElements!R) {
alias InputAssignable!E ret;
} else {
alias InputRange!E ret;
}
}
}
}
Or maybe use a different name for a compile-time block to not conflict
with static.
On Fri, Aug 27, 2010 at 2:42 AM, bearophile <bearophileHUGS at lycos.com> wrote:
>
> Steps toward a static foreach
> (just the first point is enough for now)
> http://d.puremagic.com/issues/show_bug.cgi?id=4085
More information about the Digitalmars-d
mailing list