How do I truncate a file, delete bytes, or set the end of file from a stream?

2011-06-12 Thread XP1
How do I truncate a file, delete bytes, or set the end of file from a stream? For example, what would be the easiest way to delete the last 4 bytes from a file?

Thousands separators

2011-06-12 Thread bearophile
Do you know if in Phobos there is already a way to format a number with thousands separators (a point, comma o underscore)? Bye and thank you, bearophile

Re: + operators

2011-06-12 Thread bearophile
Jonathan M Davis: That would depend entirely on the optimizer. You have to take a look at the asm produced by the compiler to be sure what its optimizations have done. Bye, bearophile

Re: + operators

2011-06-12 Thread bearophile
Jonathan M Davis: Certainly, once range propagation has been fully implemented, this particular will work without needing any casts, but as soon as the compiler doesn't know what the values of x and y are, I believe that it would still end up complaining. I am not sure D range propagation

Re: + operators

2011-06-12 Thread Jonathan M Davis
On 2011-06-12 02:37, bearophile wrote: Jonathan M Davis: Certainly, once range propagation has been fully implemented, this particular will work without needing any casts, but as soon as the compiler doesn't know what the values of x and y are, I believe that it would still end up

about attribute... (trying to implement a DataContractSerializer functionality)

2011-06-12 Thread Lloyd Dupont
From the book I was under the impression that there could be user defined attribute. I wonder if this has been implemented? My problem: I try to implement a simplistic DataContractSerializer (as in

format()

2011-06-12 Thread Lloyd Dupont
Apparently std.string.format() is not implemented / does not compile! :( Is there any sort of replacement? Something which works like writefln() but output a string!

Re: format()

2011-06-12 Thread bearophile
Lloyd Dupon: Apparently std.string.format() is not implemented / does not compile! :( This works for me, DMD 2.053: import std.stdio, std.string; void main() { int x = 10; auto s = format(%d, 10); writeln(, s, ); } Bye, bearophile

Re: format()

2011-06-12 Thread Lloyd Dupont
mm... ok. but why the line below doesn't compile? mixin(format(class %s {}, A)); bearophile wrote in message news:it2pf5$1qh6$1...@digitalmars.com... Apparently std.string.format() is not implemented / does not compile! :( This works for me, DMD 2.053:

enum sstring problem

2011-06-12 Thread Lloyd Dupont
I'm using 2.053 this compile fine: enum : string { A = hello, B = betty, } this doesn't! enum AA : string { A = hello, B = betty, } Am I missing something? Named enum can't be typed? known bug?

string manipulation performance

2011-06-12 Thread Lloyd Dupont
I have a method like that: === public string repeat(string s, int num) { string result = s; for (int i=1; inum; i++) result ~= s; return result; } === basically it will create num string, each a little longer... is there a more efficient way to go about that? thanks! :)

Re: format()

2011-06-12 Thread David Nadlinger
On 6/12/11 6:37 PM, Lloyd Dupont wrote: mm... ok. but why the line below doesn't compile? mixin(format(class %s {}, A)); Because format presumably can't be interpreted at compile time (yet) – not all functions are necessarily CTFEable. David

Re: string manipulation performance

2011-06-12 Thread Steven Schveighoffer
On Sun, 12 Jun 2011 12:49:25 -0400, Lloyd Dupont ld-rem...@galador.net wrote: I have a method like that: === public string repeat(string s, int num) { string result = s; for (int i=1; inum; i++) result ~= s; return result; } === basically it will create num string, each a

Re: + operators

2011-06-12 Thread Don
Jonathan M Davis wrote: On 2011-06-12 02:37, bearophile wrote: Jonathan M Davis: Certainly, once range propagation has been fully implemented, this particular will work without needing any casts, but as soon as the compiler doesn't know what the values of x and y are, I believe that it would

Re: format()

2011-06-12 Thread Jonathan M Davis
On 2011-06-12 10:30, David Nadlinger wrote: On 6/12/11 6:37 PM, Lloyd Dupont wrote: mm... ok. but why the line below doesn't compile? mixin(format(class %s {}, A)); Because format presumably can't be interpreted at compile time (yet) – not all functions are necessarily CTFEable.

Re: string manipulation performance

2011-06-12 Thread Jonathan M Davis
On 2011-06-12 11:08, Steven Schveighoffer wrote: On Sun, 12 Jun 2011 12:49:25 -0400, Lloyd Dupont ld-rem...@galador.net wrote: I have a method like that: === public string repeat(string s, int num) { string result = s; for (int i=1; inum; i++) result ~=

Re: about attribute... (trying to implement a DataContractSerializer functionality)

2011-06-12 Thread jdrewsen
Den 12-06-2011 15:43, Lloyd Dupont skrev: From the book I was under the impression that there could be user defined attribute. I wonder if this has been implemented? My problem: I try to implement a simplistic DataContractSerializer (as in

Re: format()

2011-06-12 Thread jdrewsen
Den 12-06-2011 18:37, Lloyd Dupont skrev: mm... ok. but why the line below doesn't compile? mixin(format(class %s {}, A)); Because the mixin is evaluated at compile time. This means that format(...) is evaluated at compile time which afaik is not supported. It may be supported in the

Re: enum sstring problem

2011-06-12 Thread Timon Gehr
Lloyd Dupont wrote: I'm using 2.053 this compile fine: enum : string { A = hello, B = betty, } this doesn't! enum AA : string { A = hello, B = betty, } Am I missing something? Named enum can't be typed? known bug? It works just fine for me.

Re: enum sstring problem

2011-06-12 Thread Lloyd Dupont
do you have DMD 2.053 on Windows? Your code fail for me with: main.d(10): Error: Integer constant expression expected instead of hello main.d(11): Error: Integer constant expression expected instead of betty main.d(10): Error: Integer constant expression expected instead of hello main.d(11):

Re: format()

2011-06-12 Thread Lloyd Dupont
yep, the example is simple because it is an example! Thanks for your suggestion! :) Jonathan M Davis wrote in message news:mailman.850.1307909499.14074.digitalmars-d-le...@puremagic.com... On 2011-06-12 10:30, David Nadlinger wrote: On 6/12/11 6:37 PM, Lloyd Dupont wrote: mm... ok. but

Re: string manipulation performance

2011-06-12 Thread Lloyd Dupont
But... string being immutable I don't see the point of allocating some space for one.. Am I missing something? Steven Schveighoffer wrote in message news:op.vwy503w4eav7ka@localhost.localdomain... On Sun, 12 Jun 2011 12:49:25 -0400, Lloyd Dupont ld-rem...@galador.net wrote: I have a

Re: enum sstring problem

2011-06-12 Thread Andrej Mitrovic
I've got 2.053 and it works for me.

Re: string manipulation performance

2011-06-12 Thread Lloyd Dupont
Thanks! Jonathan M Davis wrote in message news:mailman.851.1307909610.14074.digitalmars-d- Also, std.string.repeat has been scheduled for deprecation. You should use std.array.replicate instead. It does the same thing but for all arrays instead of just strings. - Jonathan M Davis

Re: string manipulation performance

2011-06-12 Thread Jonathan M Davis
On 2011-06-12 18:02, Lloyd Dupont wrote: But... string being immutable I don't see the point of allocating some space for one.. Am I missing something? Just because it's immutable doesn't mean that it doesn't need to exist at runtime. All immutable means is that you can't change it. It could

Re: string manipulation performance

2011-06-12 Thread Steven Schveighoffer
On Sun, 12 Jun 2011 21:02:05 -0400, Lloyd Dupont ld-rem...@galador.net wrote: But... string being immutable I don't see the point of allocating some space for one.. Am I missing something? Reserving space for appending does not make that space immutable, yet. As far as the runtime is

Re: string manipulation performance

2011-06-12 Thread Lloyd Dupont
Thanks Steven, that was very informative! Steven Schveighoffer wrote in message news:op.vwzrwdmteav7ka@localhost.localdomain... On Sun, 12 Jun 2011 21:02:05 -0400, Lloyd Dupont ld-rem...@galador.net wrote: But... string being immutable I don't see the point of allocating some space for

Object

2011-06-12 Thread Lloyd Dupont
I have problem with Object for example this doesn't compile: === Object o; o = ; === with error: cannot implicitly convert expression () of type string to object.Object or this also failed to compile: === class Foo { public: Object foo, bar, snafu; override const bool opEquals(Object

Re: Object

2011-06-12 Thread Jonathan M Davis
On 2011-06-12 22:25, Lloyd Dupont wrote: I have problem with Object for example this doesn't compile: === Object o; o = ; === with error: cannot implicitly convert expression () of type string to object.Object Object is the base class of all classes. Nothing which is not a class is an

Re: Object

2011-06-12 Thread Jonathan M Davis
On 2011-06-12 22:37, Jonathan M Davis wrote: On 2011-06-12 22:25, Lloyd Dupont wrote: I have problem with Object for example this doesn't compile: === Object o; o = ; === with error: cannot implicitly convert expression () of type string to object.Object Object is the base