BitArray/BitFields - Reworking with templates

Dmitry Olshansky dmitry.olsh at gmail.com
Mon Jul 30 13:19:49 PDT 2012


On 30-Jul-12 23:50, Era Scarecrow wrote:
> On Sunday, 29 July 2012 at 12:39:13 UTC, Era Scarecrow wrote:
>>  But having them statically separated by name/type seems much more
>> likely to be safer in the long run with reliable results.
>
>   A question regarding templates. A template with different parameters
> is completely incompatible correct? So...
>

Yeah, like twin brothers the have different IDs :)

> struct X(T) {
> }
>
> alias X!bool XB;
> alias X!int XI;
>
> void func(XB xb) {
>
> }
>
> func(XB()); //works
> func(XI()); //should fail to compile
>
> Same if it was built differently? so...
>
> template X(bool something) //'bool something' should be statically
> checkable
>    struct XY {
>      static if (something) {
>        //conditional functions or code
>      }
>      XY makeX(){
>        //XY type is only currently formed template version correct?
>        return XY();
>      }
>    }
> }
>
> //against above func, with these two...
> alias X!(false).XY XB;
> alias X!(true).XY XI;
>
> Course if there's a way to avoid asking about the inner XY, I wonder how
> I would do that.
>
>
>   Now if all that is correct, say I want to make two functions that both
> use X, but are not compatible, but template functions will allow it. So...
>
> void tempFunc(T, U)(T t, U u)
> if(
>    //What do i enter to check they are both template X or struct XY? As
> signatures will be different...
> )
> body{
>    //now acts as a middle-man to be compatible for said operation
> }
>

Not sure what you would like to accomplish here.

> alias X!(true).XY Xtrue;
>
> pure function 'func' cannot call impure function '__cpctor'
> safe function 'func' cannot call system function '__cpctor'

Yeah, it's a bug. File it please.

-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list