template typeing issues

Downs default_357-line at yahoo.de
Sat Sep 15 04:40:05 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

BCS wrote:
> 
> Is there a better way to get T[] and T[5] to play nice in a template?
> 
> void main()
> {
>     char[] c = "world";
>     t("hello", c);
> }
> 
> void t(T, U)(T a, U  b)
> {
>     static assert(is(T : U) || is(U : T));
> }
> 
> my first attempt was this:
> 
> void t(T)(T a, T  b) {
> }
> 
> But it wouldn't instance
> 
> 
Here you go!

$ cat test8.d; echo -----; gdc test8.d -o test8 && ./test8
import std.stdio;
void main() {
  char[] c="world";
  t("hello", c);
}

void t(T)(T[] a, T[] b) {
  writefln(a, " ", b);
}
- -----
hello world

 --downs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG68SVpEPJRr05fBERAoDtAJ9drqNQoWh921jLNcvm43+FSJqMqQCeJIgD
kTn597lWrax0P7x/ZJok42U=
=yje6
-----END PGP SIGNATURE-----


More information about the Digitalmars-d-learn mailing list