Re: Finding UDAs with Templates

2013-07-22 Thread Jacob Carlborg
On 2013-07-23 06:27, Paul O'Neil wrote: I'm trying to write some code that finds all the members of a class that have a particular user defined attribute. My current attempt is at https://github.com/todayman/d_template_experiments/tree/8fccd27d7d5557ec6e2f0614374cf5f79fe80b4c I would like to h

Finding UDAs with Templates

2013-07-22 Thread Paul O'Neil
I'm trying to write some code that finds all the members of a class that have a particular user defined attribute. My current attempt is at https://github.com/todayman/d_template_experiments/tree/8fccd27d7d5557ec6e2f0614374cf5f79fe80b4c I would like to have a static method that returns an arra

Re: Unwanted conflict

2013-07-22 Thread Jonathan M Davis
On Tuesday, July 23, 2013 05:42:10 Carl Sturtivant wrote: > On Sunday, 21 July 2013 at 18:37:23 UTC, Jonathan M Davis wrote: > > On Sunday, July 21, 2013 16:25:15 Carl Sturtivant wrote: > >> That's too bad, because in the real code this example was > >> derived > >> from I can't have type inference

Re: Unwanted conflict

2013-07-22 Thread Carl Sturtivant
On Sunday, 21 July 2013 at 18:37:23 UTC, Jonathan M Davis wrote: On Sunday, July 21, 2013 16:25:15 Carl Sturtivant wrote: That's too bad, because in the real code this example was derived from I can't have type inference call the right constructor as there are two constructors with the same run

Re: Floating point minimum values are positive?

2013-07-22 Thread Ali Çehreli
On 07/22/2013 03:53 PM, bearophile wrote: > Ali Çehreli: > >> Going off topic, why not -w then? If I want to be warned about >> something, I don't want the program to be compiled anyway but perhaps >> others want to look at warning messages. :) > > There are discussions like this: > http://d.pure

Re: Why is size_t unsigned?

2013-07-22 Thread Maxim Fomin
On Monday, 22 July 2013 at 21:08:48 UTC, bearophile wrote: So the standard idiom to use foreach on interval needs to be: foreach (immutable i; 0 .. 10) { ... } Bye, bearophile This comes with another issue embedded here http://forum.dlang.org/thread/felqszcrbvtrepjtf...@forum.dlang.org

Re: std.algorithm set operations on SortedRanges only?

2013-07-22 Thread Jesse Phillips
On Monday, 22 July 2013 at 21:22:42 UTC, bearophile wrote: Given all that, isn't it good to have the "Set operations" (that actually work on _sorted bags_, so their name is misleading and probably even wrong) of std.algorithm, like std.algorithm.setDifference accept only SortedRanges? SetDiff

Re: Code generation tricks

2013-07-22 Thread JS
On Monday, 22 July 2013 at 21:04:42 UTC, John Colvin wrote: On Sunday, 21 July 2013 at 17:24:11 UTC, JS wrote: This seems to be a somewhat efficient string splitter http://dpaste.dzfl.pl/4307aa5f The basic idea is for(int j = 0; j < s.length; j++) { mixin(ExpandVariadicIf!("??Cs[j]?

Re: Code generation tricks

2013-07-22 Thread JS
On Monday, 22 July 2013 at 21:04:42 UTC, John Colvin wrote: On Sunday, 21 July 2013 at 17:24:11 UTC, JS wrote: This seems to be a somewhat efficient string splitter http://dpaste.dzfl.pl/4307aa5f The basic idea is for(int j = 0; j < s.length; j++) { mixin(ExpandVariadicIf!("??Cs[j]?

Re: Floating point minimum values are positive?

2013-07-22 Thread bearophile
Ali Çehreli: Going off topic, why not -w then? If I want to be warned about something, I don't want the program to be compiled anyway but perhaps others want to look at warning messages. :) There are discussions like this: http://d.puremagic.com/issues/show_bug.cgi?id=10147 Bye, bearophile

Re: Floating point minimum values are positive?

