Re: why does isForwardRange work like this?

2014-07-31 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, 31 July 2014 at 22:21:10 UTC, Vlad Levenfeld wrote: Yes, I see the problem now. I can't think of any reason why I'd want to make save anything but a function (especially since `save` is a verb) but I guess someone out there might have a good one. It's Andrei's fault. I'm not quit

Re: why does isForwardRange work like this?

2014-07-31 Thread Vlad Levenfeld via Digitalmars-d-learn
Yes, I see the problem now. I can't think of any reason why I'd want to make save anything but a function (especially since `save` is a verb) but I guess someone out there might have a good one. So, what is gained by (inout int = 0) over ()? I wasn't even aware that giving a default value for

Re: memory/array question

2014-07-31 Thread anonymous via Digitalmars-d-learn
On Thursday, 31 July 2014 at 21:50:25 UTC, Eric wrote: objdump -d -M intel simpleOctal Not sure what the switches are for; -d disassemble - Essential if you want to, well, disassemble. -M intel Intel syntax - Because no one likes AT&T syntax. Wikipedia has a comparison: http://en.wikipedia.o

Re: How to detect current executable file name?

2014-07-31 Thread shuji via Digitalmars-d-learn
There is a solution already for this: http://dlang.org/phobos/std_file.html#.thisExePath (just for future reference, it's seriously hard to search on google)

Re: memory/array question

2014-07-31 Thread Eric via Digitalmars-d-learn
On Thursday, 31 July 2014 at 20:59:46 UTC, Vlad Levenfeld wrote: On Thursday, 31 July 2014 at 20:43:11 UTC, bearophile wrote: Take a look at the asm! Bye, bearophile I use DMD and Dub, how do I view the asm? Actually I did't think to look at the asm, mainly because I've never bothered to d

Re: why does isForwardRange work like this?

2014-07-31 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, 31 July 2014 at 20:34:42 UTC, Vlad Levenfeld wrote: What's the rationale behind stating the condition this way as opposed to, say, is (typeof(R.init.save)) == R) || is ((typeof(R.init.save()) == R) so that member fields as well as @property and non-@property methods will match

Re: memory/array question

2014-07-31 Thread Vlad Levenfeld via Digitalmars-d-learn
On Thursday, 31 July 2014 at 20:43:11 UTC, bearophile wrote: Take a look at the asm! Bye, bearophile I use DMD and Dub, how do I view the asm?

Re: memory/array question

2014-07-31 Thread bearophile via Digitalmars-d-learn
Eric: Thanks. That really works. I timed doing auto mySlice = ptr1[0 .. ptr2 - ptr1]; 1,000,000 times versus auto mySlice = ptr1[0 .. ptr2 - ptr1].dup; 1,000,000 times and I am quite convinced the data is not being copied. Take a look at the asm! Bye, bearophile

why does isForwardRange work like this?

2014-07-31 Thread Vlad Levenfeld via Digitalmars-d-learn
I've been having trouble propagating range traits for range-wrapper structs. Consider this sample code: struct Wrapper (R) { R range; static if (isInputRange!R) { /* input range stuff */ } static if (isForwardRange!R) {

Re: Unexpected memory reuse

