July 11, 2005 Re: Round V, Immutable arrays and pointers. Possible implementation. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrew Fedoniouk | > 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
|
Copyright © 1999-2021 by the D Language Foundation