2013-07-22 Thread Ali Çehreli
On 07/22/2013 02:13 PM, bearophile wrote: > Please always compile all your D code with the "-wi" switch Going off topic, why not -w then? If I want to be warned about something, I don't want the program to be compiled anyway but perhaps others want to look at warning messages. :) Ali

Re: Floating point minimum values are positive?

2013-07-22 Thread bearophile
Joseph Rushton Wakeling: It so happens that for the code in question I did, and had got that warning, and made the switch. I just hadn't realized that in either case the value would be positive! I just noticed because of a case where I was initializing a value to real.min_normal and then taki

Re: Floating point minimum values are positive?

2013-07-22 Thread Joseph Rushton Wakeling
On Monday, 22 July 2013 at 21:13:49 UTC, bearophile wrote: Please always compile all your D code with the "-wi" switch, because Walter is deaf at my suggestions to have informational warnings active on default in D compilations :-) It so happens that for the code in question I did, and had got

std.algorithm set operations on SortedRanges only?

2013-07-22 Thread bearophile
In Phobos we have std.range.assumeSorted, std.algorithm.isSorted, and various sort() functions that return a SortedRange. If you call a release() on a SortedRange you get the range that's under it (often an array). (A SortedRange was so far only a RandomAccessRange, but I've shown Andrei that

Re: Floating point minimum values are positive?

2013-07-22 Thread bearophile
Joseph Rushton Wakeling: I just realized that while e.g. int.min gives a negative value, the floating point equivalent, e.g. double.min, gives a very small positive value -- I guess the smallest possible positive value. Please always compile all your D code with the "-wi" switch, because Wa

Re: Floating point minimum values are positive?

2013-07-22 Thread H. S. Teoh
On Mon, Jul 22, 2013 at 11:02:28PM +0200, Joseph Rushton Wakeling wrote: > Always amusing to run into those little quirks of parts of the > language you've never worked with before ... > > I just realized that while e.g. int.min gives a negative value, the > floating point equivalent, e.g. double.

Re: Why is size_t unsigned?

2013-07-22 Thread bearophile
Andrej Mitrovic: Actually it used to be a bug that writing to the index /without/ ref would end up changing the iteration order, but this was fixed in 2.063. It's in the changelog: http://dlang.org/changelog.html#foreachref The right design in my opinion is to have the iteration variable im

Re: Floating point minimum values are positive?

2013-07-22 Thread John Colvin
On Monday, 22 July 2013 at 21:02:30 UTC, Joseph Rushton Wakeling wrote: Always amusing to run into those little quirks of parts of the language you've never worked with before ... I just realized that while e.g. int.min gives a negative value, the floating point equivalent, e.g. double.min, gi

Re: Code generation tricks

2013-07-22 Thread John Colvin
On Sunday, 21 July 2013 at 17:24:11 UTC, JS wrote: This seems to be a somewhat efficient string splitter http://dpaste.dzfl.pl/4307aa5f The basic idea is for(int j = 0; j < s.length; j++) { mixin(ExpandVariadicIf!("??Cs[j]??s[j..min(s.length-1, j + %%L)]::", "d", "

Floating point minimum values are positive?

2013-07-22 Thread Joseph Rushton Wakeling
Always amusing to run into those little quirks of parts of the language you've never worked with before ... I just realized that while e.g. int.min gives a negative value, the floating point equivalent, e.g. double.min, gives a very small positive value -- I guess the smallest possible positiv

Re: Why is size_t unsigned?

2013-07-22 Thread John Colvin
On Monday, 22 July 2013 at 16:29:39 UTC, Maxim Fomin wrote: This also compiles, but I used a different aggregate, yet represents the same thing. Because it is implemented differently, I get a completely different result. Unless I'm mistaken, when a result depends on the implementation, and the

Re: Why is size_t unsigned?

2013-07-22 Thread Andrej Mitrovic
On 7/22/13, monarch_dodra wrote: > 99% sure that's unspecified behavior. I wouldn't rely on anything > like that. Actually it used to be a bug that writing to the index /without/ ref would end up changing the iteration order, but this was fixed in 2.063. It's in the changelog: http://dlang.org/c

