Re: question about the semantics of unshared variables

2015-07-15 Thread aki via Digitalmars-d-learn
I noticed just making many threads cause an error. Are there any limit for the number of threads? import std.concurrency; import core.thread; void fun() { Thread.sleep(5000.msecs); } void testThread() { foreach(i; 0..2000) { spawn(&fun); } } core.thread.ThreadErro

Are Lua tables possible to do with D?

2015-07-15 Thread Robert M. Münch via Digitalmars-d-learn
Hi, do you think it's possible to implemented something like Lua Tables (a hashed heterogeneous associative array) in D? I know that Lua is dynamic and interpreted, hence it's a lot simpler to do than with a compiled language but I'm wondering if we could express such a generic data-structure

Re: Template function that accept strings and array of strings

2015-07-15 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-15 23:57, badlink wrote: Hello, I can't figure how to write a template function that accept either strings or array of strings. This is my current code: bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId) if (is(typeof(T) == char) || (isArray!T && is(typeof(T[]) == char)

Re: Weird behavior of "this" in a subclass, I think?

2015-07-15 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 16 Jul 2015 00:18:30 + seashell86 via Digitalmars-d-learn wrote: > So I've been mostly just toying around with D as it seems like it > will end up being a strong language for game development both now > and even moreso in the future. That being said, I'm perplexed by > using this

Re: Profile Ouput

2015-07-15 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 13:35:40 UTC, Mike Parker wrote: -- 4000 _Dmain _D4main6selectFZk 40002736471 4000 _D3std6random27__T7uniformVAyaa2_5b29TkTkZ7uniformFNfkkZk -- Got it now. The 2736 and 471 are the call tree time

LNK2019 error from using a function pointer to core.bitop functions?

