Copying with immutable arrays

2012-10-27 Thread Tobias Pankrath
So I have this immutable array with user defined structs but I can not make a copy from it. See: struct SwA { string[] strings; } void main() { immutable(SwA)[] arr1; SwA[] arr2 = arr1.dup; } Says: Error: cannot implicitly convert element type immutable(SwA) to mutable in

Re: How to extend built-in types

2012-10-27 Thread simendsjo
On Friday, 26 October 2012 at 16:32:29 UTC, Jonathan M Davis wrote: On Friday, October 26, 2012 15:55:34 simendsjo wrote: So.. What do I need to implement for a struct to be a valid built-in type? All valid properties (min, max etc) and operators for that type? So, you want stuff like

Re: How to extend built-in types

2012-10-27 Thread Jonathan M Davis
On Saturday, October 27, 2012 11:58:57 simendsjo wrote: The thing is that I often doesn't really care about the type, only that it exposes certain properties. Then create a template constraint (or eponymous template to use in a template constraint) which tests for those properties. That's

Re: How to extend built-in types

2012-10-27 Thread simendsjo
On Saturday, 27 October 2012 at 10:07:20 UTC, Jonathan M Davis wrote: On Saturday, October 27, 2012 11:58:57 simendsjo wrote: The thing is that I often doesn't really care about the type, only that it exposes certain properties. Then create a template constraint (or eponymous template to use

Re: Simple reading of binary data

2012-10-27 Thread Matt
On Saturday, 27 October 2012 at 11:06:09 UTC, Matt wrote: I'm having real trouble reading binary data from a file. I've been trying to use the functions from std.stdio, but keep running into problems. When I try; byte b; auto file = new File( some binary file ); file.readf( %d, b ); I get

Simple reading of binary data

2012-10-27 Thread Matt
I'm having real trouble reading binary data from a file. I've been trying to use the functions from std.stdio, but keep running into problems. When I try; byte b; auto file = new File( some binary file ); file.readf( %d, b ); I get Unexpected '€' when converting from type LockingTextReader

mousehandler

2012-10-27 Thread hr
hi, could anyone please explain how an array of Handlers is defined? void Handler(int, int); struct WData { POINTS mouse; // Current location of the mouse Queue clicks[WM_MOUSELAST - WM_MOUSEFIRST + 1]; // Array to hold the coordinates of the clicks int

Re: mousehandler

2012-10-27 Thread Tobias Pankrath
try: Handler[] mouse_handlers = new [WM_MOUSELAST - WM_MOUSEFIRST + 1] or if the size is statically known: Handler[WM_MOUSELAST - WM_MOUSEFIRST + 1] handler;

Re: How to extend built-in types

2012-10-27 Thread Jonathan M Davis
On Saturday, October 27, 2012 12:34:28 simendsjo wrote: So something like this then? Whatever you need for what you're trying to do. If your example templates test what you need tested, then they should work, though I confess that for something like division, it seems to me to be overkill to

Re: TypeInfo manipulation

2012-10-27 Thread Zhenya
On Friday, 26 October 2012 at 19:57:14 UTC, Zhenya wrote: On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote: Hi! Tell me please,are any TypeInfo/typeid/classinfo manipulations possible? For example I need a struct that overload typeid, or something like that? Some time ago I tried

Re: TypeInfo manipulation

2012-10-27 Thread Maxim Fomin
On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote: Hi! Tell me please,are any TypeInfo/typeid/classinfo manipulations possible? For example I need a struct that overload typeid, or something like that? It is impossible to overload typeid typeinfo. Some time ago I tried to write

Re: TypeInfo manipulation

2012-10-27 Thread Maxim Fomin
On Friday, 26 October 2012 at 19:57:14 UTC, Zhenya wrote: On Thursday, 25 October 2012 at 15:05:05 UTC, Zhenya wrote: Hi! Tell me please,are any TypeInfo/typeid/classinfo manipulations possible? For example I need a struct that overload typeid, or something like that? Some time ago I tried

Re: TypeInfo manipulation

2012-10-27 Thread Zhenya
What do you mean: to parametrize class by Typeinfo? class A { } A!TypeInfo var; If you mean this, than how it can help? It would be well if I could create object that inherits class with this typeinfo.

Re: TypeInfo manipulation

2012-10-27 Thread Zhenya
I have double dispatcher: template Dispatcher(R) { R execute(Left,Right)(R delegate(Left,Right) f,Object left,Object right) { return f(cast(Left)left,cast(Right)right); } struct Dispatcher { private R

Re: mousehandler

2012-10-27 Thread hr
On Saturday, 27 October 2012 at 11:59:16 UTC, Tobias Pankrath wrote: try: Handler[] mouse_handlers = new [WM_MOUSELAST - WM_MOUSEFIRST + 1] or if the size is statically known: Handler[WM_MOUSELAST - WM_MOUSEFIRST + 1] handler; Thank you for your help. after doing what you propose, i get the

Re: mousehandler

2012-10-27 Thread Tobias Pankrath
On Saturday, 27 October 2012 at 14:05:20 UTC, hr wrote: On Saturday, 27 October 2012 at 11:59:16 UTC, Tobias Pankrath wrote: try: Handler[] mouse_handlers = new [WM_MOUSELAST - WM_MOUSEFIRST + 1] or if the size is statically known: Handler[WM_MOUSELAST - WM_MOUSEFIRST + 1] handler; Thank

Re: Copying with immutable arrays

2012-10-27 Thread Ali Çehreli
On 10/27/2012 02:30 AM, Tobias Pankrath wrote: So I have this immutable array with user defined structs but I can not make a copy from it. See: struct SwA { string[] strings; } void main() { immutable(SwA)[] arr1; SwA[] arr2 = arr1.dup; } Says: Error: cannot implicitly convert element type

Where are the strings in std.string?

2012-10-27 Thread TheManWithNoName
I don't mean to be splitting hairs here, well maybe I do, but D clearly makes the string type to be immutable(char)[]. That's fine, but the std.string is all about char[] or mutable character arrays. So now, whenever I see a reference to the string, I have to ask myself: do they mean the

Re: Where are the strings in std.string?

2012-10-27 Thread H. S. Teoh
On Sat, Oct 27, 2012 at 06:53:56PM +0200, TheManWithNoName wrote: I don't mean to be splitting hairs here, well maybe I do, but D clearly makes the string type to be immutable(char)[]. That's fine, but the std.string is all about char[] or mutable character arrays. Huh? I think you're

Re: long compile time question

2012-10-27 Thread BLM768
In any case, though, separately initializing every member of an array is silly. That's what a loop is for. That, or a memcpy from an immutable copy of .init. I think that the reasoning behind DMD's implementation is that for small structs, writing out the instructions is more efficient

Re: long compile time question

2012-10-27 Thread BLM768
On Saturday, 27 October 2012 at 23:07:19 UTC, BLM768 wrote: In any case, though, separately initializing every member of an array is silly. That's what a loop is for. That, or a memcpy from an immutable copy of .init. I think that the reasoning behind DMD's implementation is that for