BitArray/BitFields - Reworking with templates
Era Scarecrow
rtcvb32 at yahoo.com
Mon Jul 30 12:50:07 PDT 2012
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...
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
}
Finally, I came across an anomaly and may just be a bug. What
about a postblits?
T func2(T)(T x) @safe pure {
return T();
}
struct XY {
this(this) @safe pure {} //safe pure added so func can call it
void func(XY x) @safe pure {
XY y = x; //postblits called on all three lines
func2(x);
func2(y);
}
}
template X(bool something) {
struct XY {
this(this) @safe pure {}
void func(XY x) @safe pure {
XY y = x; //Error: see below
func2(x);
func2(y);
}
}
}
alias X!(true).XY Xtrue;
pure function 'func' cannot call impure function '__cpctor'
safe function 'func' cannot call system function '__cpctor'
More information about the Digitalmars-d-learn
mailing list