Re: Reading a csv file

2012-08-11 Thread Andrew
On Fri, 10 Aug 2012 03:44:11 +0200, Jesse Phillips wrote: > On Friday, 10 August 2012 at 01:39:32 UTC, Andrew wrote: >> I'm trying to read in a csv file. The examples in the docs for std.csv >> all assume you're reading from a string rather than a file. > > It requires a range of dchar. I believe

"For" infinite loop

2012-08-11 Thread RivenTheMage
This is infinite loop: for (ubyte i=0; i<=255; i++) { ... } I guess it's a bug?

Re: "For" infinite loop

2012-08-11 Thread Adam D. Ruppe
A ubyte is ALWAYS <=255, since ubyte 255 + 1 == 0.

Re: "For" infinite loop

2012-08-11 Thread bearophile
RivenTheMage: This is infinite loop: for (ubyte i=0; i<=255; i++) { ... } I guess it's a bug? One way to scan all the ubytes with a for loop: import std.stdio; void main() { for (ubyte i = 0; ; i++) { write(i, " "); if (i == 255) break; } } Bye, be

Check whether a type is a instantiated by a template struct

2012-08-11 Thread Henning Pohl
So the struct is defined as: struct S(T) { } template isS(T) { // ... } static assert(isS(S!float)); static assert(!isS(float)); There may be some nasty ways using fullQualifiedName!T and so on but I guess there is a better way, isn't it?

Re: Check whether a type is a instantiated by a template struct

2012-08-11 Thread Jakob Ovrum
On Saturday, 11 August 2012 at 18:51:36 UTC, Henning Pohl wrote: So the struct is defined as: struct S(T) { } template isS(T) { // ... } static assert(isS(S!float)); static assert(!isS(float)); There may be some nasty ways using fullQualifiedName!T and so on but I guess there is a better

Re: Convert little imperative code to functional coding style

2012-08-11 Thread bioinfornatics
Le vendredi 10 août 2012 à 20:26 +0200, Timon Gehr a écrit : > Is this what you are looking for? > > import std.stdio; > import std.range: iota; > import std.algorithm: map, filter, joiner; > import std.typecons : tuple; > import std.math : sqrt, floor; > > void main(){ >

Re: Check whether a type is a instantiated by a template struct

2012-08-11 Thread Chris Cain
On Saturday, 11 August 2012 at 18:56:30 UTC, Jakob Ovrum wrote: struct S(T) {} template isS(T : S!U, U) { enum isS = true; } template isS(T) { enum isS = false; } static assert(isS!(S!float)); static assert(!isS!float); Same idea, but doing it with just one template and using static

Re: "For" infinite loop

2012-08-11 Thread RivenTheMage
On Saturday, 11 August 2012 at 18:37:18 UTC, Adam D. Ruppe wrote: A ubyte is ALWAYS <=255, since ubyte 255 + 1 == 0. Isn't both "i" and "255" should be propagated to int before comparison?

Re: "For" infinite loop

2012-08-11 Thread RivenTheMage
On Saturday, 11 August 2012 at 19:18:14 UTC, RivenTheMage wrote: On Saturday, 11 August 2012 at 18:37:18 UTC, Adam D. Ruppe wrote: A ubyte is ALWAYS <=255, since ubyte 255 + 1 == 0. Isn't both "i" and "255" should be propagated to int before comparison? Implicitly propagated, I mean.

Re: "For" infinite loop

2012-08-11 Thread Chris Cain
On Saturday, 11 August 2012 at 19:20:36 UTC, RivenTheMage wrote: Isn't both "i" and "255" should be propagated to int before comparison? Implicitly propagated, I mean. Regardless, a ubyte 0 converted to an int is still 0. a ubyte can only hold a maximum of 255 and will roll over to 0 when i

Re: Check whether a type is a instantiated by a template struct

2012-08-11 Thread Henning Pohl
On Saturday, 11 August 2012 at 19:06:22 UTC, Chris Cain wrote: Same idea, but doing it with just one template and using static ifs... struct S(T) {} template isS(T) { static if(is(T _ : S!U, U)) enum isS = true; else enum isS = false; } static assert(isS!(S!float));

Re: Check whether a type is a instantiated by a template struct

2012-08-11 Thread Jakob Ovrum
On Saturday, 11 August 2012 at 19:06:22 UTC, Chris Cain wrote: Same idea, but doing it with just one template and using static ifs... struct S(T) {} template isS(T) { static if(is(T _ : S!U, U)) enum isS = true; else enum isS = false; } static assert(isS!(S!float)); st

Re: "For" infinite loop

2012-08-11 Thread RivenTheMage
Okay, thanks for helping!

Re: "For" infinite loop

2012-08-11 Thread bioinfornatics
Le samedi 11 août 2012 à 20:48 +0200, bearophile a écrit : > RivenTheMage: > > > This is infinite loop: > > > > for (ubyte i=0; i<=255; i++) > > { > > ... > > } > > > > I guess it's a bug? > > One way to scan all the ubytes with a for loop: > > import std.stdio; > void main() { > for

Re: "For" infinite loop

2012-08-11 Thread Chris Cain
On Saturday, 11 August 2012 at 20:00:40 UTC, bioinfornatics wrote: n this case why not using a while loop ? You mean like this? void main() { ubyte i = 0; do { write(i, " "); } while(i++ != 255); } or void main() { ubyte i = 0; while(true) { write(i, " ");

Re: "For" infinite loop

2012-08-11 Thread bearophile
bioinfornatics: n this case why not using a while loop ? It uses less lines of code, and with the for loop you have a single place where to put the loop variable initialization, test and increment. This makes the code simpler to read. In this case the test is moved inside the loop, but it's

Specialize mixin templates

2012-08-11 Thread Henning Pohl
A struct takes a mixin template as argument: struct S(alias Mixin) { mixin Mixin; } How to specialize a mixin template like this one to pass to S? mixin template MixinTemplate(T) { } S(MixinTemplate!float); // Something like this

Re: Null Object works still fine

2012-08-11 Thread Adam D. Ruppe
On Saturday, 11 August 2012 at 22:23:12 UTC, Namespace wrote: This code works fine but it shouldn't, or? The reason is the print method is private, which means it is also automatically final and doesn't access any member variables. Since it doesn't access members, it doesn't actually try to

Re: Null Object works still fine

2012-08-11 Thread David Nadlinger
On Saturday, 11 August 2012 at 22:23:12 UTC, Namespace wrote: This code works fine but it shouldn't, or? http://dpaste.dzfl.pl/b9027fff You don't actually dereference ›this‹ in print(), so the null value in the implicit this parameter doesn't matter. David

Re: Null Object works still fine

2012-08-11 Thread Marco Leise
Am Sun, 12 Aug 2012 00:23:10 +0200 schrieb "Namespace" : > This code works fine but it shouldn't, or? > > http://dpaste.dzfl.pl/b9027fff That's fine. There is no check for null at every possible occasion, like I think in Java. The operating system will catch any actual null dereference though,

Re: Optional extra return value? Multiple return values with auto?

2012-08-11 Thread ReneSac
On Tuesday, 24 July 2012 at 05:30:49 UTC, Ali Çehreli wrote: The options that I can think of: - Return a struct (or a class) where one of the members is not filled-in - Similarly, return a tuple This is awkward, and doesn't look good for performance. - Use an out parameter, which can hav

Re: Optional extra return value? Multiple return values with auto?

2012-08-11 Thread Ali Çehreli
On 08/11/2012 03:48 PM, ReneSac wrote: > On Tuesday, 24 July 2012 at 05:30:49 UTC, Ali Çehreli wrote: >> - Use an out parameter, which can have a default lvalue: >> >> int g_default_param; >> >> void foo(ref int i = g_default_param) >> { >> if (&i == &g_param) { >> // The caller is not interested

Re: Optional extra return value? Multiple return values with auto?

2012-08-11 Thread Timon Gehr
There is no compiler bug. You cannot pass immutable/rvalue by reference to mutable.

vector Cross/Dot using core.simd?

2012-08-11 Thread F i L
I'm trying to write a Cross and Dot function using core.simd.float4 and DMD The C++ code looks like: from: http://fastcpp.blogspot.com/2011/04/vector-cross-product-using-sse-code.html inline __m128 CrossProduct(__m128 a, __m128 b) { return _mm_sub_ps ( _mm_mul_ps ( _mm_

Re: vector Cross/Dot using core.simd?

2012-08-11 Thread F i L
On a side note, if I run the simple code: void16 a = 0, b = 0; void16 r = __simd(XMM.PSHUFB, a, b); writeln(r.array); I get the following error: Internal error: e2ir.c 3817

Re: vector Cross/Dot using core.simd?

2012-08-11 Thread Sean Cavanaugh
On 8/11/2012 8:23 PM, F i L wrote: I'm trying to write a Cross and Dot function using core.simd.float4 and DMD Does anyone know anything about SIMD operations that may be able to help me translate these functions into a D equivalent? I would very much appreciate your help. Some reference: C+

Re: Specialize mixin templates

2012-08-11 Thread Timon Gehr
On 08/11/2012 11:42 PM, Henning Pohl wrote: A struct takes a mixin template as argument: struct S(alias Mixin) { mixin Mixin; } How to specialize a mixin template like this one to pass to S? mixin template MixinTemplate(T) { } S(MixinTemplate!float); // Something like this This is a way t