fun with mixins
Chad J
gamerChad at _spamIsBad_gmail.com
Fri Jan 26 13:47:02 PST 2007
Here's the jist of the attached source:
template doSomething()
{
auto dummy = value = some + expression;
}
uint func( uint some, uint expression )
{
uint value = 52;
mixin doSomething!();
return value;
}
It seems pretty hackish to me, yet useful.
Attached is a really long-winded alpha blending routine. The advantage
is that it's perhaps the most generalized alpha blending routine I've
ever written that is still decently fast (yeah, could be a lot better
with simd, gpu usage, or <insert common optimization that doesn't work
in general on my pda>). It could soon do things totally unrelated to
alpha blending. It seems kinda like something that the C preprocessor
would be used for, though the thought of using C kinda scares me, and I
have hope that D templates/mixins are up to the job. Maybe someday when
I have a lot of time on my hands I can figure out how to make the
templates generate runtime for-loops, complete with custom-tailored
innerloop code, which would make it a lot easier to optimize edge cases
like sourcePixel[i+1] where there may or may not be an i+1'th pixel and
I don't want to afford an 'if'.
I have to wonder, has someone done this stuff already (the mixin trick,
or some sort of graphics routine framework in D)?
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: alphablend.d
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20070126/197b464c/attachment.ksh>
More information about the Digitalmars-d
mailing list