A question regarding Array capacity, length and slices

2014-05-29 Thread Sourav via Digitalmars-d-learn
Hello, I am quite new to D and working my way through the D tutorials. While learning about slices and capacity I found that depending upon the initial number of elements in a slice (and hence its capacity) the behavior of the code changes. Consider this program: snip import std.stdio;

Re: A question regarding Array capacity, length and slices

2014-05-29 Thread Ali Çehreli via Digitalmars-d-learn
On 05/29/2014 12:37 AM, Sourav wrote: the behavior totally depends upon how many elements were present initially in the array, which means, the capacity of a slice can actually introduces little surprises in the code! Is this expected behavior or am I entirely missing something here? It is

Re: A question regarding Array capacity, length and slices

2014-05-29 Thread Sourav via Digitalmars-d-learn
Thanks! Just what I needed to understand. :-) On Thursday, 29 May 2014 at 08:12:10 UTC, Ali Çehreli wrote: On 05/29/2014 12:37 AM, Sourav wrote: the behavior totally depends upon how many elements were present initially in the array, which means, the capacity of a slice can actually

Re: Cost of .dup vs. instantiation

2014-05-29 Thread Chris via Digitalmars-d-learn
On Wednesday, 28 May 2014 at 17:33:19 UTC, monarch_dodra wrote: On Wednesday, 28 May 2014 at 14:36:25 UTC, Chris wrote: I use Appender to fill an array. The Appender is a class variable and is not instantiated with each function call to save instantiation. However, the return value or the

Re: Cost of .dup vs. instantiation

2014-05-29 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 29 May 2014 at 08:49:10 UTC, Chris wrote: monarch_dodra: Hm. This last point might be an issue. If I process a large input (text in this case) then I might run into trouble with append as a class variable. I also had a weird bug, because I didn't clear the memory for overwrite.

Re: Cost of .dup vs. instantiation

2014-05-29 Thread Chris via Digitalmars-d-learn
On Thursday, 29 May 2014 at 12:04:35 UTC, monarch_dodra wrote: On Thursday, 29 May 2014 at 08:49:10 UTC, Chris wrote: monarch_dodra: Hm. This last point might be an issue. If I process a large input (text in this case) then I might run into trouble with append as a class variable. I also had

Is this a bug or illegal code?

2014-05-29 Thread safety0ff via Digitalmars-d-learn
//*** CODE ** mixin(version = foo;); version(foo) { void main(){} } //** END CODE *** If it's illegal in D, what is the reason where is documented? The reason I was considering such a construct is the following: Some C libraries have an associated config.h header that

Re: Is this a bug or illegal code?

2014-05-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On Thu, 29 May 2014 10:45:28 -0400, safety0ff safety0ff@gmail.com wrote: //*** CODE ** mixin(version = foo;); version(foo) { void main(){} } //** END CODE *** If it's illegal in D, what is the reason where is documented? The reason I was considering such a

Re: Is this a bug or illegal code?

2014-05-29 Thread safety0ff via Digitalmars-d-learn
On Thursday, 29 May 2014 at 15:02:48 UTC, Steven Schveighoffer wrote: Even if that is valid code, you are much better off using enums and static if. enum includeSomeFeature = ... static if(includeSomeFeature) { ... } These work much more like #defines, and can be seen outside the module.

Vance Miller Kitchens

2014-05-29 Thread semarmesem via Digitalmars-d-learn
Vance Miller Kitchens really do represent excellent value for money. No wonder Big kitchen stores hate Vance Miller Kitchens so much.

Building 32bit program with MSVC?

2014-05-29 Thread Jeremy DeHaan via Digitalmars-d-learn
I know that we can use MSVC to build a 64 bit program, but is it also possible to use it to build a 32 bit program as well?

Re: Building 32bit program with MSVC?