Re: Often repeated array allocations

2013-07-22 Thread Namespace
On Monday, 22 July 2013 at 09:26:33 UTC, David wrote: Am 22.07.2013 10:41, schrieb Namespace: It's part of Dgame and it's the shape draw method. The method collects the vertices and give them to the vertex buffer. I will try it with my current way: static stack buffer with a size of 1024 and o

Re: Link problem with Derelict3

2013-07-22 Thread truc
Justin Whear wrote: > On Mon, 22 Jul 2013 20:07:28 +0200, moechofe wrote: > >> Hi, >> >> I have a problem when I try to compile Derelict3 under linux. I try >> different orders of the linked libraries without success. >> >> I've got this error: >> >> /home/martin/Derelict3/lib/dmd/libDerelictS

Re: Are properties actually all that good?

2013-07-22 Thread Dicebot
On Monday, 22 July 2013 at 18:08:15 UTC, Jesse Phillips wrote: I disagree, those discussions were about @property, they had very little to do with accessor methods (getX setY). Most of the discussion was on how to add properties into the language where disagreement was around if optional parens

Re: Link problem with Derelict3

2013-07-22 Thread Justin Whear
On Mon, 22 Jul 2013 20:07:28 +0200, moechofe wrote: > Hi, > > I have a problem when I try to compile Derelict3 under linux. I try > different orders of the linked libraries without success. > > I've got this error: > > /home/martin/Derelict3/lib/dmd/libDerelictSDL2.a(sdl_106_698.o):(.rodata +0x

Re: Do threads 'end' themselves using core.thread?

2013-07-22 Thread Sean Kelly
On Jul 22, 2013, at 10:25 AM, Alex Horvat wrote: > On Monday, 22 July 2013 at 16:58:00 UTC, Sean Kelly wrote: >> On Jul 22, 2013, at 9:45 AM, "Alex Horvat" wrote: >> When a detached thread terminates, its resources are auto- matically released back to the system:" >>> Sound

Link problem with Derelict3

2013-07-22 Thread moechofe
Hi, I have a problem when I try to compile Derelict3 under linux. I try different orders of the linked libraries without success. I've got this error: /home/martin/Derelict3/lib/dmd/libDerelictSDL2.a(sdl_106_698.o):(.rodata+0x3094): référence indéfinie vers « _D6object6Object8opEqualsMFC6Obj

Re: Are properties actually all that good?

2013-07-22 Thread Jesse Phillips
On Monday, 22 July 2013 at 17:27:02 UTC, Dicebot wrote: On Monday, 22 July 2013 at 17:15:53 UTC, Jesse Phillips wrote: Use properties. You'll find it more common in other D code. Whether you use a field or a method is up to you, I suspect using method will be more common. As multiple property

Re: Why is size_t unsigned?

2013-07-22 Thread Marco Leise
Am Mon, 22 Jul 2013 05:47:34 +0200 schrieb "JS" : > Doing simple stuff like > > for(int i = 0; i < s.length - 1; i++) fails catastrophically if s > is empty. To make right one has to reduce performance by writing > extra checks. And my opinion on the matter is that it is catastrophic style to

Re: Do threads 'end' themselves using core.thread?

2013-07-22 Thread Alex Horvat
On Monday, 22 July 2013 at 16:58:00 UTC, Sean Kelly wrote: On Jul 22, 2013, at 9:45 AM, "Alex Horvat" wrote: When a detached thread terminates, its resources are auto- matically released back to the system:" Sounds like I can call Thread.getThis().thread_detachThis() from within Dela

Re: Are properties actually all that good?

2013-07-22 Thread Dicebot
On Monday, 22 July 2013 at 17:15:53 UTC, Jesse Phillips wrote: Use properties. You'll find it more common in other D code. Whether you use a field or a method is up to you, I suspect using method will be more common. As multiple property threads have shown this is a _very_ varying preference

Re: GktD: exceptions in handlers cause segfaults.

2013-07-22 Thread Marco Leise
Am Fri, 19 Jul 2013 21:43:38 +0200 schrieb Johannes Pfau : > Am Fri, 19 Jul 2013 12:38:45 +0200 > schrieb Marco Leise : > > Would be nice to know if this is working with gdc or ldc. In theory it > should work as we use gcc's exception handling/stack unwinding so it's > probably a dmd bug. That's

Re: Are properties actually all that good?

2013-07-22 Thread Dicebot
On Monday, 22 July 2013 at 15:07:29 UTC, Land wrote: I was just thinking about properties and to be honest, I don't like them all that much. There's no way to tell if it's a read-only or write-only property (right?), but getValue and setValue are pretty self-explanatory. After many discussion I

Re: Are properties actually all that good?

2013-07-22 Thread Jesse Phillips
On Monday, 22 July 2013 at 16:42:57 UTC, Land wrote: Thank you for the replies. So, what's the bottom line? Should I use accessor methods or should I use properties? (I've read quite a bit of the mentioned 500-post topic, by the way, but I'm still not clear on what's the most logical step here)

Re: Do threads 'end' themselves using core.thread?

2013-07-22 Thread Alex Horvat
When a detached thread terminates, its resources are auto- matically released back to the system:" Sounds like I can call Thread.getThis().thread_detachThis() from within DelayedHideTitle() and that will make the thread detached and therefore it will destroy itself properly. Or, if tha

Re: Do threads 'end' themselves using core.thread?

2013-07-22 Thread Sean Kelly
On Jul 22, 2013, at 9:45 AM, "Alex Horvat" wrote: >> >> When a detached thread terminates, its resources are auto- matically >> released back to the system:" > > Sounds like I can call Thread.getThis().thread_detachThis() from within > DelayedHideTitle() and that will make the thread deta

Re: Why is size_t unsigned?

2013-07-22 Thread Maxim Fomin
On Monday, 22 July 2013 at 15:51:45 UTC, monarch_dodra wrote: So... you are saying that if the grammar allows it, then the behavior is specified? You may argue that although grammar does allows it, the feature is semantically not defined. However here it is known what "ref int i" means, to

Re: Are properties actually all that good?

2013-07-22 Thread develop32
On Monday, 22 July 2013 at 16:42:57 UTC, Land wrote: Thank you for the replies. So, what's the bottom line? Should I use accessor methods or should I use properties? (I've read quite a bit of the mentioned 500-post topic, by the way, but I'm still not clear on what's the most logical step here)

Re: Do threads 'end' themselves using core.thread?

2013-07-22 Thread Sean Kelly
On Jul 20, 2013, at 12:34 PM, Alex Horvat wrote: > If I use core.thread.Thread to create a new thread associated to a function > like this: > > Thread testThread = new Thread(&DoSomething); > > Will the testThread dispose of itself after DoSomething() completes, or do I > need to join/destroy

Re: Do threads 'end' themselves using core.thread?

2013-07-22 Thread Sean Kelly
On Jul 22, 2013, at 9:15 AM, Ali Çehreli wrote: > > Apparently, it is possible to detach from a thread or even to start it in the > detached state to begin with: "By default, a new thread is created in a > joinable state, unless attr was set to create the thread in a detached state > (using pt

Re: Do threads 'end' themselves using core.thread?

2013-07-22 Thread Ali Çehreli
On 07/22/2013 08:32 AM, Alex Horvat wrote: On Sunday, 21 July 2013 at 15:30:06 UTC, Ali Çehreli wrote: On 07/20/2013 09:43 PM, Ali Çehreli wrote: > When the parent thread terminates the child processes terminate as well. I am wrong there: What I said above is true for the main program thread.

Re: Can't use variadic arguments to functions that use templates

2013-07-22 Thread Jesse Phillips
On Sunday, 21 July 2013 at 07:22:08 UTC, JS wrote: void foo(T...)(T t) { pragma(msg, B(t)); } void main() { foo("x", "a", "b"); din.getc(); } does work. I need to have B generate compile time code so it is efficient. Your method calls an actual function at runtime so it is ne

