digitalmars.D - Variadic function arguments and build in variant type
- aarti_pl (33/33) Jan 10 2006 Hello!
- Chris Sauls (19/62) Jan 11 2006 You can already use std.boxer to achieve this -- although if I remember ...
- a.c.edwards (4/53) Jan 11 2006 std.boxer doesn't seem to be built into phobos. Need to do the following
Hello! I am new here and at the beginning I would like to say thanks to all for D language. I hope it will gain in popularity because it is really great! I would like to ask if there are consideration to make build in variant type. In such a case there could be much more cleaner solution to send variadic arguments to functions. Instead of using: --------- void foo(int x, ...) { printf("%d arguments\n", _arguments.length); for (int i = 0; i < _arguments.length; i++) { _arguments[i].print(); if (_arguments[i] == typeid(int)) ... --------- you could just write: --------- void foo(variant[] arg ...) { printf("%d arguments\n", arg.length); for (int i = 0; i < arg.length; i++) { if (arg[i].type == int) // I am not sure of this how should it //be expressed in D ... --------- I think this solution is much more consistent and simpler to use. What's more it gives extra bonus of having built in variant type, which is not so easy to implement in such a languages as C++. What do you think? Best Regards Aarti
Jan 10 2006
aarti_pl wrote:Hello! I am new here and at the beginning I would like to say thanks to all for D language. I hope it will gain in popularity because it is really great! I would like to ask if there are consideration to make build in variant type. In such a case there could be much more cleaner solution to send variadic arguments to functions. Instead of using: --------- void foo(int x, ...) { printf("%d arguments\n", _arguments.length); for (int i = 0; i < _arguments.length; i++) { _arguments[i].print(); if (_arguments[i] == typeid(int)) .... --------- you could just write: --------- void foo(variant[] arg ...) { printf("%d arguments\n", arg.length); for (int i = 0; i < arg.length; i++) { if (arg[i].type == int) // I am not sure of this how should it //be expressed in D .... --------- I think this solution is much more consistent and simpler to use. What's more it gives extra bonus of having built in variant type, which is not so easy to implement in such a languages as C++. What do you think? Best Regards AartiYou can already use std.boxer to achieve this -- although if I remember right its still fairly far from perfect. Perhaps these just needs more vocal attention? -- Chris Sauls
Jan 11 2006
In article <dq2nqb$1533$1 digitaldaemon.com>, Chris Sauls says...aarti_pl wrote:std.boxer doesn't seem to be built into phobos. Need to do the following to compile for DMD v0.141, v0.142, and v0.143Hello! I am new here and at the beginning I would like to say thanks to all for D language. I hope it will gain in popularity because it is really great! I would like to ask if there are consideration to make build in variant type. In such a case there could be much more cleaner solution to send variadic arguments to functions. Instead of using: --------- void foo(int x, ...) { printf("%d arguments\n", _arguments.length); for (int i = 0; i < _arguments.length; i++) { _arguments[i].print(); if (_arguments[i] == typeid(int)) .... --------- you could just write: --------- void foo(variant[] arg ...) { printf("%d arguments\n", arg.length); for (int i = 0; i < arg.length; i++) { if (arg[i].type == int) // I am not sure of this how should it //be expressed in D .... --------- I think this solution is much more consistent and simpler to use. What's more it gives extra bonus of having built in variant type, which is not so easy to implement in such a languages as C++. What do you think? Best Regards AartiYou can already use std.boxer to achieve this -- although if I remember right its still fairly far from perfect. Perhaps these just needs more vocal attention?-- Chris Sauls
Jan 11 2006