2015-07-15 Thread Matthew Gamble via Digitalmars-d-learn
This member function of my struct uses a function pointer btx. When the line declaring the function pointer is present I get a LNK2019 error: unresolved external symbol. bool opIndexAssign(bool value, size_t[2] inds) { int function(size_t*, size_t) btx = (value) ? &bts : &btr; // error is her

Re: Weird behavior of "this" in a subclass, I think?

2015-07-15 Thread seashell86 via Digitalmars-d-learn
On Thursday, 16 July 2015 at 00:39:29 UTC, H. S. Teoh wrote: On Thu, Jul 16, 2015 at 12:18:30AM +, seashell86 via Digitalmars-d-learn wrote: [...] The reason is that class variables cannot be overridden, only class methods can. If you want to simulate overriding of class variables, you

Re: Weird behavior of "this" in a subclass, I think?

2015-07-15 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 16 July 2015 at 00:39:29 UTC, H. S. Teoh wrote: If you want to simulate overriding of class variables, you can use a @property method instead: class Animal { @property string voice() { return "Wah!"; } void speak() { writeln(voice); }

Re: Profile Ouput

2015-07-15 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 18:02:11 UTC, jmh530 wrote: I've been confused by this too. The only thing I can find is this http://www.digitalmars.com/ctg/trace.html I think it would be cool to write something that takes the output and puts it in a prettier format. Yeah, I eventually stumb

Re: Weird behavior of "this" in a subclass, I think?

2015-07-15 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jul 16, 2015 at 12:18:30AM +, seashell86 via Digitalmars-d-learn wrote: > So I've been mostly just toying around with D as it seems like it will > end up being a strong language for game development both now and even > moreso in the future. That being said, I'm perplexed by using this

Weird behavior of "this" in a subclass, I think?

2015-07-15 Thread seashell86 via Digitalmars-d-learn
So I've been mostly just toying around with D as it seems like it will end up being a strong language for game development both now and even moreso in the future. That being said, I'm perplexed by using this code and not receiving the result I would imagine. Here is the source code of a basic

Re: Template function that accept strings and array of strings

2015-07-15 Thread Yuxuan Shui via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 21:57:50 UTC, badlink wrote: Hello, I can't figure how to write a template function that accept either strings or array of strings. This is my current code: bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId) if (is(typeof(T) == char) || (isArray!T &&

Re: Template function that accept strings and array of strings

2015-07-15 Thread Vlad Levenfeld via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 21:57:50 UTC, badlink wrote: Hello, I can't figure how to write a template function that accept either strings or array of strings. This is my current code: bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId) if (is(typeof(T) == char) || (isArray!T &&

Template function that accept strings and array of strings

2015-07-15 Thread badlink via Digitalmars-d-learn
Hello, I can't figure how to write a template function that accept either strings or array of strings. This is my current code: bool hasItemParent(T)(const(char)[] itemId, const(T)[] parentId) if (is(typeof(T) == char) || (isArray!T && is(typeof(T[]) == char))) {...} I used const(T)[] becaus

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-15 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 11:45:00 UTC, Laeeth Isharc wrote: Now - is there a way to rewrite my code without mixins? Not sure that is possible. It would be interesting if someone could figure it out though. I'm more focused on making the "givemeabettername" a bit more general. Someone a

Re: Profile Ouput

2015-07-15 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 15 July 2015 at 11:47:53 UTC, Mike Parker wrote: On Tuesday, 14 July 2015 at 13:35:40 UTC, Mike Parker wrote: -- 4000 _Dmain _D4main6selectFZk 40002736471 4000 _D3std6random27__T7uniformVAyaa2_5b29TkTkZ7uniformFNfkkZk --

question about the semantics of unshared variables

2015-07-15 Thread aki via Digitalmars-d-learn
I want to make sure about the semantics of unshared variables. import std.concurrency; import core.thread; ubyte[1024 * 1024] buf1MB; void fun() { Thread.sleep(5000.msecs); } void testThread() { foreach(i; 0..2000) { spawn(&fun); } } Are instances of buf1MB create

Re: Casting random type to random struct - is this a bug?

2015-07-15 Thread Daniel Kozák via Digitalmars-d-learn
On Wed, 15 Jul 2015 15:45:43 + "rumbu" wrote: > struct S { int a, b; } > auto s = cast(S)10; > //compiles and sets s.a to 10. > > It works also for any other type, if the structure contains a > member of that type in the first position. > > Is this normal behaviour? Yes, this is OK If y

Re: Casting random type to random struct - is this a bug?

2015-07-15 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/15/15 11:45 AM, rumbu wrote: struct S { int a, b; } auto s = cast(S)10; //compiles and sets s.a to 10. It works also for any other type, if the structure contains a member of that type in the first position. Is this normal behaviour? I would say this is a bug. As far as I know, it's not

Re: Casting random type to random struct - is this a bug?

2015-07-15 Thread Daniel Kozák via Digitalmars-d-learn
On Wed, 15 Jul 2015 11:57:01 -0400 Steven Schveighoffer wrote: > On 7/15/15 11:45 AM, rumbu wrote: > > struct S { int a, b; } > > auto s = cast(S)10; > > //compiles and sets s.a to 10. > > > > It works also for any other type, if the structure contains a > > member of that type in the first posi

Casting random type to random struct - is this a bug?

2015-07-15 Thread rumbu via Digitalmars-d-learn
struct S { int a, b; } auto s = cast(S)10; //compiles and sets s.a to 10. It works also for any other type, if the structure contains a member of that type in the first position. Is this normal behaviour?

Re: Covariant callback functions, or assigning base class members through a subclass reference

2015-07-15 Thread Jacob Carlborg via Digitalmars-d-learn
On 2015-07-14 17:53, Rene Zwanenburg wrote: Sure, but that would make Base!Derived and Base!AnotherSubClass different types. What I'd like to end up with is a Base[], being able to call foo() on the array members. Other parts of the code will add instances of derived types to this array, and ha

Re: Covariant callback functions, or assigning base class members through a subclass reference

2015-07-15 Thread Ali Çehreli via Digitalmars-d-learn
On 07/14/2015 08:28 AM, Rene Zwanenburg wrote: > But the CallbackType should be able to prevent such unsafe assignments. The following struct applies what others have recommended only if an actual derived type is provided. However, it is still unsafe as the direct assignment to 'callback' cann

Re: Profile Ouput

2015-07-15 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 13:35:40 UTC, Mike Parker wrote: -- 4000 _Dmain _D4main6selectFZk 40002736471 4000 _D3std6random27__T7uniformVAyaa2_5b29TkTkZ7uniformFNfkkZk -- OK, I've finally realized that the top part of trace.

Re: Understanding Safety of Function Pointers vs. Addresses of Functions

2015-07-15 Thread Laeeth Isharc via Digitalmars-d-learn
On Tuesday, 14 July 2015 at 17:24:41 UTC, anonymous wrote: This fails with "Error: None of the overloads of 'cos' are callable using argument types (int[])". The problem is that template mixins cannot add to existing overload sets. The spec says: "If the name of a declaration in a mixin is th

Re: static class vs. static struct

2015-07-15 Thread creiglee via Digitalmars-d-learn
In simple words, Singleton is a pattern and not a keyword. The Singleton pattern has several advantages over static classes. A singleton allows a class for which there is just one, persistent instance across the lifetime of an application. That means, it created a single instance and that insta