Re: Are properties actually all that good?

2013-07-22 Thread Land
Thank you for the replies. So, what's the bottom line? Should I use accessor methods or should I use properties? (I've read quite a bit of the mentioned 500-post topic, by the way, but I'm still not clear on what's the most logical step here)

Re: Why is size_t unsigned?

2013-07-22 Thread Maxim Fomin
On Monday, 22 July 2013 at 15:04:25 UTC, monarch_dodra wrote: On Monday, 22 July 2013 at 12:51:31 UTC, Andrej Mitrovic wrote: On 7/22/13, JS wrote: foreach doesn't allow you to modify the index to skip over elements. It does: - import std.stdio; void main() { int[] x = [1, 2, 3, 4,

Re: Why is size_t unsigned?

2013-07-22 Thread Ali Çehreli
On 07/22/2013 08:04 AM, monarch_dodra wrote: > On Monday, 22 July 2013 at 12:51:31 UTC, Andrej Mitrovic wrote: >> On 7/22/13, JS wrote: >>> foreach doesn't allow you to modify the index to skip over >>> elements. >> >> It does: >> >> - >> import std.stdio; >> >> void main() >> { >> int[]

Re: Are properties actually all that good?

2013-07-22 Thread monarch_dodra
On Monday, 22 July 2013 at 15:07:29 UTC, Land wrote: I was just thinking about properties and to be honest, I don't like them all that much. There's no way to tell if it's a read-only or write-only property (right?), but getValue and setValue are pretty self-explanatory. Also, someone was angry

Re: Do threads 'end' themselves using core.thread?

2013-07-22 Thread Alex Horvat
On Sunday, 21 July 2013 at 15:30:06 UTC, Ali Çehreli wrote: On 07/20/2013 09:43 PM, Ali Çehreli wrote: > When the parent thread terminates the child processes terminate as well. I am wrong there: What I said above is true for the main program thread. When the main program terminates, its threa

Re: Are properties actually all that good?

2013-07-22 Thread Ali Çehreli
On 07/22/2013 08:07 AM, Land wrote: > I was just thinking about properties and to be honest, I don't > like them all that much. There's no way to tell if it's a > read-only or write-only property (right?), Documentation should make it clear. Otherwise, it should be possible to detect whether a

Re: Why is size_t unsigned?

2013-07-22 Thread monarch_dodra
On Monday, 22 July 2013 at 15:39:11 UTC, Maxim Fomin wrote: On Monday, 22 July 2013 at 15:04:25 UTC, monarch_dodra wrote: On Monday, 22 July 2013 at 12:51:31 UTC, Andrej Mitrovic wrote: On 7/22/13, JS wrote: foreach doesn't allow you to modify the index to skip over elements. It does:

Are properties actually all that good?

2013-07-22 Thread Land
I was just thinking about properties and to be honest, I don't like them all that much. There's no way to tell if it's a read-only or write-only property (right?), but getValue and setValue are pretty self-explanatory. Also, someone was angry about .keys making a copy. I agree with that person an

Re: Why is size_t unsigned?

2013-07-22 Thread monarch_dodra
On Monday, 22 July 2013 at 12:51:31 UTC, Andrej Mitrovic wrote: On 7/22/13, JS wrote: foreach doesn't allow you to modify the index to skip over elements. It does: - import std.stdio; void main() { int[] x = [1, 2, 3, 4, 5]; foreach (ref i; 0 .. 5) { writeln(x[i]);

Re: Why is size_t unsigned?

2013-07-22 Thread JS
On Monday, 22 July 2013 at 12:51:31 UTC, Andrej Mitrovic wrote: On 7/22/13, JS wrote: foreach doesn't allow you to modify the index to skip over elements. It does: - import std.stdio; void main() { int[] x = [1, 2, 3, 4, 5]; foreach (ref i; 0 .. 5) { writeln(x[i]);

Re: Why is size_t unsigned?

