Re: struct init() method

2012-02-25 Thread Alex Rønne Petersen
On 25-02-2012 05:05, bearophile wrote: This program comes from a reduction of a bug I've found: struct Foo { void init() {} } void main() { Foo*[] foos; //(*foos[0]).init(); // OK foos[0].init(); // Error: function expected before (), not null of type Foo* } What do you t

Re: delegate as memeber

2012-02-25 Thread Stewart Gordon
On 21/02/2012 17:46, Jacob Carlborg wrote: On 2012-02-21 16:55, deadalnix wrote: You can implement a static opCall and use that instead of the constructor. But you don't have to call a static opCall. You can just declare a struct instance without any initialisation. Presumably half the po

Re: delegate as memeber

2012-02-25 Thread Timon Gehr
On 02/25/2012 03:32 PM, Stewart Gordon wrote: On 21/02/2012 17:46, Jacob Carlborg wrote: On 2012-02-21 16:55, deadalnix wrote: You can implement a static opCall and use that instead of the constructor. But you don't have to call a static opCall. You can just declare a struct instance withou

Re: Template Inheritance

2012-02-25 Thread Timon Gehr
On 02/22/2012 01:13 AM, BLM wrote: That last one looks a lot better than my solution. It's certainly a lot clearer. One problem I discovered with using templates was that I ended up needing virtual functions, which means that I had to convert the template functions to mixins and just instantia

Re: deh_end

2012-02-25 Thread Jacob Carlborg
On 2012-02-24 23:37, Ellery Newcomer wrote: So I'm all trying out this hot new shared switch, and it works just dandy for -m32 when d has the main function. But now I want to be able to call my shared lib from C. my little shared lib, tup.d: import std.stdio; extern(C) void xyz(int i){ writeln

Re: struct init() method

2012-02-25 Thread H. S. Teoh
On Sat, Feb 25, 2012 at 01:23:21PM +0100, Alex Rønne Petersen wrote: > On 25-02-2012 05:05, bearophile wrote: > >This program comes from a reduction of a bug I've found: > > > > > >struct Foo { > > void init() {} > >} > >void main() { > > Foo*[] foos; > > //(*foos[0]).init(); // OK > >

Re: struct init() method

2012-02-25 Thread Timon Gehr
On 02/25/2012 04:52 PM, H. S. Teoh wrote: On Sat, Feb 25, 2012 at 01:23:21PM +0100, Alex Rønne Petersen wrote: On 25-02-2012 05:05, bearophile wrote: This program comes from a reduction of a bug I've found: struct Foo { void init() {} } void main() { Foo*[] foos; //(*foos[0]).i

Re: Using delegates in callbacks for extern(C) functions

