On 08/20/2010 05:47 PM, SHOO wrote:
(2010/08/21 5:04), Andrei Alexandrescu wrote:
I think the code is ready for prime time, modulo the issues below. What
do you all think?
Overall this is a good example of modern, idiomatic D code. Everything
is clear, simple, and in the right place. Congratulations, Shoo!
*******
Line 80: You could an assert or even an enforce here for TICKSPERSPEC.
A program does not work at all when a function failed in a module
constructor. I'll set 0 for TICKSPERSEC when a function failed.
And, had better I make TICKSPERSEC -> TicksPerSec?
ticksPerSec :o)
> Line 737: I'm afraid you can't put @trusted here because you don't know
> the safety level of BaseFunc and TargetFunc. You'll need to use @system.
>
This is a source of worry very much.
I hit on the idea that manage to do:
private @safe void dummySafeFunc(alias FN)()
{
FN();
}
template isSafe(alias FN)
{
enum isSafe = is(typeof({dummySafeFunc!(FN)();}()));
}
@safe
ComparingBenchmarkReturnValue comparingBenchmark(
alias baseFunc, alias targetFunc, int CNT = 0xfff)()
if (isSafe!baseFunc && isSafe!targetFunc)
{
....
}
I think that's a very good idea. In the long term we'll need to have
some traits (either compiler-provided or deduced as above) and put them
in std.traits.
@system
ComparingBenchmarkReturnValue comparingBenchmark(
alias baseFunc, alias targetFunc, int CNT = 0xfff)()
if (!(isSafe!baseFunc && isSafe!targetFunc))
{
....
}
It is dirty slightly...
May I put isSafe in std.traits?
Yes please.
Line 762: Beautiful idiom!
Thanks! But, I want to write like this:
with (measureTime!((a){assert(a.seconds);}))
{
doSomething();
}
I don't want to name a nonuse variable.
In this usage, I think that With is proper.
But, this doesn't call destructor. (for bug 3516?
Though I think that how to use is free.
It's definitely a bug. But note that in C++ an unused value will be
destroyed at the end of expression, which makes sense. That means your
idiom would need a named variable.
Andrei
_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos