Re: Are stack+heap classes possible in D?

2015-06-19 Thread rsw0x via Digitalmars-d-learn
On Friday, 19 June 2015 at 19:10:11 UTC, Shachar Shemesh wrote: On 14/06/15 04:31, Adam D. Ruppe wrote: On Sunday, 14 June 2015 at 00:52:20 UTC, FujiBar wrote: I have read that in D structs are always allocated on the stack while classes are always allocated on the heap. That's not true; it

Re: Are stack+heap classes possible in D?

2015-06-19 Thread Shachar Shemesh via Digitalmars-d-learn
On 14/06/15 04:31, Adam D. Ruppe wrote: On Sunday, 14 June 2015 at 00:52:20 UTC, FujiBar wrote: I have read that in D structs are always allocated on the stack while classes are always allocated on the heap. That's not true; it is a really common misconception. Putting a struct on the heap

Re: Are stack+heap classes possible in D?

2015-06-17 Thread ketmar via Digitalmars-d-learn
On Wed, 17 Jun 2015 06:02:46 +, WhatMeWorry wrote: I guess the question would be why would one want a struct on the heap and a class on the stack? Performance reasons? struct on the heap: some containers, for example, doing their own memory management. class on the stack: guaranteed

Re: Are stack+heap classes possible in D?

2015-06-17 Thread WhatMeWorry via Digitalmars-d-learn
On Sunday, 14 June 2015 at 01:31:25 UTC, Adam D. Ruppe wrote: On Sunday, 14 June 2015 at 00:52:20 UTC, FujiBar wrote: I have read that in D structs are always allocated on the stack while classes are always allocated on the heap. That's not true; it is a really common misconception. Putting

Are stack+heap classes possible in D?

2015-06-13 Thread FujiBar via Digitalmars-d-learn
I have read that in D structs are always allocated on the stack while classes are always allocated on the heap. Well, I often have classes where I want some instances on the stack, some on the heap. So.. what to do?

Re: Are stack+heap classes possible in D?

2015-06-13 Thread FujiBar via Digitalmars-d-learn
On Sunday, 14 June 2015 at 01:31:25 UTC, Adam D. Ruppe wrote: On Sunday, 14 June 2015 at 00:52:20 UTC, FujiBar wrote: I have read that in D structs are always allocated on the stack while classes are always allocated on the heap. That's not true; it is a really common misconception. Putting

Re: Are stack+heap classes possible in D?

2015-06-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 14 June 2015 at 00:52:20 UTC, FujiBar wrote: I have read that in D structs are always allocated on the stack while classes are always allocated on the heap. That's not true; it is a really common misconception. Putting a struct on the heap is trivial and built into the language:

Re: Is this possible in D?

2015-02-19 Thread tcak via Digitalmars-d-learn
On Thursday, 19 February 2015 at 08:24:08 UTC, Jonathan Marler wrote: I am having a heck of a time trying to figure out how to do this. How do I change the attributes of a function based on the version without copying the function body? For example: version(StaticVersion) { static void

Is this possible in D?

2015-02-19 Thread Jonathan Marler via Digitalmars-d-learn
I am having a heck of a time trying to figure out how to do this. How do I change the attributes of a function based on the version without copying the function body? For example: version(StaticVersion) { static void myLongFunction() { // long body ... } } else { void

Re: Is this possible in D?

2015-02-19 Thread John Colvin via Digitalmars-d-learn
On Thursday, 19 February 2015 at 09:38:48 UTC, Mike Parker wrote: On Thursday, 19 February 2015 at 08:24:08 UTC, Jonathan Marler wrote: I am having a heck of a time trying to figure out how to do this. How do I change the attributes of a function based on the version without copying the

Re: Is this possible in D?

2015-02-19 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 19 February 2015 at 08:24:08 UTC, Jonathan Marler wrote: I am having a heck of a time trying to figure out how to do this. How do I change the attributes of a function based on the version without copying the function body? For example: version(StaticVersion) { static void

Re: Is this possible in D?

2015-02-19 Thread Dicebot via Digitalmars-d-learn
Most practical approach I am currently aware of is wrapping actual implementation (in most restrictive version): class Test { private static void foo_() {} version (Static) { static void foo() { foo_(); } } else { void foo() { foo_(); } } private void bar_() shared { } version

Re: Is this possible in D?

2015-02-19 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 19 February 2015 at 10:17:47 UTC, Dicebot wrote: Most practical approach I am currently aware of is wrapping actual implementation (in most restrictive version): I really like mixins for this sort of thing. ``` enum signature = void longFunction(); version( Static ) enum

Re: Is this possible in D?

2015-02-19 Thread Jonathan Marler via Digitalmars-d-learn
On Thursday, 19 February 2015 at 17:23:47 UTC, Mike Parker wrote: I agree that string mixins can kill readability. I encountered that when I used them to support both D1 and D2 in Derelict 2 years ago. But I think that when they are kept small and local as in cases like this, they aren't bad

Re: Is this possible in D?

2015-02-19 Thread tcak via Digitalmars-d-learn
On Thursday, 19 February 2015 at 12:16:18 UTC, Mike Parker wrote: On Thursday, 19 February 2015 at 10:17:47 UTC, Dicebot wrote: Most practical approach I am currently aware of is wrapping actual implementation (in most restrictive version): I really like mixins for this sort of thing. ```

Re: Is this possible in D?

2015-02-19 Thread ketmar via Digitalmars-d-learn
On Thu, 19 Feb 2015 08:24:06 +, Jonathan Marler wrote: I am having a heck of a time trying to figure out how to do this. How do I change the attributes of a function based on the version without copying the function body? For example: version(StaticVersion) { static void

Re: Is this possible in D?

2015-02-19 Thread Mike Parker via Digitalmars-d-learn
On 2/20/2015 1:06 AM, tcak wrote: @OP: By using a token string (q{}) for funcBody rather than a WYSIWYG string (r or ``), you can still get syntax highlighting in your editor. Based on your example, bye bye readibility. It is like writing rocket taking off procedures. People are complaining

Re: Using custom attribute for a general parser. Is possible in D ?

2014-05-26 Thread Ali Çehreli via Digitalmars-d-learn
On 05/23/2014 09:09 AM, bioinfornatics wrote: struct A { @section( ( word ) = word[0] == '@', ( word ) = word[0] == '\n') int a; } I was able to make that work if I used function instead of delegate: import std.stdio; struct attribute { } alias MatchFunc = bool

Re: Using custom attribute for a general parser. Is possible in D ?

2014-05-26 Thread bioinfornatics via Digitalmars-d-learn
On Monday, 26 May 2014 at 19:50:29 UTC, Ali Çehreli wrote: On 05/23/2014 09:09 AM, bioinfornatics wrote: struct A { @section( ( word ) = word[0] == '@', ( word ) = word[0] == '\n') int a; } I was able to make that work if I used function instead of delegate: import

Using custom attribute for a general parser. Is possible in D ?

2014-05-23 Thread bioinfornatics via Digitalmars-d-learn
I bask originally this qustion in this thread : http://forum.dlang.org/post/rsnswykpjfzenpliv...@forum.dlang.org but another thread is better as that is not exactly same topic. I would like to use custom annotate/attribute on members as: struct A { @Parser( start = (