get number of items in DList

2014-07-11 Thread pgtkda via Digitalmars-d-learn
How can i get the number of items which are currently hold in a DList?

Re: get number of items in DList

2014-07-11 Thread bearophile via Digitalmars-d-learn
pgtkda: How can i get the number of items which are currently hold in a DList? Try (walkLength is from std.range): mydList[].walkLength Bye, bearophile

Re: Passing Templated Function Arguments Solely by Reference

2014-07-11 Thread Nordlöw
On Wednesday, 9 July 2014 at 07:43:57 UTC, Ali Çehreli wrote: Phobos algorithms use ranges. The following is what I've come up with very quickly: Thx

Re: How to interact with fortran code

2014-07-11 Thread bachmeier via Digitalmars-d-learn
On Thursday, 10 July 2014 at 12:12:20 UTC, Marc Schütz wrote: On Wednesday, 9 July 2014 at 15:09:08 UTC, Chris wrote: On Wednesday, 9 July 2014 at 15:00:25 UTC, seany wrote: I apologize many times for this question, may be this had already been answered somewhere, but considering today the las

Re: Passing Templated Function Arguments Solely by Reference

2014-07-11 Thread Nordlöw
On Wednesday, 9 July 2014 at 07:43:57 UTC, Ali Çehreli wrote: Ali This https://github.com/nordlow/justd/blob/master/random_ex.d is what I have so far. Does this look ok to you? Question: Can I somehow avoid the duplication of logic in - auto ref randInPlace(R)(R x) @safe if (hasAssignableEl

Re: core.exception.InvalidMemoryOperationError

2014-07-11 Thread Joakim via Digitalmars-d-learn
On Thursday, 10 July 2014 at 15:36:53 UTC, francesco cattoglio wrote: A code I'm working on stops working and starts printing an infinite loop of core.exception.InvalidMemoryOperationError to the command line output. The code is quite complex and the bug seems to present itself almost in random

Re: get number of items in DList

2014-07-11 Thread Ary Borenszweig via Digitalmars-d-learn
On 7/11/14, 4:46 AM, bearophile wrote: pgtkda: How can i get the number of items which are currently hold in a DList? Try (walkLength is from std.range): mydList[].walkLength Bye, bearophile So the doubly linked list doesn't know it's length? That seems a bit inefficient...

Re: get number of items in DList

2014-07-11 Thread bearophile via Digitalmars-d-learn
Ary Borenszweig: So the doubly linked list doesn't know it's length? That seems a bit inefficient... Have you tried to compile mydList.length or mydList[].length? If both don't compile, then you have to walk the items. Walking the items is not efficient, but: - Linked lists are very uncommo

Re: get number of items in DList

2014-07-11 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 11, 2014 at 10:23:58AM -0300, Ary Borenszweig via Digitalmars-d-learn wrote: > On 7/11/14, 4:46 AM, bearophile wrote: > >pgtkda: > > > >>How can i get the number of items which are currently hold in a > >>DList? > > > >Try (walkLength is from std.range): > > > >mydList[].walkLength > >

DMDScript