2013-07-22 Thread Andrej Mitrovic
On 7/22/13, JS wrote: > foreach doesn't allow you to modify the index to skip over > elements. It does: - import std.stdio; void main() { int[] x = [1, 2, 3, 4, 5]; foreach (ref i; 0 .. 5) { writeln(x[i]); ++i; } } - Writes: 1 3 5

Re: Why is size_t unsigned?

2013-07-22 Thread John Colvin
On Monday, 22 July 2013 at 11:56:35 UTC, Regan Heath wrote: If we were to design the perfect type for representing a size or length it would hold the maximum value of an unsigned int, but would not undeflow to max unsigned int, instead it would truncate. This type would have to be built on to

Re: Why is size_t unsigned?

2013-07-22 Thread Regan Heath
On Mon, 22 Jul 2013 04:47:34 +0100, JS wrote: Doing simple stuff like for(int i = 0; i < s.length - 1; i++) fails catastrophically if s is empty. To make right one has to reduce performance by writing extra checks. There seems to be no real good reason why size_t is unsigned... Surely

Re: Why is size_t unsigned?

2013-07-22 Thread David
> how about s[i - 1..n]? > > You going to go throw some ifs around the statement that uses that? Use > a ternary if? So I'm forced to use a longer more verbose method, and > also introduce bugs, because the most obvious, simplest, and logical > solution, s[max(0, i-1)..n] won't work. -1 as index

Re: Why is size_t unsigned?

2013-07-22 Thread monarch_dodra
On Monday, 22 July 2013 at 09:34:35 UTC, JS wrote: On Monday, 22 July 2013 at 07:12:07 UTC, monarch_dodra wrote: On Monday, 22 July 2013 at 03:47:36 UTC, JS wrote: Doing simple stuff like for(int i = 0; i < s.length - 1; i++) fails catastrophically if s is empty. To make right one has to redu

Re: Often repeated array allocations

2013-07-22 Thread Jacob Carlborg
On 2013-07-21 12:18, Namespace wrote: But then I have mostly far too much and maybe a few times a bit too less store. It's not flexible. But maybe with a smaller granule. What's about this: You said you needed between 100 and 4000 floats. My suggestion will allocate 4000 floats once per threa

Re: Why is size_t unsigned?

2013-07-22 Thread JS
On Monday, 22 July 2013 at 07:12:07 UTC, monarch_dodra wrote: On Monday, 22 July 2013 at 03:47:36 UTC, JS wrote: Doing simple stuff like for(int i = 0; i < s.length - 1; i++) fails catastrophically if s is empty. To make right one has to reduce performance by writing extra checks. Not reall

Re: Often repeated array allocations

2013-07-22 Thread David
Am 22.07.2013 10:41, schrieb Namespace: > It's part of Dgame and it's the shape draw method. The method collects > the vertices and give them to the vertex buffer. > I will try it with my current way: static stack buffer with a size of > 1024 and otherwise I will temporary allocate memory. But how

Re: Often repeated array allocations

2013-07-22 Thread Namespace
It's part of Dgame and it's the shape draw method. The method collects the vertices and give them to the vertex buffer. I will try it with my current way: static stack buffer with a size of 1024 and otherwise I will temporary allocate memory. But how much shapes grow larger than 1024 vertices ;)

Re: Often repeated array allocations

2013-07-22 Thread monarch_dodra
On Sunday, 21 July 2013 at 21:35:15 UTC, Namespace wrote: On Sunday, 21 July 2013 at 21:31:08 UTC, bearophile wrote: Namespace: I have a float[1024] buffer which is used, as long as the requested size is less than 1024. If it's greater, I will temporary allocate the whole array with new float

Re: Why is size_t unsigned?

2013-07-22 Thread monarch_dodra
On Monday, 22 July 2013 at 03:47:36 UTC, JS wrote: Doing simple stuff like for(int i = 0; i < s.length - 1; i++) fails catastrophically if s is empty. To make right one has to reduce performance by writing extra checks. Not really, you could instead just write your loop correctly. 1. Don't l