Re: std.conv - custom string to struct conversion ?

2013-08-01 Thread monarch_dodra
On Friday, 2 August 2013 at 05:09:14 UTC, Jonathan M Davis wrote: On Friday, August 02, 2013 06:50:01 Douglas Petterson wrote: Is there a way to convert a string to a struct, similarly to the conversion of a struct to a custom string representation ? The following code works fine when using fo

Re: std.conv - custom string to struct conversion ?

2013-08-01 Thread Jonathan M Davis
On Friday, August 02, 2013 06:50:01 Douglas Petterson wrote: > Is there a way to convert a string to a struct, similarly to the > conversion of a struct to a custom string representation ? > > The following code works fine when using format("%s",C) or > to!string(C): > > struct sCustomConv >

std.conv - custom string to struct conversion ?

2013-08-01 Thread Douglas Petterson
Is there a way to convert a string to a struct, similarly to the conversion of a struct to a custom string representation ? The following code works fine when using format("%s",C) or to!string(C): struct sCustomConv { string toString() { return "My custom r

Re: casts / wildcards for parametrized types

2013-08-01 Thread Ali Çehreli
On 08/01/2013 05:40 PM, tx wrote: > Thanks for the reply Ali. Everything you wrote makes sense, but I > think I may have oversimplified the problem in my original email. In > general I don't care about what T is when working with Box (or > ConcreteBox as it were), but I do care that Box contains

Re: casts / wildcards for parametrized types

2013-08-01 Thread tx
Thanks for the reply Ali. Everything you wrote makes sense, but I think I may have oversimplified the problem in my original email. In general I don't care about what T is when working with Box (or ConcreteBox as it were), but I do care that Box contains a T. Consider this rather contrived example

Get attributes of type by string name

2013-08-01 Thread JS
how can I get the UDA's of a type that I only know by name and only in a CTFE. I would like to loop over an array of names passed to a me(I don't know their contents beforehand) and get the attributes. I've tried to use a mixin but I can't get the mixin to work on the string name... e.g.,

Re: casts / wildcards for parametrized types

2013-08-01 Thread Meta
On Friday, 2 August 2013 at 00:44:21 UTC, Meta wrote: One more way, not necessarily a workaround but a little trick that doesn't require you to know the exact type of box, is to use typeof(box). auto box = Box!int(); auto item = cast(Item)box; auto box2 = cast(typeof(box)); Whoops, make that

Re: casts / wildcards for parametrized types

2013-08-01 Thread Meta
One more way, not necessarily a workaround but a little trick that doesn't require you to know the exact type of box, is to use typeof(box). auto box = Box!int(); auto item = cast(Item)box; auto box2 = cast(typeof(box));

Re: are mixin string templates with functions removed?

2013-08-01 Thread Dicebot
On Thursday, 1 August 2013 at 23:15:47 UTC, Dicebot wrote: On Thursday, 1 August 2013 at 22:59:14 UTC, Dicebot wrote: ... To further clarify this, I have used your simplified example: And in case someone thinks template functions are treated any differently, "string generator(T)(T a)" acts

Re: casts / wildcards for parametrized types

2013-08-01 Thread Ali Çehreli
On 08/01/2013 04:28 PM, tx wrote: > Hi All, > Hoping somebody can provide some help here, I have a set of classes > that are similar to the following > > class Item{} > > class Box(T) : Item { >T value; >// ... > } > > //Along with some aliases: > > alias Box!(long) LongBox; > alias Box!

Re: Homework help, guys!

2013-08-01 Thread John Colvin
On Thursday, 1 August 2013 at 23:48:33 UTC, Timon Gehr wrote: On 08/02/2013 01:34 AM, hunt wrote: Hello, guys. It is weird to ask about my homework here, but I haven't gotten a proper answer yet. It's about D feature...maybe.. http://dpaste.dzfl.pl/905d6ad7 Question is that "Investigate how D

Re: Homework help, guys!

2013-08-01 Thread Timon Gehr
On 08/02/2013 01:34 AM, hunt wrote: Hello, guys. It is weird to ask about my homework here, but I haven't gotten a proper answer yet. It's about D feature...maybe.. http://dpaste.dzfl.pl/905d6ad7 Question is that "Investigate how D allows you to defend your definition of Map so that it may be u

casts / wildcards for parametrized types

2013-08-01 Thread tx
Hi All, Hoping somebody can provide some help here, I have a set of classes that are similar to the following class Item{} class Box(T) : Item { T value; // ... } //Along with some aliases: alias Box!(long) LongBox; alias Box!(char) CharBox; //etc. I'd like to have a function that opera

Homework help, guys!

2013-08-01 Thread hunt
Hello, guys. It is weird to ask about my homework here, but I haven't gotten a proper answer yet. It's about D feature...maybe.. http://dpaste.dzfl.pl/905d6ad7 Question is that "Investigate how D allows you to defend your definition of Map so that it may be used only with a type of key that i

Re: are mixin string templates with functions removed?

2013-08-01 Thread Dicebot
On Thursday, 1 August 2013 at 22:59:14 UTC, Dicebot wrote: ... To further clarify this, I have used your simplified example: - // test.d string generator(int x) { if (x > 0) { asm { mov EAX, 0xDEAD; } } return "return 42;"; } int

Re: are mixin string templates with functions removed?

2013-08-01 Thread Dicebot
On Thursday, 1 August 2013 at 22:42:11 UTC, JS wrote: I don't know why it is so damn confusing... I didn't say templates, I SAID string mixins of templates. Symbol emitting does not go that way. Object files are old school entities from C times. They have function symbol and type symbols. Te

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 22:26:06 UTC, Dicebot wrote: On Thursday, 1 August 2013 at 22:04:57 UTC, JS wrote: IS A GOING TO BE IN THE BINARY?!?!?! Yes, I'm yelling... just to get the point across about the question I'm trying to get answered. HOW MANY TIMES I NEED TO ANSWER YOUR QUESTION F

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 22:13:25 UTC, John Colvin wrote: On Thursday, 1 August 2013 at 22:04:57 UTC, JS wrote: IS A GOING TO BE IN THE BINARY?!?!?! Why don't you try it and see? Disassemble the object file or get your linker of choice to print out some info. I don't have any of the to

Re: are mixin string templates with functions removed?

2013-08-01 Thread Dicebot
On Thursday, 1 August 2013 at 22:04:57 UTC, JS wrote: IS A GOING TO BE IN THE BINARY?!?!?! Yes, I'm yelling... just to get the point across about the question I'm trying to get answered. HOW MANY TIMES I NEED TO ANSWER YOUR QUESTION FOR YOU TO NOTICE? Yes.

Re: are mixin string templates with functions removed?

2013-08-01 Thread John Colvin
On Thursday, 1 August 2013 at 22:04:57 UTC, JS wrote: IS A GOING TO BE IN THE BINARY?!?!?! Why don't you try it and see? Disassemble the object file or get your linker of choice to print out some info.

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 21:17:34 UTC, H. S. Teoh wrote: On Thu, Aug 01, 2013 at 10:06:54PM +0200, JS wrote: [...] Now are you telling me that template A() { void foo() { writeln("asdf"); } } void main() { A!().foo(); } does not create a function foo in the binary? That it is

Re: are mixin string templates with functions removed?

2013-08-01 Thread Dicebot
On Thursday, 1 August 2013 at 21:38:15 UTC, Tofu Ninja wrote: This scares me, it seems to me that the unused import should not be compiled in. And I frequently hear people talk about the linker removing unused code, but this proves that it doesn't or at least not all. It does not. People talk

Re: are mixin string templates with functions removed?

2013-08-01 Thread Tofu Ninja
On Thursday, 1 August 2013 at 20:06:56 UTC, JS wrote: the binary file is is 150kB. If I add import std.stdio; It jumps to 300kB. This scares me, it seems to me that the unused import should not be compiled in. And I frequently hear people talk about the linker removing unused code, but this

Re: are mixin string templates with functions removed?

2013-08-01 Thread H. S. Teoh
On Thu, Aug 01, 2013 at 10:06:54PM +0200, JS wrote: [...] > Now are you telling me that > > template A() > { > void foo() { writeln("asdf"); } > } > void main() > { > A!().foo(); > } > > does not create a function foo in the binary? That it is equivalent > to just calling writeln("asdf"

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 18:09:54 UTC, H. S. Teoh wrote: On Thu, Aug 01, 2013 at 07:52:28PM +0200, JS wrote: On Thursday, 1 August 2013 at 17:47:00 UTC, H. S. Teoh wrote: >On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote: >>On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote: >>

Re: What would be the best way to compile a project with GDC?

2013-08-01 Thread Dicebot
On Thursday, 1 August 2013 at 17:46:07 UTC, Gary Willoughby wrote: There must be a simpler way to pass these files to dmd in the right order? rdmd does it somehow. You do know that you can use GDC with rdmd? `rdmd --compiler=gdmd` afair. Anyway, rdmd does it my checking dmd verbose output th

Re: are mixin string templates with functions removed?

2013-08-01 Thread Dicebot
On Thursday, 1 August 2013 at 18:09:54 UTC, H. S. Teoh wrote: See for yourself: run a disassembler on the result (preferably filtered through ddemangle so the symbols are actually readable) and see what's included and what's not. On Posix, you can use objdump or nm (if you use nm, though, keep

Re: are mixin string templates with functions removed?

2013-08-01 Thread Dicebot
On Thursday, 1 August 2013 at 17:53:38 UTC, Ali Çehreli wrote: I think the question is whether the instantiations of such templates are removed. If the instance is used only to initialize an enum, the function shouldn't stay in the binary. Even if the function remains, I think the linker takes

Re: What would be the best way to compile a project with GDC?

2013-08-01 Thread Johannes Pfau
Am Thu, 01 Aug 2013 19:46:05 +0200 schrieb "Gary Willoughby" : > I've just finished a project in D and have been using rdmd to > compile during testing. While this is nice, i now want to try > other compilers to see if i get any speed gains. > > Because i use rdmd it takes care of passing every

Re: are mixin string templates with functions removed?

2013-08-01 Thread H. S. Teoh
On Thu, Aug 01, 2013 at 07:52:28PM +0200, JS wrote: > On Thursday, 1 August 2013 at 17:47:00 UTC, H. S. Teoh wrote: > >On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote: > >>On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote: > >>>If I have a bunch of templates that are only used for co

Re: are mixin string templates with functions removed?

2013-08-01 Thread John Colvin
On Thursday, 1 August 2013 at 17:57:28 UTC, JS wrote: On Thursday, 1 August 2013 at 17:53:38 UTC, Ali Çehreli wrote: On 08/01/2013 10:45 AM, H. S. Teoh wrote: On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote: On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote: If I have a bunch o

Re: Emulating enums

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 16:36:34 UTC, Ali Çehreli wrote: On 08/01/2013 03:29 AM, JS wrote: > On Thursday, 1 August 2013 at 05:22:46 UTC, Ali Çehreli wrote: >> On 07/31/2013 06:10 PM, JS wrote: >>> http://dpaste.dzfl.pl/dbb40dbc >>> >>> The code was pared down from a lot of string mixin cod

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 17:53:38 UTC, Ali Çehreli wrote: On 08/01/2013 10:45 AM, H. S. Teoh wrote: On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote: On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote: If I have a bunch of templates that are only used for code generation, are

Re: What would be the best way to compile a project with GDC?

2013-08-01 Thread H. S. Teoh
On Thu, Aug 01, 2013 at 07:46:05PM +0200, Gary Willoughby wrote: > I've just finished a project in D and have been using rdmd to > compile during testing. While this is nice, i now want to try other > compilers to see if i get any speed gains. Based on my experience, you will, with gdc / ldc. The

Re: are mixin string templates with functions removed?

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 17:47:00 UTC, H. S. Teoh wrote: On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote: On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote: >If I have a bunch of templates that are only used for code >generation, are they removed in the binary(since they are

Re: are mixin string templates with functions removed?

2013-08-01 Thread Ali Çehreli
On 08/01/2013 10:45 AM, H. S. Teoh wrote: On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote: On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote: If I have a bunch of templates that are only used for code generation, are they removed in the binary(since they are not needed)? templa

What would be the best way to compile a project with GDC?

2013-08-01 Thread Gary Willoughby
I've just finished a project in D and have been using rdmd to compile during testing. While this is nice, i now want to try other compilers to see if i get any speed gains. Because i use rdmd it takes care of passing everything to dmd. Now i want to try GDC and i need to pass the files in the

Re: are mixin string templates with functions removed?

2013-08-01 Thread H. S. Teoh
On Thu, Aug 01, 2013 at 07:12:51PM +0200, John Colvin wrote: > On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote: > >If I have a bunch of templates that are only used for code > >generation, are they removed in the binary(since they are not > >needed)? > > templates don't exist in binaries. Te

Re: are mixin string templates with functions removed?

2013-08-01 Thread John Colvin
On Thursday, 1 August 2013 at 17:09:07 UTC, JS wrote: If I have a bunch of templates that are only used for code generation, are they removed in the binary(since they are not needed)? templates don't exist in binaries.

are mixin string templates with functions removed?

2013-08-01 Thread JS
If I have a bunch of templates that are only used for code generation, are they removed in the binary(since they are not needed)?

Re: Emulating enums

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 16:36:34 UTC, Ali Çehreli wrote: On 08/01/2013 03:29 AM, JS wrote: > On Thursday, 1 August 2013 at 05:22:46 UTC, Ali Çehreli wrote: >> On 07/31/2013 06:10 PM, JS wrote: >>> http://dpaste.dzfl.pl/dbb40dbc >>> >>> The code was pared down from a lot of string mixin cod

Re: Emulating enums

2013-08-01 Thread Ali Çehreli
On 08/01/2013 03:29 AM, JS wrote: > On Thursday, 1 August 2013 at 05:22:46 UTC, Ali Çehreli wrote: >> On 07/31/2013 06:10 PM, JS wrote: >>> http://dpaste.dzfl.pl/dbb40dbc >>> >>> The code was pared down from a lot of string mixin code generation. I >>> nest the structs because I want a nested enu

Re: instantiate each of a tuple of templates (Take 2)

2013-08-01 Thread John Colvin
On Thursday, 1 August 2013 at 15:06:50 UTC, Artur Skawina wrote: On 08/01/13 14:50, John Colvin wrote: template a(T ...) { void a(R r) { //want to get a tuple of //the members of T, each //instantiated with R. //do some RT stuff } } Is this possible?

Re: instantiate each of a tuple of templates (Take 2)

2013-08-01 Thread John Colvin
On Thursday, 1 August 2013 at 14:57:07 UTC, monarch_dodra wrote: On Thursday, 1 August 2013 at 12:50:42 UTC, John Colvin wrote: template a(T ...) { void a(R r) { //want to get a tuple of //the members of T, each //instantiated with R. //do some RT stuff } }

Re: instantiate each of a tuple of templates (Take 2)

2013-08-01 Thread Artur Skawina
On 08/01/13 14:50, John Colvin wrote: > template a(T ...) > { > void a(R r) > { > //want to get a tuple of > //the members of T, each > //instantiated with R. > > //do some RT stuff > } > } > > Is this possible? > > Whatever I try, I keep running in to

Re: instantiate each of a tuple of templates (Take 2)

2013-08-01 Thread monarch_dodra
On Thursday, 1 August 2013 at 12:50:42 UTC, John Colvin wrote: template a(T ...) { void a(R r) { //want to get a tuple of //the members of T, each //instantiated with R. //do some RT stuff } } Is this possible? Whatever I try, I keep running in to "c

Re: std.container: RedBlackTree questions

2013-08-01 Thread monarch_dodra
On Thursday, 1 August 2013 at 12:27:51 UTC, Ivan Kazmenko wrote: Hi! The key points of this lengthy letter are: (0) I find RedBlackTree hard to use, and below is one story of trying to get it to work. (1) Perhaps I did something wrong a few times. Please show me a better way to go. (2) P

Re: instantiate each of a tuple of templates (Take 2)

2013-08-01 Thread Dicebot
On Thursday, 1 August 2013 at 12:50:42 UTC, John Colvin wrote: ... Does this help http://dpaste.dzfl.pl/fe533f7a ?

Re: instantiate each of a tuple of templates (Take 2)

2013-08-01 Thread monarch_dodra
On Thursday, 1 August 2013 at 12:50:42 UTC, John Colvin wrote: template a(T ...) { void a(R r) { //want to get a tuple of //the members of T, each //instantiated with R. //do some RT stuff } } Is this possible? Whatever I try, I keep running in to "c

Re: std.container: RedBlackTree questions

2013-08-01 Thread Ivan Kazmenko
On Thursday, 1 August 2013 at 12:55:30 UTC, John Colvin wrote: On Thursday, 1 August 2013 at 12:27:51 UTC, Ivan Kazmenko wrote: On a relevant note, I find the unittests of RedBlackTree a bit excessive even when they compile successfully. They seem to test the integrity of the whole tree every

Re: Profiling graph library

2013-08-01 Thread Joseph Rushton Wakeling
On 08/01/2013 01:56 PM, bearophile wrote: > I have not critiqued linear flow programming its, I love it and perhaps I was > the one that has introduced it in D. In the main D newsgroup I have just said > that in D it still causes some performance loss, even using ldc2. That's what I meant -- your

Re: std.container: RedBlackTree questions

2013-08-01 Thread John Colvin
On Thursday, 1 August 2013 at 12:27:51 UTC, Ivan Kazmenko wrote: On a relevant note, I find the unittests of RedBlackTree a bit excessive even when they compile successfully. They seem to test the integrity of the whole tree every time a tree operation takes place, and that makes the unittests

instantiate each of a tuple of templates (Take 2)

2013-08-01 Thread John Colvin
template a(T ...) { void a(R r) { //want to get a tuple of //the members of T, each //instantiated with R. //do some RT stuff } } Is this possible? Whatever I try, I keep running in to "cannot use local as parameter to non-global template" errors, wh

instantiate a tuple of templates

2013-08-01 Thread John Colvin
Say I have a template template A(T ...) { void A }

Re: instantiate a tuple of templates

2013-08-01 Thread John Colvin
On Thursday, 1 August 2013 at 12:43:21 UTC, John Colvin wrote: Say I have a template template A(T ...) { void A } woops sorry, partial post. Will finish and post again.

Re: Named UDA's

2013-08-01 Thread Dicebot
On Thursday, 1 August 2013 at 11:02:00 UTC, JS wrote: Anyways, Just an idea I had when trying to make attributes more useful. struct Name { string data; } @Name("hello") void foo(); I favor this approach much more because of strong typing.

std.container: RedBlackTree questions

2013-08-01 Thread Ivan Kazmenko
Hi! The key points of this lengthy letter are: (0) I find RedBlackTree hard to use, and below is one story of trying to get it to work. (1) Perhaps I did something wrong a few times. Please show me a better way to go. (2) Perhaps the library code could be improved as well to make the pro

Re: Profiling graph library

2013-08-01 Thread bearophile
Joseph Rushton Wakeling: So, your critiques of component programming certainly have merit on the performance side. I have not critiqued linear flow programming its, I love it and perhaps I was the one that has introduced it in D. In the main D newsgroup I have just said that in D it still ca

Named UDA's

2013-08-01 Thread JS
I guess D doesn't support named UDA's directly? e.g., @(Name = "My Name", Other = .34) It would be nice to have the ability to have an "attribute" hierarchy where looking up attributes on objects could easily be done. e.g., @(Name = "s", Other = 2) struct s { @(Name = "q", Default_Valu

Re: Profiling graph library

2013-08-01 Thread Joseph Rushton Wakeling
On 07/31/2013 02:31 PM, bearophile wrote: > If this resulting array is used only for a short period of time: > > return sequence.map!(x => x.func).array; Just to compare, I tried rewriting the cacheing version of the neighbours() function to use this kind of sequence. Here's the original code: h

Re: Emulating enums

2013-08-01 Thread JS
On Thursday, 1 August 2013 at 05:22:46 UTC, Ali Çehreli wrote: On 07/31/2013 06:10 PM, JS wrote: http://dpaste.dzfl.pl/dbb40dbc The code was pared down from a lot of string mixin code generation. I nest the structs because I want a nested enums. I don't want have to have eState and eStateTyp

Re: Mysql - Sql things ?

2013-08-01 Thread Larry
On Wednesday, 31 July 2013 at 12:09:02 UTC, David wrote: https://github.com/rejectedsoftware/mysql-native Waw ! Many thanks, Completely missed it :) See you