digitalmars.D - Makeshift array "literals"
- Chris Sauls (14/14) Jun 22 2005 Until such time as we get /real/ array literals, maybe something like th...
- Vathix (9/24) Jun 22 2005 The dup kills it. Better would be to allow templates to have var args,
- Stewart Gordon (14/31) Jun 22 2005 I did something like this a while back
Until such time as we get /real/ array literals, maybe something like the following ought to be added to Phobos somewhere (object.d?), to at least provide a near equivelant on the function-body level: Too bad functions can't be called to assign to constants and module/class/struct level statics. Maybe a rule could be made, stating its legal so long as only literals and/or defined constants are used as parameters? Thus allowing things like: -- Chris Sauls
Jun 22 2005
On Wed, 22 Jun 2005 08:51:26 -0400, Chris Sauls <ibisbasenji gmail.com> wrote:Until such time as we get /real/ array literals, maybe something like the following ought to be added to Phobos somewhere (object.d?), to at least provide a near equivelant on the function-body level: Too bad functions can't be called to assign to constants and module/class/struct level statics. Maybe a rule could be made, stating its legal so long as only literals and/or defined constants are used as parameters? Thus allowing things like: -- Chris SaulsThe dup kills it. Better would be to allow templates to have var args, template ConstArray(T, T[] ta ...) { const T[] ConstArray = ta; } const char[][] NAMES = ConstArray!(char[], "John", "Paul", "Ringo", "George");
Jun 22 2005
Chris Sauls wrote:Until such time as we get /real/ array literals, maybe something like the following ought to be added to Phobos somewhere (object.d?), to at least provide a near equivelant on the function-body level:I did something like this a while back http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D/12920 but yes, rewriting it to use a typesafe variadic now that we have it is a logical progression.Too bad functions can't be called to assign to constants and module/class/struct level statics. Maybe a rule could be made, stating its legal so long as only literals and/or defined constants are used as parameters?The problem is that functions can have side effects. And so it would be possible to create initialisers that confusingly depend on the order of evaluation.Thus allowing things like:You can already use the static initialiser syntax on such things: const char[][] NAMES = [ "Grant", "Paul", "Bonnie" ]; Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jun 22 2005