Re: More uses of operator in

2014-10-29 Thread Araq via Digitalmars-d-learn
Without that, algorithms can't make guarantees about their complexity, and it could have very negative impact on the performance of some programs. Yeah. For the programs where efficiency matters but that are never ever profiled.

Template constraint: T is a value type

2014-10-29 Thread Gareth Foster via Digitalmars-d-learn
Hi there, I'm looking to write a function template that operates only on value types. Basically I'm looking for an equivalent of where T: struct from C# (http://msdn.microsoft.com/en-us/library/d5x73970.aspx) I was thinking that maybe using template Foo(T) if (is(T : struct) or is(T:

Re: More uses of operator in

2014-10-29 Thread via Digitalmars-d-learn
On Tuesday, 28 October 2014 at 20:24:03 UTC, Steven Schveighoffer wrote: It's also O(lgn) on a sorted set, or O(1) on a hash set. So? As araq points out this should be caught in profiling. Avoiding generality is not the best approach. A linear scan of a SIMD friendly array that is in cache

Re: Template constraint: T is a value type

2014-10-29 Thread Rikki Cattermole via Digitalmars-d-learn
On 29/10/2014 11:01 p.m., Gareth Foster wrote: Hi there, I'm looking to write a function template that operates only on value types. Basically I'm looking for an equivalent of where T: struct from C# (http://msdn.microsoft.com/en-us/library/d5x73970.aspx) I was thinking that maybe using

Re: Reflections on isPalindrome

2014-10-29 Thread MattCoder via Digitalmars-d-learn
On Tuesday, 28 October 2014 at 16:07:38 UTC, MachineCode wrote: I'm very surprise. If they either equal or fast sometimes the compiler did great optizations or it's just a multicore processor that's helping or what else? the first version (from your post, the one using ranges) change in each

Re: dub fetch target redirection...

2014-10-29 Thread Mike Parker via Digitalmars-d-learn
On 10/29/2014 1:48 PM, WhatMeWorry wrote: It looks like dub fetch... is putting all packages at %appdata% path on my windows machine. Is there a way to redirect packages to a user specified path? You're not really supposed to worry about that. It's how dub manages the packages internally. Why

Re: Template constraint: T is a value type

2014-10-29 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 10:01:18 UTC, Gareth Foster wrote: Hi there, I'm looking to write a function template that operates only on value types. Basically I'm looking for an equivalent of where T: struct from C# (http://msdn.microsoft.com/en-us/library/d5x73970.aspx) I was

Re: dub fetch target redirection...

2014-10-29 Thread Kagamin via Digitalmars-d-learn
https://github.com/D-Programming-Language/dub/issues/229

Equivalent in D for .p2align 4,,15 ?

2014-10-29 Thread Etienne via Digitalmars-d-learn
I'm looking for the D inline assembler equivalent of the .p2align 4,,15 directive to optimize a loop. Here's more information: http://stackoverflow.com/questions/21546946/what-p2align-does-in-asm-code I tried searching through a turbo assembler tutorial (because D's is based on it) and found

Re: Equivalent in D for .p2align 4,,15 ?

2014-10-29 Thread anonymous via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 17:16:23 UTC, Etienne wrote: I'm looking for the D inline assembler equivalent of the .p2align 4,,15 directive to optimize a loop. Here's more information: http://stackoverflow.com/questions/21546946/what-p2align-does-in-asm-code I tried searching through a

Re: Equivalent in D for .p2align 4,,15 ?

2014-10-29 Thread Etienne via Digitalmars-d-learn
On 2014-10-29 1:44 PM, anonymous wrote: D inline assembler has an 'align' directive [1]. Aligning to a 16 byte boundary in D: `align 16;`. [1] http://dlang.org/iasm.html -- align IntegerExpression, near the top Of course, align directive works on instructions in asm. Thanks anonymous, that

Re: dub fetch target redirection...

2014-10-29 Thread WhatMeWorry via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 12:47:48 UTC, Kagamin wrote: https://github.com/D-Programming-Language/dub/issues/229 Thanks. This s-ludwig guy is great.

Re: dub fetch target redirection...

2014-10-29 Thread WhatMeWorry via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 11:35:17 UTC, Mike Parker wrote: On 10/29/2014 1:48 PM, WhatMeWorry wrote: It looks like dub fetch... is putting all packages at %appdata% path on my windows machine. Is there a way to redirect packages to a user specified path? You're not really supposed to

Need help: Return reference slice