2014-05-29 Thread Remo via Digitalmars-d-learn
On Thursday, 29 May 2014 at 18:25:19 UTC, Jeremy DeHaan wrote: I know that we can use MSVC to build a 64 bit program, but is it also possible to use it to build a 32 bit program as well? Yes of course it is possible. It you are talking about Visual-D then it is possible there too.

Read file on compiler time.

2014-05-29 Thread Remo via Digitalmars-d-learn
Is there a way to read a text file into a sting at compile time in D2 ? It would be great to read for example some JSON file and then parse it using CTFU and create some D code based on it.

Re: Read file on compiler time.

2014-05-29 Thread Adam D. Ruppe via Digitalmars-d-learn
string a = import(file.txt); dmd yourprogram.d -Jlocation_of_file so for example dmd yourprogram.d -J. if file.txt is in the same directory as the .d file.

Re: Read file on compiler time.

2014-05-29 Thread Remo via Digitalmars-d-learn
On Thursday, 29 May 2014 at 20:21:32 UTC, Adam D. Ruppe wrote: string a = import(file.txt); dmd yourprogram.d -Jlocation_of_file so for example dmd yourprogram.d -J. if file.txt is in the same directory as the .d file. Excellent, thank you Adam! Now another question is it also possible

Re: Read file on compiler time.

2014-05-29 Thread bearophile via Digitalmars-d-learn
Remo: is it also possible to save/write string at compile time? There is pragma(msg, ...) but it's a little crappy. There are plans and a pull request for a good _ctWrite, but it's stalled for reasons unknown to me. Bye, bearophile

Re: Read file on compiler time.

2014-05-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 29 May 2014 at 20:38:30 UTC, Remo wrote: Now another question is it also possible to save/write string at compile time? Sort of, use pragma(msg, some string); and it will be printed out when that code is compiled. Important that it is when the code is compiled, NOT when the

Re: Read file on compiler time.

2014-05-29 Thread Remo via Digitalmars-d-learn
On Thursday, 29 May 2014 at 20:44:09 UTC, bearophile wrote: Remo: is it also possible to save/write string at compile time? There is pragma(msg, ...) but it's a little crappy. There are plans and a pull request for a good _ctWrite, but it's stalled for reasons unknown to me. Bye,

Re: Building 32bit program with MSVC?

2014-05-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Thu, 29 May 2014 20:12:52 + Remo via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Thursday, 29 May 2014 at 18:25:19 UTC, Jeremy DeHaan wrote: I know that we can use MSVC to build a 64 bit program, but is it also possible to use it to build a 32 bit program as well?

Examining Members of a module at Compile Time

2014-05-29 Thread Meta via Digitalmars-d-learn
I'd like to get a list of all classes in the current module, so I came up with this code: class Test {} class TestChild: Test {} class TestChildChild: TestChild {} void main() { foreach (item; __traits(allMembers, mixin(__MODULE__))) { static if

Re: Examining Members of a module at Compile Time

2014-05-29 Thread Dicebot via Digitalmars-d-learn
class Test {} class TestChild: Test {} class TestChildChild: TestChild {} alias Alias(alias Symbol) = Symbol; // this does the trick void main() { foreach (item; __traits(allMembers, mixin(__MODULE__))) { alias sym = Alias!(__traits(getMember, mixin(__MODULE__), item));

Re: Examining Members of a module at Compile Time

2014-05-29 Thread Meta via Digitalmars-d-learn
On Thursday, 29 May 2014 at 23:18:32 UTC, Dicebot wrote: class Test {} class TestChild: Test {} class TestChildChild: TestChild {} alias Alias(alias Symbol) = Symbol; // this does the trick void main() { foreach (item; __traits(allMembers, mixin(__MODULE__))) { alias sym =

Question about wrapping raw C pointers from D

2014-05-29 Thread Rusty D. Shackleford via Digitalmars-d-learn
Hi, in C++ I can use smart pointers to wrap raw pointers with custom deleter to automatically manage C resources. Is there anything like this in D?