Re: can't I use __traits(allMembers) recursivly ?

2014-01-23 Thread Jacob Carlborg
On 2014-01-24 07:11, Uplink_Coder wrote: I'm trying to serialize my struct through CT-Refelction Here's a serialization library if you need it [1]. It will hopefully be included as std.serialization in Phobos at some point. https://github.com/jacob-carlborg/orange -- /Jacob Carlborg

Re: can't I use __traits(allMembers) recursivly ?

2014-01-23 Thread Uplink_Coder
I'm trying to serialize my struct through CT-Refelction

Re: TLF = thread local functions

2014-01-23 Thread dennis luehring
Am 23.01.2014 15:44, schrieb Frustrated: So, TLS solves the data issue with threading. I just thought, with out much thinking, what about having thread local functions? Doesn't make sense? Let me explain. Functions generally are not thread safe because of reentry, right? The same data is used by

Re: Why is string.front dchar?

2014-01-23 Thread Jakob Ovrum
On Thursday, 23 January 2014 at 10:25:40 UTC, Timon Gehr wrote: Sure. Their existence means it is in general wrong to think of a dchar as one character. As stated, I was specifically talking about the Unicode definition of a character, which is completely distinct from graphemes.

Re: Python calling D

2014-01-23 Thread Ellery Newcomer
On Monday, 20 January 2014 at 02:30:46 UTC, CJS wrote: For future reference, I tried but wasn't able to make calling D from python work. I tried to just compile D to an .a library, including statically linking phobos, and then wrapping it with cython like I would with C code. (I've made this

Re: Shared objects aka dynamic libraries

