Re: Using opDispatch as *magic* getter/setter. Possible or not?

2011-03-30 Thread Jacob Carlborg
On 3/31/11 2:32 AM, Aleksandar Ružičić wrote: Is it possible to use opDispatch as generic getter and setter at the same time? Something like __get() and __set() in PHP.. this is what I've tried: https://gist.github.com/895571 and I get Error: template instance opDispatch!("bar") matches more th

Re: template template parameter

2011-03-30 Thread Ali Çehreli
On 03/30/2011 04:32 PM, Caligo wrote: I have a struct that looks something like this: struct Box(T, size_t width, size_t height){ alias width width_; alias height height_; //do something with a Box of different size void Fun( B )(B b){ // using width and height of b B.width_;

Re: Using opDispatch as *magic* getter/setter. Possible or not?

2011-03-30 Thread spir
On 03/31/2011 02:40 AM, Aleksandar Ružičić wrote: 2011/3/31 Aleksandar Ružičić: Or maybe there is some other way to achive what I want and I'm not aware of it? :-) I know I could have used opIndex and opIndexAssign but I really want config.section.entry syntax instead of config["section"]["e

Using opDispatch as *magic* getter/setter. Possible or not?

2011-03-30 Thread Aleksandar Ružičić
Is it possible to use opDispatch as generic getter and setter at the same time? Something like __get() and __set() in PHP.. this is what I've tried: https://gist.github.com/895571 and I get Error: template instance opDispatch!("bar") matches more than one template declaration, path\to\test.d(57):

Re: Using opDispatch as *magic* getter/setter. Possible or not?

2011-03-30 Thread Aleksandar Ružičić
2011/3/31 Aleksandar Ružičić : > > Or maybe there is some other way to achive what I want and I'm not > aware of it? :-) > I know I could have used opIndex and opIndexAssign but I really want config.section.entry syntax instead of config["section"]["entry"]...

template template parameter

2011-03-30 Thread Caligo
I have a struct that looks something like this: struct Box(T, size_t width, size_t height){ alias width width_; alias height height_; //do something with a Box of different size void Fun( B )(B b){ // using width and height of b B.width_; B.height_; } } auto b1 = Box!(double, 2,

Re: Contracts or Exceptions?

2011-03-30 Thread bearophile
Jonathan M Davis: > Naturally, the executation time does vary some, but it's consistently over > 400 > times (and generally more like 450 times) more expensive to have the > exception > be thrown and caught than it is to have it not be thrown. On Windows in a benchmark I've seen thrown except

Re: Contracts or Exceptions?

2011-03-30 Thread Jonathan M Davis
On 2011-03-30 14:05, Ali Çehreli wrote: > On 03/30/2011 12:40 PM, Jonathan M Davis wrote: > > On 2011-03-30 05:09, spir wrote: > >> On 03/30/2011 05:32 AM, Ali Çehreli wrote: > >>> On 03/29/2011 03:40 PM, Kai Meyer wrote: > I was given two words of advice on exceptions: > "Use excepti

Re: Contracts or Exceptions?

2011-03-30 Thread Ali Çehreli
On 03/30/2011 12:40 PM, Jonathan M Davis wrote: On 2011-03-30 05:09, spir wrote: On 03/30/2011 05:32 AM, Ali Çehreli wrote: On 03/29/2011 03:40 PM, Kai Meyer wrote: I was given two words of advice on exceptions: "Use exceptions for the exceptional" "Use exceptions only for the exceptiona

Re: Contracts or Exceptions?

2011-03-30 Thread Jonathan M Davis
On 2011-03-30 05:09, spir wrote: > On 03/30/2011 05:32 AM, Ali Çehreli wrote: > > On 03/29/2011 03:40 PM, Kai Meyer wrote: > >> I was given two words of advice on exceptions: > >> "Use exceptions for the exceptional" > >> "Use exceptions only for the exceptional" > > > > Those advices are given

Re: Can I use a delegate as a template parameter? (Issue 2962?)

2011-03-30 Thread Simen kjaeraas
On Wed, 30 Mar 2011 14:07:51 +0200, Magnus Lie Hetland wrote: A while ago, I wrote something like this: void C(alias foo)() { void bar() { foo(); } bar(); } void B(T)(uint x=2) { uint foo() { return x; } C!foo(); } Also, aside from the erratic DMD be

Re: Contracts or Exceptions?

2011-03-30 Thread Ali Çehreli
On 03/30/2011 08:42 AM, Kai Meyer wrote: > we were talking about what sort of things you can do to > increase performance Sorry to change the topic. :) I am fortunate that what I currently work on does not require more than being careful about not using the wrong algorithms and data structures

Re: Contracts or Exceptions?

2011-03-30 Thread Kai Meyer
On 03/29/2011 09:32 PM, Ali Çehreli wrote: On 03/29/2011 03:40 PM, Kai Meyer wrote: > I was given two words of advice on exceptions: > "Use exceptions for the exceptional" > "Use exceptions only for the exceptional" Those advices are given by wise people: they are wise only because they leav

Re: Contracts or Exceptions?

2011-03-30 Thread Kai Meyer
On 03/30/2011 08:25 AM, Kagamin wrote: Kai Meyer Wrote: do all the checking before hand. Arrays are a good example. When not in -release mode, array boundaries are checked upon every access to the array, and an exception is thrown if access goes out of bounds. In -release mode, if you go out of

Re: Memory usage of AAs?

2011-03-30 Thread spir
On 03/30/2011 03:31 PM, Steven Schveighoffer wrote: On Tue, 29 Mar 2011 22:20:05 -0400, Nick Sabalausky wrote: "spir" wrote in message news:mailman.2909.1301443345.4748.digitalmars-d-le...@puremagic.com... On 03/30/2011 01:24 AM, Nick Sabalausky wrote: My understanding of hash tables is tha

Re: Contracts or Exceptions?

2011-03-30 Thread Kagamin
Kai Meyer Wrote: > do all the checking before hand. Arrays are a good example. When not in > -release mode, array boundaries are checked upon every access to the > array, and an exception is thrown if access goes out of bounds. In > -release mode, if you go out of bounds you get a segfault. No

Re: Contracts or Exceptions?

2011-03-30 Thread Kagamin
Mike Linford Wrote: > Hello, > > So I'm writing a function for a library. It takes a struct as an > argument. The struct's fields can't just be any old values, though. The > function won't work if some of the fields are weird. It could return an > erroneous value, or even crash. > > The thin

Re: Memory usage of AAs?

2011-03-30 Thread Steven Schveighoffer
On Tue, 29 Mar 2011 22:20:05 -0400, Nick Sabalausky wrote: "spir" wrote in message news:mailman.2909.1301443345.4748.digitalmars-d-le...@puremagic.com... On 03/30/2011 01:24 AM, Nick Sabalausky wrote: My understanding of hash tables is that they allocate a fixed size array and map keys to

Can I use a delegate as a template parameter? (Issue 2962?)

2011-03-30 Thread Magnus Lie Hetland
A while ago, I wrote something like this: void C(alias foo)() { void bar() { foo(); } bar(); } void B(T)(uint x=2) { uint foo() { return x; } C!foo(); } It worked well, so I didn't think any more about it. Then suddenly, I started getting the following error:

Re: Contracts or Exceptions?

2011-03-30 Thread spir
On 03/30/2011 05:32 AM, Ali Çehreli wrote: On 03/29/2011 03:40 PM, Kai Meyer wrote: I was given two words of advice on exceptions: "Use exceptions for the exceptional" "Use exceptions only for the exceptional" Those advices are given by wise people: they are wise only because they leave th