Re: How to require operator overloading in interface

2013-07-21 Thread JS
On Saturday, 20 July 2013 at 19:04:29 UTC, Jesse Phillips wrote: On Saturday, 20 July 2013 at 18:53:44 UTC, JS wrote: if they want to allow the same op in there class, which they probably do, they have to override the long hand anyways and redirect. Nope, that is why you make the template fin

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

2013-07-21 Thread JS
On Saturday, 20 July 2013 at 18:57:18 UTC, Jesse Phillips wrote: On Saturday, 20 July 2013 at 18:27:23 UTC, JS wrote: is there any way to pass t directly to A? template A(T...) doesn't seem work nor does using an alias. (or at least, when I try to foreach over it, it doesn't work). template

Re: Return all objects with specified UDA?

2013-07-21 Thread Jacob Carlborg
On 2013-07-21 06:21, Carl wrote: I am experimenting with user defined attributes, but am wondering if a list of all objects with a specified UDA could be generated? If not, is there a workaround for getting these objects without a direct reference? If you modify druntime you can do it. This te

Re: Often repeated array allocations

2013-07-21 Thread Jacob Carlborg
On 2013-07-21 08:45, Namespace wrote: But D isn't like Ada. It's more like C++ and there Heap allocations is often used too. It would be really cool if we had allocators already. Something like: with (AllocatorX) { /// will use malloc and free instead of calling the GC float[] arr;

Re: Often repeated array allocations

2013-07-21 Thread Namespace
On Sunday, 21 July 2013 at 09:16:47 UTC, Jacob Carlborg wrote: On 2013-07-21 08:45, Namespace wrote: But D isn't like Ada. It's more like C++ and there Heap allocations is often used too. It would be really cool if we had allocators already. Something like: with (AllocatorX) { /// will use

Re: Often repeated array allocations

2013-07-21 Thread bearophile
Namespace: But D isn't like Ada. But D should be a bit more like Ada, for such things :-) Bye, bearophile

Re: Often repeated array allocations

2013-07-21 Thread Namespace
On Sunday, 21 July 2013 at 10:30:16 UTC, bearophile wrote: Namespace: But D isn't like Ada. But D should be a bit more like Ada, for such things :-) Bye, bearophile I agree, but how? ;) You know by yourself that Walter & Andrei are very hard to convince by such things.

Re: Often repeated array allocations

2013-07-21 Thread bearophile
Namespace: I agree, but how? ;) You know by yourself that Walter & Andrei are very hard to convince by such things. I think there is only a small number of Ada ideas worth copying, like: - Integral overflows; - Ranged integers; - A library of collections allocated in-place in the standard

Re: A little of coordination for Rosettacode

2013-07-21 Thread bearophile
Now this D entry works again: http://rosettacode.org/wiki/S-Expressions#D Probably it can be written without explicit indexes, only using txt.front, txt.popFrontN, txt.find, etc. Do you want to produce such modified version? This simple task shows well why a parser combinators like Parsec i

Re: Often repeated array allocations

2013-07-21 Thread Dmitry Olshansky
21-Jul-2013 00:46, Namespace пишет: On Saturday, 20 July 2013 at 20:22:56 UTC, Dmitry Olshansky wrote: 21-Jul-2013 00:19, Namespace пишет: Let us assume we have a method of a class which is used often and the method is called periodically and must allocate every time a array between 100 and 400

Re: Often repeated array allocations

2013-07-21 Thread Dmitry Olshansky
21-Jul-2013 00:42, Ali Çehreli пишет: On 07/20/2013 01:22 PM, Dmitry Olshansky wrote: > 21-Jul-2013 00:19, Namespace пишет: >> Let us assume we have a method of a class which is used often and the >> method is called periodically and must allocate every time a array >> between 100 and 4000 e

Re: Unwanted conflict

2013-07-21 Thread Carl Sturtivant
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-time argument types. I'll put in a bug report.

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

2013-07-21 Thread Ali Çehreli
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 threads are terminated as well. Otherwise, a child can continue

mixin string evaluation

2013-07-21 Thread Martin Krejcirik
Is it somehow possible to evaluate a string on template parameters ? Something like this: enum source = "TYPE var;"; template Eval(TYPE) { string Eval() { return evaluate(source); <-- replace TYPE with int } } mixin(Eval!int); <-- int var here Basically

Re: mixin string evaluation

2013-07-21 Thread Ali Çehreli
On 07/21/2013 09:26 AM, Martin Krejcirik wrote: Is it somehow possible to evaluate a string on template parameters ? Something like this: enum source = "TYPE var;"; template Eval(TYPE) { string Eval() { return evaluate(source); <-- replace TYPE with int

Code generation tricks

2013-07-21 Thread JS
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", " if (r.length <= i) r.length += 5;

Re: Unwanted conflict

2013-07-21 Thread Jonathan M Davis
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-time argument types. You could use a factory function instead

Re: mixin string evaluation

2013-07-21 Thread Artur Skawina
On 07/21/13 18:26, Martin Krejcirik wrote: > Is it somehow possible to evaluate a string on template parameters ? > Something like this: > > enum source = "TYPE var;"; > > template Eval(TYPE) > { > string Eval() > { > return evaluate(source); <-- replace TYPE with int >

Re: Often repeated array allocations

2013-07-21 Thread Namespace
My analogy goes as follows: a chunk of memory for temporary needs => scratch pad (as in sheet of paper for quick notes/sketches). Something along the lines of: class A{ static float[] buffer; static this(){ buffer = new float[as_big_as_it_gets]; }

Re: Often repeated array allocations

2013-07-21 Thread bearophile
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[Size]; That's one of the ways I solve similar problems. Any improvements? Or is 1024 to small / big? An idea is

Re: Often repeated array allocations

2013-07-21 Thread Namespace
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[Size]; That's one of the ways I solve similar problems.

Re: Often repeated array allocations

2013-07-21 Thread Dmitry Olshansky
22-Jul-2013 01:19, Namespace пишет: I really like the idea. I've changed it a bit: 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[Size]; Any improvements? Or is 1024 to small /

Re: mixin string evaluation

2013-07-21 Thread Martin Krejcirik
On 21.7.2013 19:15, Ali Çehreli wrote: > string Eval() > { > string statement = source; > auto found = statement.findSkip("TYPE"); > assert(found); > > return TYPE.stringof ~ statement; > } Thanks, actually findSplit is what I need, but works like a cha

interesting semantic possible?

2013-07-21 Thread JS
Say I have a template function where there are variations, it would be nice to be able to specify those variables like strip!Left(s), strip!Right(s), strip(s), etc... instead of ahving to do stripLeft, stripRight, and strip. But the goal isn't just to add an extra ! to type but that it reduce

Re: interesting semantic possible?

2013-07-21 Thread JS
BTW, I'm not saying D can't do anything like this enum Dir { Left, Right, Both } string strip(Dir dir = Dir.Both)(string s) but one has to call it like strip!(Dir.Left)(s); (or if using strings, strip!"Left"(s)) Possibly, to make it easier the compiler and localize the enum if one is used:

Re: interesting semantic possible?

2013-07-21 Thread bearophile
JS: Say I have a template function where there are variations, it would be nice to be able to specify those variables like strip!Left(s), strip!Right(s), strip(s), etc... instead of ahving to do stripLeft, stripRight, and strip. But the goal isn't just to add an extra ! to type but that it

Why is size_t unsigned?

2013-07-21 Thread 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. There seems to be no real good reason why size_t is unsigned... Surely one doesn't require too many strings larger than 2^6

Re: Why is size_t unsigned?

2013-07-21 Thread Ali Çehreli
On 07/21/2013 08:47 PM, 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. Checks are needed for program correctness. If not in source code, in compiler gene

Re: Why is size_t unsigned?

2013-07-21 Thread H. S. Teoh
On Mon, Jul 22, 2013 at 05:47:34AM +0200, 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. I'm not sure if it's your intention, but your code above has an of

Re: Why is size_t unsigned?

2013-07-21 Thread JS
On Monday, 22 July 2013 at 03:58:31 UTC, Ali Çehreli wrote: On 07/21/2013 08:47 PM, 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. Checks are needed for pr

Re: Why is size_t unsigned?

2013-07-21 Thread JS
On Monday, 22 July 2013 at 04:31:12 UTC, H. S. Teoh wrote: On Mon, Jul 22, 2013 at 05:47:34AM +0200, 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. I'm not su

Re: Why is size_t unsigned?

2013-07-21 Thread Ali Çehreli
On 07/21/2013 09:36 PM, JS wrote: > On Monday, 22 July 2013 at 03:58:31 UTC, Ali Çehreli wrote: >> > There seems to be no real good reason why size_t is >> unsigned... >> >> How about, every addressable memory locations must be countable? > > for strings themselves, I would prefer an int to be r

Re: Why is size_t unsigned?

2013-07-21 Thread H. S. Teoh
On Mon, Jul 22, 2013 at 06:43:47AM +0200, JS wrote: > On Monday, 22 July 2013 at 04:31:12 UTC, H. S. Teoh wrote: > >On Mon, Jul 22, 2013 at 05:47:34AM +0200, JS wrote: [...] > >>There seems to be no real good reason why size_t is unsigned... > >[...] > > > >The reason is because it must span the ra