www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - tupleof on arrays?

reply Yang Bo <pop.atry gmail.com> writes:
I have some string generate from template, and I need to dump them to
stack and modify it. So I write:

template S(int n) {
  const char[] S = "n = " ~ n;
}
void f() {
  char[S!(123).length] s = [S!(0).tupleof];
  s[0] = 'm';
}

The problem is, there is not a 'tupleof' property on array. Should this
feature be buildin ?
Oct 16 2007
next sibling parent Yang Bo <pop.atry gmail.com> writes:
Yang Bo дµÀ:
 I have some string generate from template, and I need to dump them to
 stack and modify it. So I write:
 
 template S(int n) {
   const char[] S = "n = " ~ n;
 }
 void f() {
   char[S!(123).length] s = [S!(0).tupleof];
   s[0] = 'm';
 }
 
 The problem is, there is not a 'tupleof' property on array. Should this
 feature be buildin ?
I forget the n.stringof, it should be: template S(int n) { const char[] S = "n = " ~ n.stringof; } void f() { char[S!(123).length] s = [S!(0).tupleof]; s[0] = 'm'; }
Oct 16 2007
prev sibling next sibling parent BCS <ao pathlink.com> writes:
Reply to Yang,

 I have some string generate from template, and I need to dump them to
 stack and modify it. So I write:
 
 template S(int n) {
 const char[] S = "n = " ~ n;
 }
 void f() {
 char[S!(123).length] s = [S!(0).tupleof];
 s[0] = 'm';
 }
 The problem is, there is not a 'tupleof' property on array. Should
 this feature be buildin ?
 
no. What would it return? contents of the array? What would it do with a non const? I think you can get the effect you want with a cast ot a slice or maybe both. also somthing along this line should work. template S(int n) { const char[4+n.stringof.length] S = "n = " ~ n.stringof; }
Oct 16 2007
prev sibling parent Reiner Pope <some address.com> writes:
Yang Bo wrote:
 I have some string generate from template, and I need to dump them to
 stack and modify it. So I write:
 
 template S(int n) {
   const char[] S = "n = " ~ n;
 }
 void f() {
   char[S!(123).length] s = [S!(0).tupleof];
   s[0] = 'm';
 }
 
 The problem is, there is not a 'tupleof' property on array. Should this
 feature be buildin ?
What's wrong with simply void f() { char[S!(123).length] s = S!(0); s[0] = 'm'; }
Oct 16 2007