digitalmars.D - How to define a const?/static?/final? array.
- Regan Heath (6/6) Jun 09 2004 I want to define an array whose contents cannot be modified. I tried
- J Anderson (6/10) Jun 09 2004 I suggested an approach to this a while ago. Simply wrap the array in a...
- Regan Heath (7/16) Jun 09 2004 Eeeew! This should be simple, not complicated, and it should be intuitiv...
- J Anderson (37/54) Jun 09 2004 //module 1
- Regan Heath (13/70) Jun 09 2004 Thanks for the example. I still think this is just plain wrong. In
- J Anderson (12/21) Jun 09 2004 Oh, I though you where talking about parmeter const.
- Regan Heath (19/39) Jun 09 2004 So the 'const' applies to the array reference and not the data.
- Regan Heath (8/51) Jun 09 2004 Let me revice this, as it's not the D style...
- Matthew (17/58) Jun 09 2004 Mind reader. :-)
- Kris (11/18) Jun 09 2004 It would seem quite reasonable to, as others have noted, use the keyword
- Regan Heath (35/59) Jun 09 2004 I found final in my search for the right keyword, the online docs list i...
- Regan Heath (5/67) Jun 09 2004 my wording here was a bit ambiguous, what I mean is: the data aa points ...
- Matthew (6/26) Jun 09 2004 No, me neither. But I don't want us to have the double qualifier.
-
Kris
(2/5)
Jun 09 2004
Hey; I'd be very happy if the compiler supported that right now
- J Anderson (11/50) Jun 10 2004 Just had a thought...
- Regan Heath (11/67) Jun 10 2004 I never thought of "final" like that.. "final" to me mean "cannot be
- J Anderson (4/74) Jun 10 2004 Sorry, your right.
- Sam McCall (8/25) Jun 13 2004 But your variable isn't the data in the array, it's a (pointer,length)
- Regan Heath (10/35) Jun 13 2004 Yep. That is the problem. I can only specify the array itself is constan...
- Sam McCall (4/11) Jun 13 2004 Wouldn't have a clue, sorry ;-)
I want to define an array whose contents cannot be modified. I tried const, final, static .. I searched the site and didn't find any help, 'final' does not seem to be documented. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 09 2004
Regan Heath wrote:I want to define an array whose contents cannot be modified. I tried const, final, static .. I searched the site and didn't find any help, 'final' does not seem to be documented. ReganI suggested an approach to this a while ago. Simply wrap the array in a struct and use the operators. You can even use a template to save you from having to write the code again. -- -Anderson: http://badmama.com.au/~anderson/
Jun 09 2004
On Thu, 10 Jun 2004 07:19:01 +0800, J Anderson <REMOVEanderson badmama.com.au> wrote:Regan Heath wrote:Eeeew! This should be simple, not complicated, and it should be intuitive. Why can't we have a keyword? Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/I want to define an array whose contents cannot be modified. I tried const, final, static .. I searched the site and didn't find any help, 'final' does not seem to be documented. ReganI suggested an approach to this a while ago. Simply wrap the array in a struct and use the operators. You can even use a template to save you from having to write the code again.
Jun 09 2004
Regan Heath wrote:On Thu, 10 Jun 2004 07:19:01 +0800, J Anderson <REMOVEanderson badmama.com.au> wrote:Because the programmer has to do something <g>.Regan Heath wrote:Eeeew! This should be simple, not complicated, and it should be intuitive. Why can't we have a keyword?I want to define an array whose contents cannot be modified. I tried const, final, static .. I searched the site and didn't find any help, 'final' does not seem to be documented. ReganI suggested an approach to this a while ago. Simply wrap the array in a struct and use the operators. You can even use a template to save you from having to write the code again.Regan//module 1 template constArray(T) //This would be in another module { struct Array { private T [] array; static Array opCall(T [] array) { Array t; t.array = array; return t; } T opIndex(int i) { return array[i]; } int length() { return array.length; } } } Once you have it setup (you only ever need to do that once) it looks like: alias constArray!(int).Array constA; //module 2 void test(constA array) { int x = array[0]; //You just can't change the array variable (well at least not without force). } void main() { int [] a; a ~= 10; a ~= 30; test(constA(a)); //Ok there's a small bit of extra typing -> if D only had automatic boxing.... } -- -Anderson: http://badmama.com.au/~anderson/
Jun 09 2004
On Thu, 10 Jun 2004 07:59:15 +0800, J Anderson <REMOVEanderson badmama.com.au> wrote:Regan Heath wrote:Thanks for the example. I still think this is just plain wrong. In C/C++ it's this simple: const int pp[10] = { 0,1,2,3,4,5,6,7,8,9 }; void main( ) { pp[0] = 5; //error C2166: l-value specifies const object }On Thu, 10 Jun 2004 07:19:01 +0800, J Anderson <REMOVEanderson badmama.com.au> wrote:Because the programmer has to do something <g>.Regan Heath wrote:Eeeew! This should be simple, not complicated, and it should be intuitive. Why can't we have a keyword?I want to define an array whose contents cannot be modified. I tried const, final, static .. I searched the site and didn't find any help, 'final' does not seem to be documented. ReganI suggested an approach to this a while ago. Simply wrap the array in a struct and use the operators. You can even use a template to save you from having to write the code again.-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/Regan//module 1 template constArray(T) //This would be in another module { struct Array { private T [] array; static Array opCall(T [] array) { Array t; t.array = array; return t; } T opIndex(int i) { return array[i]; } int length() { return array.length; } } } Once you have it setup (you only ever need to do that once) it looks like: alias constArray!(int).Array constA; //module 2 void test(constA array) { int x = array[0]; //You just can't change the array variable (well at least not without force). } void main() { int [] a; a ~= 10; a ~= 30; test(constA(a)); //Ok there's a small bit of extra typing -> if D only had automatic boxing.... }
Jun 09 2004
Regan Heath wrote:Thanks for the example. I still think this is just plain wrong. In C/C++ it's this simple: const int pp[10] = { 0,1,2,3,4,5,6,7,8,9 }; void main( ) { pp[0] = 5; //error C2166: l-value specifies const object }Oh, I though you where talking about parmeter const. You can do this: const int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; void main( ) { pp[0] = 5; //This is ok in D } But you can change the values but not the length. So my first suggestion still stands. -- -Anderson: http://badmama.com.au/~anderson/
Jun 09 2004
On Thu, 10 Jun 2004 08:19:41 +0800, J Anderson <REMOVEanderson badmama.com.au> wrote:Regan Heath wrote:So the 'const' applies to the array reference and not the data. Seems we need a new syntax to apply const to the array and/or the data, something like: const int const pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const array I know, I have reversed the current syntax meaning. I think the above is how it should work however. Any other suggestions?Thanks for the example. I still think this is just plain wrong. In C/C++ it's this simple: const int pp[10] = { 0,1,2,3,4,5,6,7,8,9 }; void main( ) { pp[0] = 5; //error C2166: l-value specifies const object }Oh, I though you where talking about parmeter const. You can do this: const int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; void main( ) { pp[0] = 5; //This is ok in D } But you can change the values but not the length.So my first suggestion still stands.It works.. it just seems wrong to be unable to do this with a keyword. Why can't we? I have read the posts about 'const' some people like it, some hate it, we have const for data types, but in the case of arrays (as above) it only applies to the reference, not the data itself. All I want to be able to do is specify some data that cannot be changed. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 09 2004
On Thu, 10 Jun 2004 13:10:31 +1200, Regan Heath <regan netwin.co.nz> wrote:On Thu, 10 Jun 2004 08:19:41 +0800, J Anderson <REMOVEanderson badmama.com.au> wrote:Let me revice this, as it's not the D style... const int[] const pp = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const int[] pp = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int[] const pp = [ 0,1,2,3,4,5,6,7,8,9 ]; // const array I think this syntax makes more sense.Regan Heath wrote:So the 'const' applies to the array reference and not the data. Seems we need a new syntax to apply const to the array and/or the data, something like: const int const pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const arrayThanks for the example. I still think this is just plain wrong. In C/C++ it's this simple: const int pp[10] = { 0,1,2,3,4,5,6,7,8,9 }; void main( ) { pp[0] = 5; //error C2166: l-value specifies const object }Oh, I though you where talking about parmeter const. You can do this: const int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; void main( ) { pp[0] = 5; //This is ok in D } But you can change the values but not the length.I know, I have reversed the current syntax meaning. I think the above is how it should work however. Any other suggestions?-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/So my first suggestion still stands.It works.. it just seems wrong to be unable to do this with a keyword. Why can't we? I have read the posts about 'const' some people like it, some hate it, we have const for data types, but in the case of arrays (as above) it only applies to the reference, not the data itself. All I want to be able to do is specify some data that cannot be changed. Regan
Jun 09 2004
"Regan Heath" <regan netwin.co.nz> wrote in message news:opr9ctjtys5a2sq9 digitalmars.com...On Thu, 10 Jun 2004 08:19:41 +0800, J Anderson <REMOVEanderson badmama.com.au> wrote:Mind reader. :-)Regan Heath wrote:So the 'const' applies to the array reference and not the data. Seems we need a new syntax to apply const to the array and/or the data, something like: const int const pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const arrayThanks for the example. I still think this is just plain wrong. In C/C++ it's this simple: const int pp[10] = { 0,1,2,3,4,5,6,7,8,9 }; void main( ) { pp[0] = 5; //error C2166: l-value specifies const object }Oh, I though you where talking about parmeter const. You can do this: const int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; void main( ) { pp[0] = 5; //This is ok in D } But you can change the values but not the length.I know, I have reversed the current syntax meaning. I think the above is how it should work however. Any other suggestions?AgreedSo my first suggestion still stands.It works.. it just seems wrong to be unable to do this with a keyword.Why can't we? I have read the posts about 'const' some people like it, some hate it, we have const for data types, but in the case of arrays (as above) it only applies to the reference, not the data itself.Most of the debates - about using const (C++-sense) for DbC - are not germane to your requirement. I agree that something const (in the D sense) should be declarable in array form. Is there any need for the second or third of your pp definitions above? Perhaps the language should simply use const with arrays to mean const size + const data. Of course, if someone can offer good reasons against, then a more complex syntax may be required. I'd shy away from the const x const y syntax, if at all possible, however, simply because it's confusing. How about (and it's right off the top of my head, so ...): const(int pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const(int) pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const(pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; // const array ?
Jun 09 2004
"Matthew" wroteOf course, if someone can offer good reasons against, then a more complexsyntaxmay be required. I'd shy away from the const x const y syntax, if at all possible, however, simply because it's confusing. How about (and it's right off the top of my head, so ...): const(int pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const(int) pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const(pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; // const arrayIt would seem quite reasonable to, as others have noted, use the keyword 'final' as a storage class indicator. That is, where you have data that is read-only, immutable, constant (whatever one wishes to call it) the 'final' qualifier would do the "right thing". That includes isolating said data into a separate, potentially ROMable, section. Of course, this doesn't address the related debate regarding read-only function arguments ... Rather than "const const" syntax, what do you think about a "final const" combo instead? Personally, I don't care much for the parenthesized declaration ...
Jun 09 2004
On Wed, 9 Jun 2004 19:05:07 -0700, Kris <someidiot earthlink.dot.dot.dot.net> wrote:"Matthew" wroteI found final in my search for the right keyword, the online docs list it here... http://www.digitalmars.com/d/declaration.html StorageClass: abstract auto const deprecated final override static synchronized But does not describe what it means.Of course, if someone can offer good reasons against, then a more complexsyntaxmay be required. I'd shy away from the const x const y syntax, if at all possible, however, simply because it's confusing. How about (and it's right off the top of my head, so ...): const(int pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const(int) pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const(pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; // const arrayIt would seem quite reasonable to, as others have noted, use the keyword 'final' as a storage class indicator.That is, where you have data that is read-only, immutable, constant (whatever one wishes to call it) the 'final' qualifier would do the "right thing". That includes isolating said data into a separate, potentially ROMable, section.Sounds good. It's exactly what I was looking for.Of course, this doesn't address the related debate regarding read-only function arguments ... Rather than "const const" syntax, what do you think about a "final const" combo instead?Why not just final. I cannot see why you'd want to declare it as final (meaning const data) and not const (meaning the array ref cannot change). Tho, there would still be a distinction between 'final' array data and a 'const' array, see example below... eg. final int[] pp = [ 0,1,2,3,4,5,6,7,9 ]; void main() { int[] aa = [ 1,2,3 ]; int[] bb; pp[0] = 0; //compile error pp = aa; //compile error aa[] = pp[0..3] //ok, aa's data is 'final', but aa is not 'const' aa[0] = 0; //compile error aa = bb; //ok, aa is not const }Personally, I don't care much for the parenthesized declaration ...Too many parenthesis, not good, if we can avoid it, I say lets. Regan. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 09 2004
On Thu, 10 Jun 2004 14:31:59 +1200, Regan Heath <regan netwin.co.nz> wrote:On Wed, 9 Jun 2004 19:05:07 -0700, Kris <someidiot earthlink.dot.dot.dot.net> wrote:my wording here was a bit ambiguous, what I mean is: the data aa points to after this line (pp's data) is final, but aa does not become 'const'"Matthew" wroteI found final in my search for the right keyword, the online docs list it here... http://www.digitalmars.com/d/declaration.html StorageClass: abstract auto const deprecated final override static synchronized But does not describe what it means.Of course, if someone can offer good reasons against, then a more complexsyntaxmay be required. I'd shy away from the const x const y syntax, if at all possible, however, simply because it's confusing. How about (and it's right off the top of my head, so ...): const(int pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const(int) pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const(pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; // const arrayIt would seem quite reasonable to, as others have noted, use the keyword 'final' as a storage class indicator.That is, where you have data that is read-only, immutable, constant (whatever one wishes to call it) the 'final' qualifier would do the "right thing". That includes isolating said data into a separate, potentially ROMable, section.Sounds good. It's exactly what I was looking for.Of course, this doesn't address the related debate regarding read-only function arguments ... Rather than "const const" syntax, what do you think about a "final const" combo instead?Why not just final. I cannot see why you'd want to declare it as final (meaning const data) and not const (meaning the array ref cannot change). Tho, there would still be a distinction between 'final' array data and a 'const' array, see example below... eg. final int[] pp = [ 0,1,2,3,4,5,6,7,9 ]; void main() { int[] aa = [ 1,2,3 ]; int[] bb; pp[0] = 0; //compile error pp = aa; //compile error aa[] = pp[0..3] //ok, aa's data is 'final', but aa is not 'const'aa[0] = 0; //compile error aa = bb; //ok, aa is not const }-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/Personally, I don't care much for the parenthesized declaration ...Too many parenthesis, not good, if we can avoid it, I say lets. Regan.
Jun 09 2004
"Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message news:ca8fi6$1h5u$1 digitaldaemon.com..."Matthew" wroteNo, me neither. But I don't want us to have the double qualifier. What about final int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const array meaning immutable array, immutable values?Of course, if someone can offer good reasons against, then a more complexsyntaxmay be required. I'd shy away from the const x const y syntax, if at all possible, however, simply because it's confusing. How about (and it's right off the top of my head, so ...): const(int pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const(int) pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const(pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; // const arrayIt would seem quite reasonable to, as others have noted, use the keyword 'final' as a storage class indicator. That is, where you have data that is read-only, immutable, constant (whatever one wishes to call it) the 'final' qualifier would do the "right thing". That includes isolating said data into a separate, potentially ROMable, section. Of course, this doesn't address the related debate regarding read-only function arguments ... Rather than "const const" syntax, what do you think about a "final const" combo instead? Personally, I don't care much for the parenthesized declaration ...
Jun 09 2004
"Matthew" wroteWhat about final int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const array meaning immutable array, immutable values?Hey; I'd be very happy if the compiler supported that right now <g>
Jun 09 2004
Matthew wrote:"Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message news:ca8fi6$1h5u$1 digitaldaemon.com...Just had a thought... Final with classes means you can't resize (ie inherit from them) them but you can still change the values so I think it would make more sense to do: final //Can't resize const //Can't resize or change values Otherwise you've got final meaning two different things, which is never a good idea. -- -Anderson: http://badmama.com.au/~anderson/"Matthew" wroteNo, me neither. But I don't want us to have the double qualifier. What about final int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const array meaning immutable array, immutable values?Of course, if someone can offer good reasons against, then a more complexsyntaxmay be required. I'd shy away from the const x const y syntax, if at all possible, however, simply because it's confusing. How about (and it's right off the top of my head, so ...): const(int pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const(int) pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const(pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; // const arrayIt would seem quite reasonable to, as others have noted, use the keyword 'final' as a storage class indicator. That is, where you have data that is read-only, immutable, constant (whatever one wishes to call it) the 'final' qualifier would do the "right thing". That includes isolating said data into a separate, potentially ROMable, section. Of course, this doesn't address the related debate regarding read-only function arguments ... Rather than "const const" syntax, what do you think about a "final const" combo instead? Personally, I don't care much for the parenthesized declaration ...
Jun 10 2004
On Thu, 10 Jun 2004 19:18:06 +0800, J Anderson <REMOVEanderson badmama.com.au> wrote:Matthew wrote:I never thought of "final" like that.. "final" to me mean "cannot be changed""Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message news:ca8fi6$1h5u$1 digitaldaemon.com...Just had a thought... Final with classes means you can't resize (ie inherit from them) them"Matthew" wroteNo, me neither. But I don't want us to have the double qualifier. What about final int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const array meaning immutable array, immutable values?Of course, if someone can offer good reasons against, then a more complexsyntaxmay be required. I'd shy away from the const x const y syntax, if at all possible, however, simply because it's confusing. How about (and it's right off the top of my head, so ...): const(int pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const(int) pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const(pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; // const arrayIt would seem quite reasonable to, as others have noted, use the keyword 'final' as a storage class indicator. That is, where you have data that is read-only, immutable, constant (whatever one wishes to call it) the 'final' qualifier would do the "right thing". That includes isolating said data into a separate, potentially ROMable, section. Of course, this doesn't address the related debate regarding read-only function arguments ... Rather than "const const" syntax, what do you think about a "final const" combo instead? Personally, I don't care much for the parenthesized declaration ...but you can still change the values so I think it would make more sense to do: final //Can't resize const //Can't resize or change values Otherwise you've got final meaning two different things, which is never a good idea.I always thought "final" meant "cannot change" i.e. a final class == a class that cannot be changed. a final method == a method that cannot be changed. a final array == an array that cannot be changed. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 10 2004
Regan Heath wrote:On Thu, 10 Jun 2004 19:18:06 +0800, J Anderson <REMOVEanderson badmama.com.au> wrote:Sorry, your right. -- -Anderson: http://badmama.com.au/~anderson/Matthew wrote:I never thought of "final" like that.. "final" to me mean "cannot be changed""Kris" <someidiot earthlink.dot.dot.dot.net> wrote in message news:ca8fi6$1h5u$1 digitaldaemon.com...Just had a thought... Final with classes means you can't resize (ie inherit from them) them"Matthew" wroteNo, me neither. But I don't want us to have the double qualifier. What about final int pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const array meaning immutable array, immutable values?Of course, if someone can offer good reasons against, then a more complexsyntaxmay be required. I'd shy away from the const x const y syntax, if at all possible, however, simply because it's confusing. How about (and it's right off the top of my head, so ...): const(int pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; //const array const data const(int) pp[] = [ 0,1,2,3,4,5,6,7,8,9 ]; // const data int const(pp[]) = [ 0,1,2,3,4,5,6,7,8,9 ]; // const arrayIt would seem quite reasonable to, as others have noted, use the keyword 'final' as a storage class indicator. That is, where you have data that is read-only, immutable, constant (whatever one wishes to call it) the 'final' qualifier would do the "right thing". That includes isolating said data into a separate, potentially ROMable, section. Of course, this doesn't address the related debate regarding read-only function arguments ... Rather than "const const" syntax, what do you think about a "final const" combo instead? Personally, I don't care much for the parenthesized declaration ...but you can still change the values so I think it would make more sense to do: final //Can't resize const //Can't resize or change values Otherwise you've got final meaning two different things, which is never a good idea.I always thought "final" meant "cannot change" i.e. a final class == a class that cannot be changed. a final method == a method that cannot be changed. a final array == an array that cannot be changed. Regan
Jun 10 2004
Regan Heath wrote:But your variable isn't the data in the array, it's a (pointer,length) pair, isn't it? In java at least, final is "shallow", so it would mean that you can't make it point to other data, and you can't change the length. I get the impression that (with careful placement ;-) const can be "deep". So I likebut you can still change the values so I think it would make more sense to do: final //Can't resize const //Can't resize or change values Otherwise you've got final meaning two different things, which is never a good idea.I always thought "final" meant "cannot change" i.e. a final class == a class that cannot be changed. a final method == a method that cannot be changed. a final array == an array that cannot be changed.Samfinal //Can't resize const //Can't resize or change values
Jun 13 2004
On Sun, 13 Jun 2004 23:50:03 +1200, Sam McCall <tunah.d tunah.net> wrote:Regan Heath wrote:Yep. That is the problem. I can only specify the array itself is constant, not the data, as I want to.But your variable isn't the data in the array, it's a (pointer,length) pair, isn't it?but you can still change the values so I think it would make more sense to do: final //Can't resize const //Can't resize or change values Otherwise you've got final meaning two different things, which is never a good idea.I always thought "final" meant "cannot change" i.e. a final class == a class that cannot be changed. a final method == a method that cannot be changed. a final array == an array that cannot be changed.In java at least, final is "shallow", so it would mean that you can't make it point to other data, and you can't change the length.That is how "const" works on D char[] (I believe).I get the impression that (with careful placement ;-) const can be "deep".It can? Currently? How?So I like >> final //Can't resize >> const //Can't resize or change valuesWhere else can "final" be used, and what does it mean when used there... We want it to have a consistent meaning. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Jun 13 2004
Regan Heath wrote:Er, I meant the accepted meaning of const as it's used in C++.I get the impression that (with careful placement ;-) const can be "deep".It can? Currently? How?Where else can "final" be used, and what does it mean when used there... We want it to have a consistent meaning.Wouldn't have a clue, sorry ;-) Sam
Jun 13 2004