2014-01-23 Thread Mineko
On Tuesday, 21 January 2014 at 14:19:51 UTC, Russel Winder wrote: I appear to be unable to use Google the last couple of days :-( so I admit defeat, expose my current ignorance, hopefully to quickly become enlightened. Is it possible to easily with DMD, LDC and/or GDC create shared objects a

Re: User defined types: Problems with ref

2014-01-23 Thread Ali Çehreli
On 01/23/2014 07:26 AM, Chris wrote: > On Thursday, 23 January 2014 at 15:24:19 UTC, Chris wrote: >> Here's what I'm trying to do. >> >> struct Element(T) { >> T x; >> T y; >> >> public void setX(T value) { >> x = value; >> } >> // More fancy functions ... >> } >> >> I s

Re: User defined types: Problems with ref

2014-01-23 Thread FreeSlave
Anyway, why do you need pointers to elements?

Re: User defined types: Problems with ref

2014-01-23 Thread FreeSlave
On Thursday, 23 January 2014 at 15:24:19 UTC, Chris wrote: Thanks, that was fast! Yes I was tinkering around with pointers, but didn't get it right, you did. However, the output is still the same, i.e. two different sets: // After creating and changing Hello, world! // The Elements in Tr

Re: can't I use __traits(allMembers) recursivly ?

2014-01-23 Thread Tobias Pankrath
On Thursday, 23 January 2014 at 23:42:26 UTC, Uplink_Coder wrote: When I try to struct _pod_ { string s1; enum e1 { v1,v2 }; } auto printPod(Pod)() if (__traits(isPOD,Pod)) { string result; foreach (member;__traits(allMembers,Pod) ) { auto _member=__traits(ge

can't I use __traits(allMembers) recursivly ?

2014-01-23 Thread Uplink_Coder
When I try to struct _pod_ { string s1; enum e1 { v1,v2 }; } auto printPod(Pod)() if (__traits(isPOD,Pod)) { string result; foreach (member;__traits(allMembers,Pod) ) { auto _member=__traits(getMember,Pod,member); } writeln(result); } void main

Re: Shared objects aka dynamic libraries

2014-01-23 Thread Dicebot
On Thursday, 23 January 2014 at 19:40:42 UTC, Kagamin wrote: On Tuesday, 21 January 2014 at 17:53:38 UTC, Russel Winder It's linux users, who use linux. Windows users don't use windows for anything, they use software running on windows, lol. It awesome how this statement can be read as both li

Re: Shared objects aka dynamic libraries

2014-01-23 Thread Kagamin
On Tuesday, 21 January 2014 at 17:53:38 UTC, Russel Winder wrote: I'll have to get my wife's Windows 7 machine out to test all the D tool changes I am making. It is a real shame that anyone actually uses Windows for anything :-) It's linux users, who use linux. Windows users don't use windows

Re: shared methods

2014-01-23 Thread Kagamin
A minor caveat is GDC treats shared as volatile, which can be not optimal. Even worse, on some platforms like itanium volatile generates fences.

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Uplink_Coder
Great now it works! Thanks for your time :D

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Stanislav Blinov
On Thursday, 23 January 2014 at 17:59:05 UTC, Uplink_Coder wrote: First and foremost, I'd suggest you use the beautiful solution proposed by Meta. But to illustrate problems with your code: foreach (i,Item;[__traits(allMembers,Enum)]) { This is the culprit. More specifically, you don't n

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Uplink_Coder
Oh my bad wasn't too carefull with deletion auto EnumToSelect(Enum)(string Name = __traits(identifier,Enum)) if (is(Enum==enum)) { foreach (i,Item;[__traits(allMembers,Enum)]) { reslt ~= "\toption(value='"~__traits(getMember,Enum,Item)~"') "~Item~"\n"; } debug import std.stdio; debug

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Uplink_Coder
Could you show an exact code that fails? sure! auto EnumToSelect(Enum)(string Name = __traits(identifier,Enum)) if (is(Enum==enum)) { foreach (i,Item;[__traits(allMembers,Enum)]) { else form_string ~= "\toption(value='"~Item~"') "~__traits(getMember,Enum,It

Re: "Best" way of handling a receive()d message with a class instance.

2014-01-23 Thread Meta
On Thursday, 23 January 2014 at 16:00:30 UTC, Francesco Cattoglio wrote: Sorry, MY BAD! You can just write auto handler = new Handler; receive(&handler.MyFunc); Somehow when I tried this before it failed to compile, and I thought I had to go through loops for achieving this. It's also useful

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Meta
On Thursday, 23 January 2014 at 15:07:18 UTC, Uplink_Coder wrote: Hello, I have an Enum to represent possible Options for a selectList e.g enum options { blueish="Blue", redish ="Red" } and I want the List-Entrys to say "blueish" or "redish". the value send to the app should be "Blue" or "Re

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Uplink_Coder
void main() { foreach(m; EnumMembers!Options) { writeln(m, " ", cast(string)m); } } Still not there at compile-time ... because I need to index my members

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Stanislav Blinov
On Thursday, 23 January 2014 at 17:15:41 UTC, Uplink_Coder wrote: void main() { foreach(m; EnumMembers!Options) { writeln(m, " ", cast(string)m); } } Still not there at compile-time ... because I need to index my members Could you show an exact code that fails?

Re: Compare type with another at CT

2014-01-23 Thread Stanislav Blinov
On Thursday, 23 January 2014 at 16:40:49 UTC, Frustrated wrote: Yes, I that is what I tried initially but the error was due to that static if. Not sure why but static if (is(T : A)) { ... } static assert(0,

Re: TLF = thread local functions

2014-01-23 Thread David Nadlinger
On Thursday, 23 January 2014 at 16:15:46 UTC, Frustrated wrote: The point is that making the **STACK** TLS too should a way around having to use synchronization. Precisely because the STACK is not TLS makes functions not thread safe(since data is already "safe" in d). Maybe you could elabora

Re: Compare type with another at CT

2014-01-23 Thread Frustrated
Yes, I that is what I tried initially but the error was due to that static if. Not sure why but static if (is(T : A)) { ... } static assert(0, "error"); doesn't work as the assert is called no matter what.

Re: TLF = thread local functions

2014-01-23 Thread Stanislav Blinov
On Thursday, 23 January 2014 at 16:15:46 UTC, Frustrated wrote: On Thursday, 23 January 2014 at 14:49:11 UTC, Dicebot wrote: On Thursday, 23 January 2014 at 14:44:01 UTC, Frustrated wrote: Precisely because the STACK is not TLS makes functions not thread safe(since data is already "safe" in

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Stanislav Blinov
On Thursday, 23 January 2014 at 15:31:53 UTC, Uplink_Coder wrote: Try getMember: http://dlang.org/traits.html#getMember if i try it, I get __aggr2297 cannot be read at compile time There's a convenience wrapper for that, EnumMembers: http://dlang.org/phobos/std_traits.html#.EnumMembers void

Re: Compare type with another at CT

2014-01-23 Thread Adam D. Ruppe
On Thursday, 23 January 2014 at 16:21:39 UTC, Frustrated wrote: static if (T is A) Try: static if(is(T : A)) {} The is() thingy is different than the is operator. T:A means "T implicitly converts to A", so if T is a class implementing interface A, that would pass. There's

Compare type with another at CT

2014-01-23 Thread Frustrated
I am trying to compare a type with another type at compile time. My code is class Q(T) { static auto foo() { static if (T is A) { ... } static assert(0, "error"); } } and get the error "

Re: TLF = thread local functions

2014-01-23 Thread Frustrated
On Thursday, 23 January 2014 at 14:49:11 UTC, Dicebot wrote: On Thursday, 23 January 2014 at 14:44:01 UTC, Frustrated wrote: Functions generally are not thread safe because of reentry, right? No. They are not thread safe because they use shared data (explicitly/implicitly). Functions that onl

Re: "Best" way of handling a receive()d message with a class instance.

2014-01-23 Thread Francesco Cattoglio
Sorry, MY BAD! You can just write auto handler = new Handler; receive(&handler.MyFunc); Somehow when I tried this before it failed to compile, and I thought I had to go through loops for achieving this.

Re: User defined types: Problems with ref

2014-01-23 Thread Chris
On Thursday, 23 January 2014 at 15:34:38 UTC, FreeSlave wrote: On Thursday, 23 January 2014 at 15:24:19 UTC, Chris wrote: Here's what I'm trying to do. struct Element(T) { T x; T y; public void setX(T value) { x = value; } // More fancy functions ... } I store Element(s) i

"Best" way of handling a receive()d message with a class instance.

2014-01-23 Thread Francesco Cattoglio
Suppose that I receive a message, but instead of defining a function inside the receive() block, I want to call a member of a class instance. (This is useful to me for several reasons). Right now my code looks like: class Handler { auto handle() { return (string msg) { writeln("rec

Re: User defined types: Problems with ref

2014-01-23 Thread FreeSlave
On Thursday, 23 January 2014 at 15:24:19 UTC, Chris wrote: Here's what I'm trying to do. struct Element(T) { T x; T y; public void setX(T value) { x = value; } // More fancy functions ... } I store Element(s) in an array and want to pass each one by reference, which

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Uplink_Coder
Try getMember: http://dlang.org/traits.html#getMember if i try it, I get __aggr2297 cannot be read at compile time

Re: User defined types: Problems with ref

2014-01-23 Thread Chris
On Thursday, 23 January 2014 at 15:24:19 UTC, Chris wrote: Here's what I'm trying to do. struct Element(T) { T x; T y; public void setX(T value) { x = value; } // More fancy functions ... } I store Element(s) in an array and want to pass each one by reference, which

User defined types: Problems with ref

2014-01-23 Thread Chris
Here's what I'm trying to do. struct Element(T) { T x; T y; public void setX(T value) { x = value; } // More fancy functions ... } I store Element(s) in an array and want to pass each one by reference, which does not work. class Tree { Element!string[] element

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Jacob Carlborg
On 2014-01-23 16:07, Uplink_Coder wrote: Hello, I have an Enum to represent possible Options for a selectList e.g enum options { blueish="Blue", redish ="Red" } and I want the List-Entrys to say "blueish" or "redish". the value send to the app should be "Blue" or "Red". I can use __traits(

Re: Ddoc

2014-01-23 Thread Rikki Cattermole
On Thursday, 23 January 2014 at 15:00:17 UTC, sg wrote: On Thursday, 23 January 2014 at 14:25:41 UTC, Rikki Cattermole wrote: On Thursday, 23 January 2014 at 13:57:43 UTC, sg wrote: Ddoc itself is provided as part of the D compiler. For usage with D source code. Following is from http://d

Re: getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Rikki Cattermole
On Thursday, 23 January 2014 at 15:07:18 UTC, Uplink_Coder wrote: Hello, I have an Enum to represent possible Options for a selectList e.g enum options { blueish="Blue", redish ="Red" } and I want the List-Entrys to say "blueish" or "redish". the value send to the app should be "Blue" or "Re

getting Key:Value pairs of an enum at compile time ?

2014-01-23 Thread Uplink_Coder
Hello, I have an Enum to represent possible Options for a selectList e.g enum options { blueish="Blue", redish ="Red" } and I want the List-Entrys to say "blueish" or "redish". the value send to the app should be "Blue" or "Red". I can use __traits(allMembers,Enum) for the identifiers, but ho

Re: Ddoc

2014-01-23 Thread sg
On Thursday, 23 January 2014 at 14:25:41 UTC, Rikki Cattermole wrote: On Thursday, 23 January 2014 at 13:57:43 UTC, sg wrote: Ddoc itself is provided as part of the D compiler. For usage with D source code. Following is from http://dlang.org/ddoc.html Using Ddoc for other Documentation D

Re: TLF = thread local functions

2014-01-23 Thread Dicebot
On Thursday, 23 January 2014 at 14:44:01 UTC, Frustrated wrote: Functions generally are not thread safe because of reentry, right? No. They are not thread safe because they use shared data (explicitly/implicitly). Functions that only use thread-local data are always thread-safe.

TLF = thread local functions

2014-01-23 Thread Frustrated
So, TLS solves the data issue with threading. I just thought, with out much thinking, what about having thread local functions? Doesn't make sense? Let me explain. Functions generally are not thread safe because of reentry, right? The same data is used by the function for each thread calling it a

Re: Ddoc

2014-01-23 Thread Rikki Cattermole
On Thursday, 23 January 2014 at 13:57:43 UTC, sg wrote: I have looked at http://dlang.org/ddoc.html and http://qznc.github.io/d-tut/documentation.html and have some idea about how to write the text that will eventually become the document. But I have no clue as to go from the input file wit

Ddoc

2014-01-23 Thread sg
I have looked at http://dlang.org/ddoc.html and http://qznc.github.io/d-tut/documentation.html and have some idea about how to write the text that will eventually become the document. But I have no clue as to go from the input file with Ddoc comments to the final document. I am on Windows 7

Re: Why is string.front dchar?

2014-01-23 Thread Timon Gehr
On 01/23/2014 02:39 AM, Jakob Ovrum wrote: On Thursday, 23 January 2014 at 01:17:19 UTC, Timon Gehr wrote: On 01/16/2014 06:56 AM, Jakob Ovrum wrote: Note that the Unicode definition of an unqualified "character" is the translation of a code *point*, which is very different from a *glyph*, whi