Re: Equivalents to policy classes in D

2012-04-21 Thread Joseph Rushton Wakeling
On 20/04/12 04:36, Joseph Rushton Wakeling wrote: On 03/04/12 02:24, Cristi Cobzarenco wrote: Mixins templates would be the answer: OK, I've had a go at writing up some mixin template-based policy code of my own. Oh, fun. You can even have the constructor provided by a template mixin ... !

Re: Equivalents to policy classes in D

2012-04-19 Thread Joseph Rushton Wakeling
On 03/04/12 02:24, Cristi Cobzarenco wrote: Mixins templates would be the answer: OK, I've had a go at writing up some mixin template-based policy code of my own. However ... it winds up with compilation errors that I can't decipher: mixin.d(55): Error: type

Re: Equivalents to policy classes in D

2012-04-19 Thread Andrej Mitrovic
On 4/20/12, Joseph Rushton Wakeling joseph.wakel...@webdrake.net wrote: void main() { auto oneOne = MyStruct!(size_t, GenOne, WriteOne); auto oneTwo = MyStruct!(double, GenOne, WriteTwo); auto threeOne = MyStruct!(double, GenThree, WriteOne); auto threeTwo =

Re: Equivalents to policy classes in D

2012-04-19 Thread Joseph Rushton Wakeling
On 20/04/12 04:41, Andrej Mitrovic wrote: You're doing the equivalent of: auto one = Foo; but you need: auto one = Foo(); Ah, clear. I'm an idiot -- I wrote my own constructor requiring a number as input! That said, I'm surprised that it accepts the () given that the constructor does ask

Re: Equivalents to policy classes in D

2012-04-19 Thread Andrej Mitrovic
On 4/20/12, Joseph Rushton Wakeling joseph.wakel...@webdrake.net wrote: That said, I'm surprised that it accepts the () given that the constructor does ask for a number. You can use: @disable this(); But it doesn't work in all cases: struct Foo { @disable this(); this(int i) { } }

Re: Equivalents to policy classes in D

2012-04-04 Thread Joseph Rushton Wakeling
Thanks to all for the useful suggestions here. I'll have a play with the ideas suggested and come back if problems arise ... :-)

Re: Equivalents to policy classes in D

2012-04-03 Thread Jacob Carlborg
On 2012-04-03 01:15, Joseph Rushton Wakeling wrote: Hello all, I'm coming to D from a background programming in C and C++, though I wouldn't describe myself as an expert in either. One of the C++ techniques I picked up over the last couple of years was the use of policy classes, and I'm

Equivalents to policy classes in D

2012-04-02 Thread Joseph Rushton Wakeling
Hello all, I'm coming to D from a background programming in C and C++, though I wouldn't describe myself as an expert in either. One of the C++ techniques I picked up over the last couple of years was the use of policy classes, and I'm wondering how D addresses this issue of combining

Re: Equivalents to policy classes in D

2012-04-02 Thread Cristi Cobzarenco
Mixins templates would be the answer: import std.exception; mixin template UncheckedIndices( T ) { ref T opIndex( int i ) { return this.get_( i ); } } mixin template CheckedIndices( T ) { ref T opIndex( int i ) { enforce( i 0 i this.size ); return this.get_( i ); } }

Re: Equivalents to policy classes in D

2012-04-02 Thread James Miller
On 3 April 2012 12:24, Cristi Cobzarenco cristi.cobzare...@gmail.com wrote: Mixins templates would be the answer: import std.exception; mixin template UncheckedIndices( T ) {   ref T opIndex( int i ) {     return this.get_( i );   } } mixin template CheckedIndices( T ) {   ref T

Re: Equivalents to policy classes in D

2012-04-02 Thread Henry Robbins Gouk
I'm not all that familiar with policy classes but, if I understand what you are asking correctly, you can provide implementations in interfaces if the methods are final or static. Is this the sort of thing you mean? import std.stdio; interface Foo { final string foo() {