Re: delegates and temporary struct

2013-05-16 Thread 1100110
On 05/16/2013 09:21 PM, Maxim Fomin wrote: > On Thursday, 16 May 2013 at 22:53:56 UTC, Jack Applegame wrote: >> Look at this code: >>> import std.stdio; >>> >>> class Foo { >>> int value = 123456; >>> } >>> >>> struct Bar { >>> this(Foo f) { foo = f; } >>> @property auto lambda() { >>> return (){

Re: delegates and temporary struct

2013-05-16 Thread Maxim Fomin
On Thursday, 16 May 2013 at 22:53:56 UTC, Jack Applegame wrote: Look at this code: import std.stdio; class Foo { int value = 123456; } struct Bar { this(Foo f) { foo = f; } @property auto lambda() { return (){ writefln("value = %s", foo.value); }; } Foo foo; } auto getLambda(Foo f) { return

delegates and temporary struct

2013-05-16 Thread Jack Applegame
Look at this code: import std.stdio; class Foo { int value = 123456; } struct Bar { this(Foo f) { foo = f; } @property auto lambda() { return (){ writefln("value = %s", foo.value); }; } Foo foo; } auto getLambda(Foo f) { return Bar(f).lambda; // lambda closure points to temporary Bar

Re: cast(size_t)&c != 0, but c is null

2013-05-16 Thread Dmitry Olshansky
16-May-2013 13:31, Maxim Fomin пишет: On Thursday, 16 May 2013 at 09:05:46 UTC, Dicebot wrote: On Wednesday, 15 May 2013 at 19:30:41 UTC, Dmitry Olshansky wrote: Won't this work? *cast(void**)&object Right question is "is this guaranteed to work by spec?". Spec is silent about this but in p

Re: Garbage collector question

2013-05-16 Thread gedaiu
On Thursday, 16 May 2013 at 06:21:06 UTC, Namespace wrote: On Thursday, 16 May 2013 at 06:08:30 UTC, gedaiu wrote: Does the garbage collector manages the memory from extern(C) functions, or we have to delete manualy the objects created in those kind of functions? Thanks, Bogdan You mean som

Re: Can't instantiate SimpleTimeZone

2013-05-16 Thread Jonathan M Davis
On Thursday, May 16, 2013 16:00:58 Andrej Mitrovic wrote: > I was using the AE[1] library, but recently it started to fail to > compile due to essentially this: > > > import std.datetime; > > void main() > { > Duration dur; > auto x = new SimpleTimeZone(dur); > } > > > > test.d

Re: Recursive mixin templates

2013-05-16 Thread Simen Kjaeraas
On Thu, 16 May 2013 17:01:54 +0200, Sebastian Graf wrote: I aim to use a simplistic, rough edged property generator, but I'm having issues. See http://dpaste.dzfl.pl/72837a7a. My code and mixin logic seems to work basically, but it gets hairy when using mixinMap to generate getters and setter

Re: Getting byte size of POD classes and dynamic arrays

2013-05-16 Thread Andrej Mitrovic
On 5/16/13, Byron Heads wrote: > On Thu, 16 May 2013 08:11:35 -0500, 1100110 wrote: >> >> __traits(classInstanceSize, MyClass); ? > > Any ideas on how to get the element type of an array > ie: int[] -> int int[][] -> int[] Try the ElementType template in std.range. There's also ElementEncod

Recursive mixin templates

2013-05-16 Thread Sebastian Graf
I aim to use a simplistic, rough edged property generator, but I'm having issues. See http://dpaste.dzfl.pl/72837a7a. My code and mixin logic seems to work basically, but it gets hairy when using mixinMap to generate getters and setters from a list in a recursive template fashion. It won't work if

Re: Can't instantiate SimpleTimeZone

2013-05-16 Thread Andrej Mitrovic
On 5/16/13, nazriel wrote: > I believe it may be related to this: > http://forum.dlang.org/post/517e4196.9090...@outerproduct.org > > http://forum.dlang.org/post/CAFDvkctF-_A=jpp7a+qo43vsqlbg_upnusjjj01vkaeqwbj...@mail.gmail.com Thanks, that does explain it. I have to put this in the changelog AS

Re: Getting byte size of POD classes and dynamic arrays

2013-05-16 Thread bearophile
Byron Heads: Not the most initiative name for the function but works for my case.< It has a strange name because a string (that is a dynamic array) iterated as range (like by map()) has a type different from the same iterated on default with foreach... Bye, bearophile

Re: Can't instantiate SimpleTimeZone

2013-05-16 Thread nazriel
On Thursday, 16 May 2013 at 14:01:13 UTC, Andrej Mitrovic wrote: I was using the AE[1] library, but recently it started to fail to compile due to essentially this: import std.datetime; void main() { Duration dur; auto x = new SimpleTimeZone(dur); } test.d(8): Error:

Re: Can't instantiate SimpleTimeZone

2013-05-16 Thread Andrej Mitrovic
On 5/16/13, Andrej Mitrovic wrote: > I was using the AE[1] library [1]: https://github.com/CyberShadow/ae

Can't instantiate SimpleTimeZone

2013-05-16 Thread Andrej Mitrovic
I was using the AE[1] library, but recently it started to fail to compile due to essentially this: import std.datetime; void main() { Duration dur; auto x = new SimpleTimeZone(dur); } > test.d(8): Error: immutable method std.datetime.SimpleTimeZone.this is not > callab

Re: Getting byte size of POD classes and dynamic arrays

2013-05-16 Thread Byron Heads
On Thu, 16 May 2013 13:49:51 +, Byron Heads wrote: > On Thu, 16 May 2013 08:11:35 -0500, 1100110 wrote: >> >> __traits(classInstanceSize, MyClass); ? > > Any ideas on how to get the element type of an array ie: int[] -> int > int[][] -> int[] > > I am going to block dynamic arrays wit

Re: Getting byte size of POD classes and dynamic arrays

2013-05-16 Thread Byron Heads
On Thu, 16 May 2013 08:11:35 -0500, 1100110 wrote: > > __traits(classInstanceSize, MyClass); ? Any ideas on how to get the element type of an array ie: int[] -> int int[][] -> int[] I am going to block dynamic arrays with more then 1D, since they are holding pointers in the data block

Re: Getting byte size of POD classes and dynamic arrays

2013-05-16 Thread Byron Heads
On Thu, 16 May 2013 15:32:35 +0200, bearophile wrote: > Byron Heads: > >> now I am wondering way a POD has a vtable. > > In D global structs are PODs, while classe instances are are not PODs. > > All classes have a vtable because they inherit some methods from the > Object class. > > Bye, > be

Re: Getting byte size of POD classes and dynamic arrays

2013-05-16 Thread 1100110
On 05/16/2013 08:21 AM, Byron Heads wrote: > On Thu, 16 May 2013 08:11:35 -0500, 1100110 wrote: > >> On 05/16/2013 08:09 AM, Byron Heads wrote: >>> I am working on d-leveldb wrapper (https://github.com/bheads/d-leveldb) >>> and I need to be able to pass blocks of data between D and leveldb API. >>

Re: Getting byte size of POD classes and dynamic arrays

2013-05-16 Thread bearophile
Byron Heads: now I am wondering way a POD has a vtable. In D global structs are PODs, while classe instances are are not PODs. All classes have a vtable because they inherit some methods from the Object class. Bye, bearophile

Re: Getting byte size of POD classes and dynamic arrays

2013-05-16 Thread Byron Heads
On Thu, 16 May 2013 08:11:35 -0500, 1100110 wrote: > On 05/16/2013 08:09 AM, Byron Heads wrote: >> I am working on d-leveldb wrapper (https://github.com/bheads/d-leveldb) >> and I need to be able to pass blocks of data between D and leveldb API. >> I am having rouble getting the byte size of dynam

Re: Getting byte size of POD classes and dynamic arrays

2013-05-16 Thread 1100110
On 05/16/2013 08:09 AM, Byron Heads wrote: > I am working on d-leveldb wrapper (https://github.com/bheads/d-leveldb) > and I need to be able to pass blocks of data between D and leveldb API. > I am having rouble getting the byte size of dynamic arrays and POD > classes. > > I can get the right s

Getting byte size of POD classes and dynamic arrays

2013-05-16 Thread Byron Heads
I am working on d-leveldb wrapper (https://github.com/bheads/d-leveldb) and I need to be able to pass blocks of data between D and leveldb API. I am having rouble getting the byte size of dynamic arrays and POD classes. I can get the right size for 1D dynamic arrays, need a way to compute the t

Re: template specialization and template mixin

2013-05-16 Thread Andrej Mitrovic
On 5/16/13, Jack Applegame wrote: > Why this doesn't compile? I think this is a bug.

template specialization and template mixin

2013-05-16 Thread Jack Applegame
This code compiles , as expected struct A { void func(string s : "foo")() { pragma(msg, "func for foo"); } void func(string s)() { pragma(msg, "func for others: " ~ s); } } void main() { A a; a.func!"foo"(); a.func!"bar"();

Monad and its little sisters

2013-05-16 Thread qznc
I implemented the Maybe monad using template specialization. Feedback welcome! https://bitbucket.org/qznc/d-monad/src/ba39f2551af0e2e90a40653af92c048fed519a18/generic.d?at=master However, a few questions or possibly shortcomings of D came up. 1. I could not specify the inheritance between the

Re: cast(size_t)&c != 0, but c is null

2013-05-16 Thread David
Am 15.05.2013 17:08, schrieb Artur Skawina: > On 05/15/13 13:04, Dicebot wrote: >> On Wednesday, 15 May 2013 at 10:31:29 UTC, David wrote: "&c" is address of reference, no class instance. I don't know if there is a way to get a pointer to class instance in D but I am not aware of one. >>>

Re: cast(size_t)&c != 0, but c is null

2013-05-16 Thread Dicebot
On Thursday, 16 May 2013 at 09:31:11 UTC, Maxim Fomin wrote: On Thursday, 16 May 2013 at 09:05:46 UTC, Dicebot wrote: On Wednesday, 15 May 2013 at 19:30:41 UTC, Dmitry Olshansky wrote: Won't this work? *cast(void**)&object Right question is "is this guaranteed to work by spec?". Spec is sil

Re: cast(size_t)&c != 0, but c is null

2013-05-16 Thread Timothee Cour
interface with C++ for example (for example extern(C++) classes ) On Thu, May 16, 2013 at 2:31 AM, Maxim Fomin wrote: > On Thursday, 16 May 2013 at 09:05:46 UTC, Dicebot wrote: > >> On Wednesday, 15 May 2013 at 19:30:41 UTC, Dmitry Olshansky wrote: >> >>> Won't this work? >>> *cast(void**)&objec

Re: cast(size_t)&c != 0, but c is null

2013-05-16 Thread Maxim Fomin
On Thursday, 16 May 2013 at 09:05:46 UTC, Dicebot wrote: On Wednesday, 15 May 2013 at 19:30:41 UTC, Dmitry Olshansky wrote: Won't this work? *cast(void**)&object Right question is "is this guaranteed to work by spec?". Spec is silent about this but in practice this should work. Real questio

Re: cast(size_t)&c != 0, but c is null

2013-05-16 Thread Dicebot
On Wednesday, 15 May 2013 at 19:30:41 UTC, Dmitry Olshansky wrote: Won't this work? *cast(void**)&object Right question is "is this guaranteed to work by spec?".

Re: cannot have overloaded nested functions?

2013-05-16 Thread Jonathan M Davis
On Thursday, May 16, 2013 01:15:06 Timothee Cour wrote: > > as far as I can tell, it means exactly what it says, and I don't know how > > it could be friendlier. > > the error message 'declaration fun is already defined' is surprising > because 'void fun(int x);' and 'void fun();' are typically 2

Re: cannot have overloaded nested functions?

2013-05-16 Thread Timothee Cour
> as far as I can tell, it means exactly what it says, and I don't know how it could be friendlier. the error message 'declaration fun is already defined' is surprising because 'void fun(int x);' and 'void fun();' are typically 2 different function declarations, having different signatures. So thi

why doesn't formattedRead take args by ref instead of by pointer?

2013-05-16 Thread Timothee Cour
If I change formattedRead's input signature to: uint formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, ref S args) and adjusted code accordingly. It seems to work fine. see implementation here: https://github.com/timotheecour/dtools/blob/master/dtools/overrides/format.d#L29 (just run unitt

Re: cannot have overloaded nested functions?

2013-05-16 Thread Jonathan M Davis
On Thursday, May 16, 2013 00:28:15 Timothee Cour wrote: > at the very least (or until it gets fixed) dmd should emit a more friendly > error message: > 'cannot overload a function in a nested scope' > otherwise this is hard to understand. I don't know what else it would say. It means exactly what

Re: cannot have overloaded nested functions?

2013-05-16 Thread Timothee Cour
at the very least (or until it gets fixed) dmd should emit a more friendly error message: 'cannot overload a function in a nested scope' otherwise this is hard to understand. On Wed, May 15, 2013 at 11:43 PM, Jonathan M Davis wrote: > On Wednesday, May 15, 2013 20:48:19 Steven Schveighoffer wrote