2012-02-25 Thread Timon Gehr
On 02/24/2012 07:22 PM, simendsjo wrote: I have a C function taking a callback function as a parameter. My thought was to wrap this up using a template, but I cannot get it to work: extern(C) alias void function() Callback; template Wrap(alias dg) { extern(C) void Wrap() { dg(); } } void main(

Supporting and signature-checking all foreach variations

2012-02-25 Thread Ashish Myles
I want to define a general-purpose centroid computer for point containers and ran into a couple of challenges. Firstly, here is the basic code Point3 computeCentroid(PointContainer)(const ref PointContainer C) if (...)// want a signature constraint for usability of foreach {

Re: Supporting and signature-checking all foreach variations

2012-02-25 Thread Alex Rønne Petersen
On 25-02-2012 17:25, Ashish Myles wrote: I want to define a general-purpose centroid computer for point containers and ran into a couple of challenges. Firstly, here is the basic code Point3 computeCentroid(PointContainer)(const ref PointContainer C) if (...)// want a signature

Write struct to file

2012-02-25 Thread Chopin
Hello! import std.stdio; struct nagger { string name; int age; double weight; string msg; } void main() { auto lal = new nagger(); lal.name = "AHAHAHAHHA"; lal.age = 23; lal.weight = 108.5; lal.msg = "fgfdgfdgfdgfdgfdgfdg"; writeln(cast(ubyte[])(lal)); }

Re: Write struct to file

2012-02-25 Thread Timon Gehr
On 02/25/2012 07:03 PM, Chopin wrote: Hello! import std.stdio; struct nagger { string name; int age; double weight; string msg; } void main() { auto lal = new nagger(); lal.name = "AHAHAHAHHA"; lal.age = 23; lal.weight = 108.5; lal.msg = "fgfdgfdgfdgfdgfdgfdg"; writeln(cast(ubyte[])(lal)); }

Re: Write struct to file

2012-02-25 Thread Timon Gehr
On 02/25/2012 07:15 PM, Timon Gehr wrote: On 02/25/2012 07:03 PM, Chopin wrote: Hello! import std.stdio; struct nagger { string name; int age; double weight; string msg; } void main() { auto lal = new nagger(); lal.name = "AHAHAHAHHA"; lal.age = 23; lal.weight = 108.5; lal.msg = "fgfdgfdgfdgf

Re: delegate as memeber

2012-02-25 Thread Artur Skawina
On 02/25/12 15:37, Timon Gehr wrote: > On 02/25/2012 03:32 PM, Stewart Gordon wrote: >> On 21/02/2012 17:46, Jacob Carlborg wrote: >>> On 2012-02-21 16:55, deadalnix wrote: >> >>> You can implement a static opCall and use that instead of the >>> constructor. >> >> But you don't have to call a stat

Re: delegate as memeber

2012-02-25 Thread Timon Gehr
On 02/25/2012 07:23 PM, Artur Skawina wrote: On 02/25/12 15:37, Timon Gehr wrote: On 02/25/2012 03:32 PM, Stewart Gordon wrote: On 21/02/2012 17:46, Jacob Carlborg wrote: On 2012-02-21 16:55, deadalnix wrote: You can implement a static opCall and use that instead of the constructor. But y

Re: std.socket with GDC

2012-02-25 Thread Vladimir Panteleev
On Friday, 24 February 2012 at 19:15:26 UTC, Mars wrote: Hello everybody. When trying to compile a program using GDC (Windows), which includes an import std.socket, I get a lot "undefined reference"s, like undefined reference to `WSAGetLastError@0' Try linking with libws2_32.a.

Re: Write struct to file

2012-02-25 Thread Andrej Mitrovic
Well first I'd recommend not allocating the struct on the heap. Then you can do: import std.stdio; struct nagger { string name; int age; double weight; string msg; } void main() { nagger lal; lal.name = "name"; lal.age= 23; lal.weight = 108.5; lal.msg

Re: Write struct to file

2012-02-25 Thread Andrej Mitrovic
On 2/25/12, Andrej Mitrovic wrote: > This doesn't work for heap-allocated structs. > Sorry my bad. .sizeof should always be set on Types and not variable names, because a struct pointer will have sizeof == size_t, whereas a simple struct variable will have sizeof equal to the struct size. So it c

Re: Using delegates in callbacks for extern(C) functions

2012-02-25 Thread simendsjo
On Sat, 25 Feb 2012 17:12:50 +0100, Timon Gehr wrote: On 02/24/2012 07:22 PM, simendsjo wrote: I have a C function taking a callback function as a parameter. My thought was to wrap this up using a template, but I cannot get it to work: extern(C) alias void function() Callback; template Wr

Make alias parameter optional?

2012-02-25 Thread Robert Rouse
Is it possible to do something like this? void foo(T, T2, alias thing)(T a, T2 b) { // do stuff with a // call b (since b would be a delegate) // call thing if thing is given } I come from the Ruby world and I'm just playing around to see how much I can replicate of the "block" functional

Re: Make alias parameter optional?

2012-02-25 Thread Trass3r
void foo(T, T2, alias thing = (){})(T a, T2 b) { thing(); } void bar(){} void main() { foo!(int,int,bar)(1,2); foo(1,2); }

Re: Supporting and signature-checking all foreach variations

2012-02-25 Thread Ashish Myles
On Sat, Feb 25, 2012 at 11:37 AM, Alex Rønne Petersen wrote: > On 25-02-2012 17:25, Ashish Myles wrote: >> >> 1. Since support for foreach can be added in many ways (with >>   ref/non-ref/const variants), I wanted to check if there was any >>   signature constraint that could check if the containe

Re: Supporting and signature-checking all foreach variations

2012-02-25 Thread Dmitry Olshansky
On 25.02.2012 20:25, Ashish Myles wrote: I want to define a general-purpose centroid computer for point containers and ran into a couple of challenges. Firstly, here is the basic code Point3 computeCentroid(PointContainer)(const ref PointContainer C) if (...)// want a signature

Re: struct init() method

2012-02-25 Thread Dmitry Olshansky
On 25.02.2012 8:05, bearophile wrote: This program comes from a reduction of a bug I've found: struct Foo { void init() {} } void main() { Foo*[] foos; //(*foos[0]).init(); // OK foos[0].init(); // Error: function expected before (), not null of type Foo* } What do you th

Re: std.socket with GDC

2012-02-25 Thread Mars
On Saturday, 25 February 2012 at 18:27:29 UTC, Vladimir Panteleev wrote: On Friday, 24 February 2012 at 19:15:26 UTC, Mars wrote: Hello everybody. When trying to compile a program using GDC (Windows), which includes an import std.socket, I get a lot "undefined reference"s, like undefined ref

Re: Make alias parameter optional?

2012-02-25 Thread Robert Rouse
On Saturday, 25 February 2012 at 18:54:35 UTC, Trass3r wrote: void foo(T, T2, alias thing = (){})(T a, T2 b) { thing(); } void bar(){} void main() { foo!(int,int,bar)(1,2); foo(1,2); } Cool. Didn't know you can do that, but I guess it makes sense that it would work th

Re: Write struct to file

2012-02-25 Thread Ali Çehreli
On 02/25/2012 10:33 AM, Andrej Mitrovic wrote: Well first I'd recommend not allocating the struct on the heap. Then you can do: import std.stdio; struct nagger { string name; int age; double weight; string msg; } void main() { nagger lal; lal.name = "name";

Re: Make alias parameter optional?

2012-02-25 Thread Ali Çehreli
On 02/25/2012 01:55 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 18:54:35 UTC, Trass3r wrote: void foo(T, T2, alias thing = (){})(T a, T2 b) { thing(); } void bar(){} void main() { foo!(int,int,bar)(1,2); foo(1,2); } Cool. Didn't know you can do that, but I guess it makes sense t

Re: Make alias parameter optional?

2012-02-25 Thread Robert Rouse
On Saturday, 25 February 2012 at 22:12:55 UTC, Ali Çehreli wrote: On 02/25/2012 01:55 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 18:54:35 UTC, Trass3r wrote: void foo(T, T2, alias thing = (){})(T a, T2 b) { thing(); } void bar(){} void main() { foo!(int,int,bar)(1,2); foo(1,2)

Re: Write struct to file

2012-02-25 Thread Andrej Mitrovic
On 2/25/12, Ali Çehreli wrote: > That passes because lal.name.ptr and dup.name.ptr have the same value. > Maybe that wasn't the intention but the data is not really in the file. I'm not sure where you're getting that from: import std.stdio; struct nagger { string name; int age; doub

Re: Write struct to file

2012-02-25 Thread Andrej Mitrovic
To be honest the C fread and fwrite aren't even necessary since you can do a rawRead and rawWrite instead.

Re: std.socket with GDC

2012-02-25 Thread DNewbie
On Sat, Feb 25, 2012, at 10:38 PM, Mars wrote: > On Saturday, 25 February 2012 at 18:27:29 UTC, Vladimir Panteleev > wrote: > > On Friday, 24 February 2012 at 19:15:26 UTC, Mars wrote: > >> Hello everybody. > >> > >> When trying to compile a program using GDC (Windows), which > >> includes an i

Re: Write struct to file

2012-02-25 Thread Andrej Mitrovic
On 2/25/12, Ali Çehreli wrote: > But there is no way for fwrite to follow name.ptr to also write the > characters that are in the string, right? Oh my I just got a big fat zero on the finals. You're absolutely right, what gets copied is the length and the pointer. The only reason my last sample w

Re: Write struct to file

2012-02-25 Thread Andrej Mitrovic
On 2/26/12, Andrej Mitrovic wrote: > allocated on the stack Sorry, I meant the data segment not the stack. That's -1 score for me.

Re: Write struct to file

2012-02-25 Thread Andrej Mitrovic
On 2/25/12, Andrej Mitrovic wrote: > I'm not sure where you're getting that from: Let that be a classic lesson on what never to do. Here's a demonstration on how wrong I was: import std.stdio; struct Foo { char[] name; } void main(string[] args) { if (args[1] == "write") { Foo

Re: Make alias parameter optional?

2012-02-25 Thread Ary Manzana
On 2/25/12 7:31 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 22:12:55 UTC, Ali Çehreli wrote: On 02/25/2012 01:55 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 18:54:35 UTC, Trass3r wrote: void foo(T, T2, alias thing = (){})(T a, T2 b) { thing(); } void bar(){} void

Re: struct init() method

2012-02-25 Thread Jonathan M Davis
On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote: > This is useful: > > struct S{ > @disable enum init = 0; > } I thought that the way that you were supposed to do that was @disable this(); - Jonathan M Davis

Re: struct init() method

2012-02-25 Thread Alex Rønne Petersen
On 26-02-2012 00:18, Jonathan M Davis wrote: On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote: This is useful: struct S{ @disable enum init = 0; } I thought that the way that you were supposed to do that was @disable this(); - Jonathan M Davis Yeah, I'm not sure what purpose

Re: Write struct to file

2012-02-25 Thread Ali Çehreli
On 02/25/2012 03:00 PM, Andrej Mitrovic wrote: On 2/25/12, Ali Çehreli wrote: But there is no way for fwrite to follow name.ptr to also write the characters that are in the string, right? Oh my I just got a big fat zero on the finals. You're absolutely right, what gets copied is the length an

Re: Make alias parameter optional?

2012-02-25 Thread Robert Rouse
On Saturday, 25 February 2012 at 23:10:51 UTC, Ary Manzana wrote: On 2/25/12 7:31 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 22:12:55 UTC, Ali Çehreli wrote: On 02/25/2012 01:55 PM, Robert Rouse wrote: On Saturday, 25 February 2012 at 18:54:35 UTC, Trass3r wrote: void foo(T,

Re: Make alias parameter optional?

2012-02-25 Thread Andrej Mitrovic
On 2/25/12, Ali Çehreli wrote: > Apparently template parameters > with default values need not be at the end of the template parameter list Well it would make variadic templates rather hard to use if this was illegal: void print(bool pretty = false, T...)(T args) { } void main() { print(1, "two"

Re: struct init() method

2012-02-25 Thread H. S. Teoh
On Sun, Feb 26, 2012 at 12:23:47AM +0100, Alex Rønne Petersen wrote: > On 26-02-2012 00:18, Jonathan M Davis wrote: > >On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote: > >>This is useful: > >> > >>struct S{ > >> @disable enum init = 0; > >>} > > > >I thought that the way that you were

Re: struct init() method

2012-02-25 Thread Jonathan M Davis
On Saturday, February 25, 2012 17:54:44 H. S. Teoh wrote: > On Sun, Feb 26, 2012 at 12:23:47AM +0100, Alex Rønne Petersen wrote: > > On 26-02-2012 00:18, Jonathan M Davis wrote: > > >On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote: > > >>This is useful: > > >> > > >>struct S{ > > >> > > >>

Re: std.socket with GDC

2012-02-25 Thread Andrew Wiley
On Sat, Feb 25, 2012 at 4:45 PM, DNewbie wrote: > > > On Sat, Feb 25, 2012, at 10:38 PM, Mars wrote: >> On Saturday, 25 February 2012 at 18:27:29 UTC, Vladimir Panteleev >> wrote: >> > On Friday, 24 February 2012 at 19:15:26 UTC, Mars wrote: >> >> Hello everybody. >> >> >> >> When trying to compil

Re: struct init() method

2012-02-25 Thread Alex Rønne Petersen
On 26-02-2012 02:54, Jonathan M Davis wrote: On Saturday, February 25, 2012 17:54:44 H. S. Teoh wrote: On Sun, Feb 26, 2012 at 12:23:47AM +0100, Alex Rønne Petersen wrote: On 26-02-2012 00:18, Jonathan M Davis wrote: On Saturday, February 25, 2012 17:07:14 Timon Gehr wrote: This is useful: s

Re: Supporting and signature-checking all foreach variations

2012-02-25 Thread Jesse Phillips
On Saturday, 25 February 2012 at 16:26:05 UTC, Ashish Myles wrote: 2. Secondly, TDPL on page 381 says that foreach iterates over C[], if C defines the opSlice() function without any arguments. However the code above doesn't seem to work and requires me to explicitly invoke the slice opera