Does dmd have SSE intrinsics?
Daniel Keep
daniel.keep.lists at gmail.com
Tue Sep 22 18:39:24 PDT 2009
Jeremie Pelletier wrote:
> I don't get how void could be used to simplify generic code. You can
> already use type unions and variants for that and if you need a single
> more generic type you can always use void* to point to the data.
You can't take the address of a return value. I'm not even sure you
could define a union type that would function generically without
specialising on void anyway.
And using a Variant is just ridiculous; it's adding runtime overhead
that is completely unnecessary.
> Besides in your above example, suppose the interesting thing its doing
> is to modify the result data, how would the compiler know how to modify
> void? It would just push back the error to the next statement.
Example from actual code:
ReturnType!(Fn) glCheck(alias Fn)(ParameterTypeTuple!(Fn) args)
{
alias ReturnType!(Fn) returnT;
static if( is( returnT == void ) )
Fn(args);
else
auto result = Fn(args);
glCheckError();
static if( !is( returnT == void ) )
return result;
}
This function is used to wrap OpenGL calls so that error checking is
performed automatically. Here's what it would look like if we could use
void variables:
ReturnType!(Fn) glCheck(alias Fn)(ParameterTypeTuple!(Fn) args)
{
auto result = Fn(args);
glCheckError();
return result;
}
I don't CARE about the result. If I did, I wouldn't be allowing voids
at all, or I would be special-casing on it anyway and it wouldn't be an
issue.
The point is that there is NO WAY in a generic function to NOT care what
the return type is. You have to, even if it ultimately doesn't matter.
> Why don't you just replace ReturnType!func by auto and let the compiler
> resolve the return type to void?
Well, there's this thing called "D1". Quite a few people use it.
Especially since D2 isn't finished yet.
More information about the Digitalmars-d
mailing list