2014-10-29 Thread advibm via Digitalmars-d-learn
Hello, I would like to create a D function that returns a slice of a string. This slice shall be a reference to a part of the string argument. Is this generally possible in D? This is the function: auto ref betweenTwoStrings(T)(inout T src, string start, string end) { long a =

Re: Need help: Return reference slice

2014-10-29 Thread bearophile via Digitalmars-d-learn
advibm: I would like to have something like that: char[] buf; // already filled array char[] partOfBuf = betweenTwoStrings(buf, START, END); partOfBuf[0] = 'a'; // THIS should also change the 'buf' variable assert(buf[0] == 'a'); Thanks for your help To do this you don't need to return a

Re: Need help: Return reference slice

2014-10-29 Thread advibm via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 19:54:45 UTC, bearophile wrote: advibm: I would like to have something like that: char[] buf; // already filled array char[] partOfBuf = betweenTwoStrings(buf, START, END); partOfBuf[0] = 'a'; // THIS should also change the 'buf' variable assert(buf[0] ==

readln with buffer fails

2014-10-29 Thread dcrepid via Digitalmars-d-learn
I have this simple code: int main() { import std.stdio; char[4096] Input; readln(Input); //readln!(char)(Input); // also fails return 0; } I get these messages during compilation: test.d(39): Error: template std.stdio.readln cannot deduce function from argument types

Re: readln with buffer fails

2014-10-29 Thread Peter Alexander via Digitalmars-d-learn
You need to take a slice of the buffer: char[] buf = Input[]; readln(buf); // line now in buf The reason for this is because you need to know where the string ends. If you just passed in Input, how would you know how long the line read was?

Re: readln with buffer fails

2014-10-29 Thread Baz via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 21:14:17 UTC, dcrepid wrote: I have this simple code: int main() { import std.stdio; char[4096] Input; readln(Input); //readln!(char)(Input); // also fails return 0; } I get these messages during compilation: test.d(39): Error: template

Re: readln with buffer fails

2014-10-29 Thread ketmar via Digitalmars-d-learn
On Wed, 29 Oct 2014 21:14:13 + dcrepid via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: Now, I'm used to 'buffer' meaning one thing, but here it seems that buffer means something more akin to a 'sink' object, or a forced dynamic array type? Is there some way I can avoid

Re: Need help: Return reference slice

2014-10-29 Thread Ali Çehreli via Digitalmars-d-learn
On 10/29/2014 12:50 PM, advibm wrote: Hello, I would like to create a D function that returns a slice of a string. This slice shall be a reference to a part of the string argument. Is this generally possible in D? This is the function: auto ref betweenTwoStrings(T)(inout T src, string start,

Dart bindings for D?

2014-10-29 Thread Laeeth Isharc via Digitalmars-d-learn
Hi. I have had a look around for these, but was not able to see them. It looks perhaps like dart_api.h is the main file to convert - I will have a crack at starting this unless anyone knows of any already in existence. Rationale for using Dart in combination with D is that I am not

Re: Dart bindings for D?

2014-10-29 Thread ketmar via Digitalmars-d-learn
On Wed, 29 Oct 2014 22:12:30 + Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: it's OT, but haven't you tried Adam Ruppe's script.d? it has d-like syntax with influences from javascript, written entirely in D, and has simple interoperability with D code. it's

Re: readln with buffer fails

2014-10-29 Thread dcrepid via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 21:19:25 UTC, Peter Alexander wrote: You need to take a slice of the buffer: char[] buf = Input[]; readln(buf); // line now in buf The reason for this is because you need to know where the string ends. If you just passed in Input, how would you know how long

Re: readln with buffer fails

2014-10-29 Thread dcrepid via Digitalmars-d-learn
err, I meant rvalue *reference* above

Re: readln with buffer fails

2014-10-29 Thread dcrepid via Digitalmars-d-learn
lol, if only I could edit my posts. The comment preceding the readln() call was wrong too. This is what I have now: // readln(buf) requires a slice *Reference*. // rvalue references aren't supported by D, so readln(Input[]) fails

Re: readln with buffer fails

2014-10-29 Thread Justin Whear via Digitalmars-d-learn
On Wed, 29 Oct 2014 23:10:10 +, dcrepid wrote: On Wednesday, 29 October 2014 at 21:19:25 UTC, Peter Alexander wrote: You need to take a slice of the buffer: char[] buf = Input[]; readln(buf); // line now in buf The reason for this is because you need to know where the string ends. If

Re: Dart bindings for D?

2014-10-29 Thread Etienne Cimon via Digitalmars-d-learn
On 2014-10-29 18:12, Laeeth Isharc wrote: Rationale for using Dart in combination with D is that I am not thrilled about learning or writing in Javascript, yet one has to do processing on the client in some language, and there seem very few viable alternatives for that. It would be nice to run

Re: readln with buffer fails

2014-10-29 Thread dcrepid via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 23:28:07 UTC, Justin Whear wrote: Part of what readln does is *modify* the slice itself, not just the pointed-to characters. In particular it alters the length member so that you know how much input was actually read. This is also why the rvalue reference

Re: Dart bindings for D?

2014-10-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 22:12:32 UTC, Laeeth Isharc wrote: I will have a crack at starting this unless anyone knows of any already in existence. I haven't heard of any. Rationale for using Dart in combination with D is that I am not thrilled about learning or writing in Javascript,

Re: Dart bindings for D?

2014-10-29 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 22:22:39 UTC, ketmar via Digitalmars-d-learn wrote: it's not lightning fast, though, but the code is understandable and it's fairly easy to extend the language if necessary. Curious, what have you tried with it? I wanted to keep it simple but actually

Pointer to constructor

2014-10-29 Thread Toshiaki Takada via Digitalmars-d-learn
Hi Folks, Quick question, how do I get pointer to a class constructor, let's say default constructor? I want to set it to AA, but couldn't find a way. Thanks! --Toshiaki

Re: Pointer to constructor

2014-10-29 Thread Adam D. Ruppe via Digitalmars-d-learn
You can access constructors just like any other method if you use the __ctor name. So like MyClass.__ctor.

Re: Dart bindings for D?

2014-10-29 Thread ketmar via Digitalmars-d-learn
On Thu, 30 Oct 2014 01:31:23 + Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wednesday, 29 October 2014 at 22:22:39 UTC, ketmar via Digitalmars-d-learn wrote: it's not lightning fast, though, but the code is understandable and it's fairly easy to

Re: Dart bindings for D?

2014-10-29 Thread via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 22:12:32 UTC, Laeeth Isharc wrote: I have had a look around for these, but was not able to see them. It looks perhaps like dart_api.h is the main file to convert - I will have a crack at starting this unless anyone knows of any already in existence. Dart VM