fun with tuples/argument conversion function
Daniel Keep
daniel.keep.lists at gmail.com
Fri May 11 20:51:23 PDT 2007
Robert Fraser wrote:
> Heh; nice thinking there! Thanks!
>
> BCS Wrote:
>> alternate between inType and outType
>>
>> void dTypesToJavaTypes(everything...)(everything stuff)
>> {
>> foreach(i, thing, stuff)
>> {
>> static if(i & 0x01 == 0)
>> {
>> use stuff[i] and stuff[i+1]
>> }
>> }
>> }
>>
>>
>> nested templates:
>> template dTypes(InType...)
>> {
>> void ToJavaTypes(OutType...)(InTypes..., OutTypes...)(InTypes inVars,
>> out OutTypes outVars)
>> {
>>
>> }
>> }
>>
>> dTypes!(int).ToJavaTypes!(Jint)(i, ji);
>>
>>
>
The only other way I can think of doing it would be to make a template
that, given the D type expands to the JNI type. So...
template jniType(T)
{
static if( is( T == char[] ) )
alias javaString jniType;
else // ...
}
Then you need a template to apply this to a tuple...
template jniTypes(T, Ts...)
{
alias Tuple!(jniType!(T), jniTypes!(Ts)) jniTypes;
}
And now you can do this:
void dTypesToJavaTypes(InTypes...)(InTypes inVars,
out jniTypes!(InTypes) outVars)
{
// Do stuff
}
It's messy, but the nice thing is that it makes your templates easier to
use.
That said, if you can get away with it, I'd go with BCS' approach. :)
-- Daniel
--
int getRandomNumber()
{
return 4; // chosen by fair dice roll.
// guaranteed to be random.
}
http://xkcd.com/
v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
More information about the Digitalmars-d-learn
mailing list