2014-07-31 Thread Sean Kelly via Digitalmars-d-learn
On Thursday, 31 July 2014 at 19:28:24 UTC, Marc Schütz wrote: On Thursday, 31 July 2014 at 18:30:41 UTC, Anonymous wrote: module test; import std.stdio; class buffer(T, size_t sz) { auto arr = new T[sz]; This allocates an array with `sz` elements once _at compile time_, places it som

Re: Checked shift?

2014-07-31 Thread bearophile via Digitalmars-d-learn
H. S. Teoh: OK, makes sense. But what about if only the most significant bit is 1? Wouldn't that also be an overflow? So you're essentially checking if the topmost n bits are zero, where n is the number of bits you wish to shift by. Of course. https://issues.dlang.org/show_bug.cgi?id=13231

Re: memory/array question

2014-07-31 Thread Eric via Digitalmars-d-learn
On Thursday, 31 July 2014 at 19:43:00 UTC, bearophile wrote: Eric: Suppose I have some memory allocated on the heap, and I have two pointers pointing to the beginning and end of a contiguous segment of that memory. Is there a way I can convert those two pointers to an array slice without act

Re: memory/array question

2014-07-31 Thread bearophile via Digitalmars-d-learn
Eric: Suppose I have some memory allocated on the heap, and I have two pointers pointing to the beginning and end of a contiguous segment of that memory. Is there a way I can convert those two pointers to an array slice without actually copying anything within the segment? Use something li

Re: Unexpected memory reuse

2014-07-31 Thread bearophile via Digitalmars-d-learn
Marc Schütz: class buffer(T, size_t sz) { auto arr = new T[sz]; This allocates an array with `sz` elements once _at compile time_, places it somewhere into the executable, and uses its address as the default initializer for the member `arr`. Right. It's not a compiler bug. Dmd/ldc

memory/array question

2014-07-31 Thread Eric via Digitalmars-d-learn
Suppose I have some memory allocated on the heap, and I have two pointers pointing to the beginning and end of a contiguous segment of that memory. Is there a way I can convert those two pointers to an array slice without actually copying anything within the segment? Thx, Eric

Re: Unexpected memory reuse

2014-07-31 Thread via Digitalmars-d-learn
On Thursday, 31 July 2014 at 18:30:41 UTC, Anonymous wrote: module test; import std.stdio; class buffer(T, size_t sz) { auto arr = new T[sz]; This allocates an array with `sz` elements once _at compile time_, places it somewhere into the executable, and uses its address as the defaul

Re: Unexpected memory reuse

2014-07-31 Thread Anonymous via Digitalmars-d-learn
On Thursday, 31 July 2014 at 18:51:09 UTC, Sean Kelly wrote: This looks like an optimizer bug. Do you see the same result with -release set vs. not, etc? I get it regardless of -release or -O. Replacing the arr declaration with T[sz] arr; fixes the problem.

Re: Unexpected memory reuse

2014-07-31 Thread Sean Kelly via Digitalmars-d-learn
This looks like an optimizer bug. Do you see the same result with -release set vs. not, etc?

Unexpected memory reuse

2014-07-31 Thread Anonymous via Digitalmars-d-learn
module test; import std.stdio; class buffer(T, size_t sz) { auto arr = new T[sz]; enum end = sz-1; } void foo(T, size_t sz)() { auto buf = new buffer!(T,sz); writeln("before ", buf.arr); foreach(ref ele; buf.arr) ++ele; writeln("after ", buf.arr);

Re: Unexpected memory reuse

2014-07-31 Thread Anonymous via Digitalmars-d-learn
Whoops, that is writeln("a ",a.arr); and so on.

Re: Checked shift?

2014-07-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 31, 2014 at 06:08:56PM +, bearophile via Digitalmars-d-learn wrote: > H. S. Teoh: > > >What would you check for? Shifting something that already has its > >high bit set? > > If you have a uint where the 3 most significant bits are 1, and you > shift it 3 bits on the left, you los

Re: Checked shift?

2014-07-31 Thread bearophile via Digitalmars-d-learn
H. S. Teoh: What would you check for? Shifting something that already has its high bit set? If you have a uint where the 3 most significant bits are 1, and you shift it 3 bits on the left, you lose those three bits, you have an overflow. The point of checkedint functions/intrinsics is to re

Re: Checked shift?

2014-07-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 31, 2014 at 05:00:22PM +, bearophile via Digitalmars-d-learn wrote: > Is it a good idea to add int/uint/long/ulong functions for the "<<" > left shift operation here? > > https://github.com/D-Programming-Language/druntime/blob/master/src/core/checkedint.d [...] What would you che

Re: Get the default hash function.

2014-07-31 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 31, 2014 at 12:05:52PM +, francesco cattoglio via Digitalmars-d-learn wrote: > Really simple question: > how do I get the compiler-generated hash function for a given type? > > For example: > Struct S > { > int i; > } > > can be used in an associative array. That means the co

Checked shift?

2014-07-31 Thread bearophile via Digitalmars-d-learn
Is it a good idea to add int/uint/long/ulong functions for the "<<" left shift operation here? https://github.com/D-Programming-Language/druntime/blob/master/src/core/checkedint.d Bye, bearophile

Re: Split class declaration and definition

2014-07-31 Thread Daniel Kozak via Digitalmars-d-learn
V Thu, 31 Jul 2014 13:26:38 + Kagamin via Digitalmars-d-learn napsáno: > On Thursday, 31 July 2014 at 12:02:22 UTC, Kozzi11 wrote: > > module m; > > @someUda > > class C { > > void someFun(); > > } > > > > @someUda > > class D { > > void anotherFun(); > > } > > > > mixin(generateFunDe

Re: Get the default hash function.

2014-07-31 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 31 July 2014 at 12:05:53 UTC, francesco cattoglio wrote: Really simple question: how do I get the compiler-generated hash function for a given type? For example: Struct S { int i; } can be used in an associative array. That means the compiler generates a "toHash" function. I

Re: Split class declaration and definition

2014-07-31 Thread Kagamin via Digitalmars-d-learn
On Thursday, 31 July 2014 at 12:02:22 UTC, Kozzi11 wrote: module m; @someUda class C { void someFun(); } @someUda class D { void anotherFun(); } mixin(generateFunDefForClassesWithSomeUda!m); This is usually done by generating functions in the classes directly. class C { mixin G

Re: Split class declaration and definition

2014-07-31 Thread bearophile via Digitalmars-d-learn
Kozzi11: Is possible to somehow split class declaration and definition. I mean something like this: class C { void hello(); // just prototype } class C { void hello() { //actual code } } or something like this void C.hello() { //actual code } I think this is cur

Get the default hash function.

2014-07-31 Thread francesco cattoglio via Digitalmars-d-learn
Really simple question: how do I get the compiler-generated hash function for a given type? For example: Struct S { int i; } can be used in an associative array. That means the compiler generates a "toHash" function. Is there any simple way to call it directly?

Re: Split class declaration and definition

2014-07-31 Thread Kozzi11 via Digitalmars-d-learn
On Thursday, 31 July 2014 at 11:41:07 UTC, FreeSlave wrote: On Thursday, 31 July 2014 at 11:34:38 UTC, Kozzi11 wrote: Is possible to somehow split class declaration and definition. I mean something like this: class C { void hello(); // just prototype } class C { void hello() {

Re: Split class declaration and definition

2014-07-31 Thread FreeSlave via Digitalmars-d-learn
On Thursday, 31 July 2014 at 11:34:38 UTC, Kozzi11 wrote: Is possible to somehow split class declaration and definition. I mean something like this: class C { void hello(); // just prototype } class C { void hello() { //actual code } } or something like this void C.hel

Split class declaration and definition

2014-07-31 Thread Kozzi11 via Digitalmars-d-learn
Is possible to somehow split class declaration and definition. I mean something like this: class C { void hello(); // just prototype } class C { void hello() { //actual code } } or something like this void C.hello() { //actual code }

Re: A little of coordination for Rosettacode

2014-07-31 Thread bearophile via Digitalmars-d-learn
safety0ff: I modified the Hamming numbers code in a personal exercise. It now uses considerably less memory but is slower. I've posted the code here in case it is of use: http://dpaste.dzfl.pl/3990023e5577 For a single n, n = 350_000_000: Alternative version 2: 13.4s and ~5480 MB of ram My c

Re: pointer array?

2014-07-31 Thread FreeSlave via Digitalmars-d-learn
On Wednesday, 30 July 2014 at 20:51:25 UTC, Daniel Kozak via Digitalmars-d-learn wrote: V Wed, 30 Jul 2014 14:33:51 + seany via Digitalmars-d-learn napsáno: In Ali's excllent book, somehow one thing has escaped my attention, and that it the mentioning of pointer arrays. Can pointers of

Re: Member access of __gshared global object

2014-07-31 Thread via Digitalmars-d-learn
On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote: 1. Are AAs reference type? if so, why does the compiler copy it? This is probably your problem. They are reference types, but initially that reference is `null`. When you write: auto cmds = CONFIG.commands; `cmds` contains a copy

Re: Emacs d-mode cannot handle backquoted backslashe

2014-07-31 Thread Nordlöw
On Thursday, 31 July 2014 at 09:20:28 UTC, Russel Winder via Digitalmars-d-learn wrote: Not just at the moment I'm afraid. I'll try and take a look at it tomorrow. Great!

Re: Emacs d-mode cannot handle backquoted backslashe

2014-07-31 Thread Russel Winder via Digitalmars-d-learn
On Thu, 2014-07-31 at 08:40 +, "Nordlöw" via Digitalmars-d-learn wrote: > Currently Emacs d-mode cannot correctly highlight > > `\` > > because it doesn't understand that single backslashes are > self-contained in back-quoted strings. > > I believe this extract from d-mode.el > > (defvar d

Emacs d-mode cannot handle backquoted backslashe

2014-07-31 Thread Nordlöw
Currently Emacs d-mode cannot correctly highlight `\` because it doesn't understand that single backslashes are self-contained in back-quoted strings. I believe this extract from d-mode.el (defvar d-mode-syntax-table nil "Syntax table used in d-mode buffers.") (or d-mode-syntax-table (