fun with tuples/argument conversion function

BCS ao at pathlink.com
Fri May 11 13:54:23 PDT 2007


Reply to Robert,

> Hi all,
> 
> Right now I'm trying to write a function that, given an arbitrary
> number of arguments as D types concerts them into intermediate types
> that will be pasrd to the JNI. For example, given a char[], it will
> use the JNI to construct the relevant java.lang.string, and pass back
> the jobject.
> 
> The problem is that I can't define two tuples in the function
> template. For example, I can't write a function:
> 
> void dTypesToJavaTypes(InTypes..., OutTypes...)(InTypes inVars, out
> OutTypes outVars)
> 
> The number of in parameters will always be the same as the number of
> out parameters, and all the types should be known at compile-time, and
> though I'd rather not force the caller to know the out types, there's
> probably no way around that. Any suggestions? Maybe an out tuple and
> in varargs?
> 

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);




More information about the Digitalmars-d-learn mailing list