2014-07-11 Thread Chris via Digitalmars-d-learn
Tried to compile on linux, got this error message (I guess I can fix it): dmd -c textgen.d textgen.d(36): Error: cannot implicitly convert expression ("DMDScript fatal runtime error: ") of type string to char[] textgen.d(36): Error: cannot implicitly convert expression (0) of type int to char[

Re: core.exception.InvalidMemoryOperationError

2014-07-11 Thread francesco cattoglio via Digitalmars-d-learn
On Friday, 11 July 2014 at 11:43:44 UTC, Joakim wrote: On Thursday, 10 July 2014 at 15:36:53 UTC, francesco cattoglio wrote: A code I'm working on stops working and starts printing an infinite loop of core.exception.InvalidMemoryOperationError to the command line output. The code is quite compl

Value Reference Type Traits

2014-07-11 Thread Nordlöw
Is there a trait to check if a type is a - value type (struct, static array, etc) - reference type (class, dynamic array, string, etc) ?

Re: Value Reference Type Traits

2014-07-11 Thread anonymous via Digitalmars-d-learn
On Friday, 11 July 2014 at 16:10:31 UTC, Nordlöw wrote: Is there a trait to check if a type is a - value type (struct, static array, etc) - reference type (class, dynamic array, string, etc) ? There's http://dlang.org/phobos/std_traits.html#hasIndirections Note that structs and static arrays

Re: Passing Templated Function Arguments Solely by Reference

2014-07-11 Thread Ali Çehreli via Digitalmars-d-learn
On 07/11/2014 03:38 AM, "Nordlöw" wrote: > https://github.com/nordlow/justd/blob/master/random_ex.d > > is what I have so far. Does this look ok to you? The following seems redundant because the other isFloatingPoint!E version uses the default arguments 0 and 1 anyway. auto ref randInPlace(E)

Question about @nogc in D 2.066

2014-07-11 Thread Weasel via Digitalmars-d-learn
@nogc void main(string[] args) { immutable(char)[] s1 = "hello"; immutable(int)[] a1 = [1, 2]; } Why does the s1 not throw an error, but the a1 does? As far as I can tell, they're both immutable arrays. Error is: "Error: array literal @nogc function main may cause GC allocation" It

Re: Question about @nogc in D 2.066

2014-07-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 11 July 2014 at 20:02:32 UTC, Weasel wrote: Why does the s1 not throw an error, but the a1 does? Strings don't allocate upon use whereas all other arrays do unless you specifically mark it as static - immutability isn't considered here (I think because the part of the compiler that

Re: Question about @nogc in D 2.066

2014-07-11 Thread Dicebot via Digitalmars-d-learn
Key difference is that type of string literal is immutable(char)[] so it is perfectly legal to keep it in binary text segment. Type of array literal is just T[] (int[] here) and you can possibly mutate their elements. Because of this each assignment of array literal needs to allocate a new copy

Re: Question about @nogc in D 2.066

2014-07-11 Thread Timon Gehr via Digitalmars-d-learn
On 07/11/2014 10:39 PM, Dicebot wrote: Key difference is that type of string literal is immutable(char)[] so it is perfectly legal to keep it in binary text segment. Type of array literal is just T[] (int[] here) and you can possibly mutate their elements. Because of this each assignment of array

Re: Question about @nogc in D 2.066

2014-07-11 Thread Trass3r via Digitalmars-d-learn
http://forum.dlang.org/thread/pxotrowaqcenrpnnw...@forum.dlang.org

Re: Question about @nogc in D 2.066

2014-07-11 Thread Dicebot via Digitalmars-d-learn
On Friday, 11 July 2014 at 21:02:30 UTC, Timon Gehr wrote: He is allocating an immutable(int)[] here. There is no reason why it should allocate unless providing different addresses for different runs of the code is considered a feature, as the literal has a compile-time known value. It's just t

Re: Insert a char in string

2014-07-11 Thread JR via Digitalmars-d-learn
On Thursday, 10 July 2014 at 19:33:15 UTC, simendsjo wrote: On 07/10/2014 06:05 PM, Alexandre wrote: I have a string X and I need to insert a char in that string... auto X = "100"; And I need to inser a ',' in position 3 of this string..., I try to use the array.insertInPlace, bu

I don't get it. version(unittest) can't seem to use local variable

2014-07-11 Thread dysmondad via Digitalmars-d-learn
I'm new to D. I've been using C since it was a baby and C++ back when it was only a pre-compiler for c. So, I may just be stuck thinking in C land. The issue is I am attempting to use the version(unittest) feature. However the compiler pukes up the error below. I'm sure it's something easy en

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-11 Thread Rikki Cattermole via Digitalmars-d-learn
On 12/07/2014 5:08 p.m., dysmondad wrote: I'm new to D. I've been using C since it was a baby and C++ back when it was only a pre-compiler for c. So, I may just be stuck thinking in C land. The issue is I am attempting to use the version(unittest) feature. However the compiler pukes up the error

Re: I don't get it. version(unittest) can't seem to use local variable

2014-07-11 Thread Ali Çehreli via Digitalmars-d-learn
On 07/11/2014 10:08 PM, dysmondad wrote: > class Velocity > { [...] > ref Velocity opOpAssign(string op) ( in float multiplier ) Unrelated to your question, you want to return just Velocity there. Unlike C++, classes are reference types in D. So, Velocity itself is essentially a Velocit

Raw Binary into the console

2014-07-11 Thread Sean Campbell via Digitalmars-d-learn
How Can I Print Raw Binary Into The Console? I Have Variable Of Type ubyte which equals 0b011 How Can I Get The Variable To Print Out As 011

Re: Raw Binary into the console

2014-07-11 Thread Ali Çehreli via Digitalmars-d-learn
On 07/11/2014 10:56 PM, Sean Campbell wrote: > How Can I Print Raw Binary Into The Console? Taking a step back, a D program prints to stdout, not console. However, in most cases a D program's output ends up on the console when it is started in a console. So, one can print any byte value to t