July 11, 2005
> template ivDetector(alias V )
> {
>    auto IvStorage __ts  = new IvStorage( V, (*V).sizeof  );
> }
>
> class IvStrorage
> {
>    void[] _data;
>    void* _p;
>    this( void* p, uint sz ) { _p = p; _data = p[ 0..sz ]; }
>    ~this(  ) { compare data here and rise exception if... } // bad, but....
> }
>
> And use it as:
>
> int* somePointer;
> //immutable (somePointer)
> {
>   mixin ivDetector!(somePointer);
>    // Statements...
> }
>
> Will it work for you?

Nah, you cannot use local variable as template alias parameters. But you are right, this is possible with a little template magic and auto classes.

Ciao
uwe
1 2
Next ›   Last »