C++ guys hate static_if?
Timon Gehr
timon.gehr at gmx.ch
Thu Mar 14 13:57:56 PDT 2013
On 03/14/2013 06:51 PM, Andrei Alexandrescu wrote:
> On 3/14/13 1:48 PM, H. S. Teoh wrote:
>> I don't agree. Phobos is a prime example. Does Phobos have unittests?
>> Yes, and lots of them. Does it still have non-compilable template
>> instantiations? Yes, because unittests can't cover all possibilities --
>> there are too many possible combinations of template arguments. There
>> are bound to be untested combinations which don't work but we're unaware
>> of.
>
> If you found a few, that would be great. I don't think you'll have an
> easy time.
>
> Andrei
>
Challenge accepted. Clearly the Phobos developers do not instantiate
their templates before shipping them. :o)
The following breaks most of std.range, and most of std.algorithm could
likely be broken too, but I am too lazy to investigate.
import std.range, std.algorithm;
struct TrollFace{
@property string front()const{ return "troll"; }
@property string back()const{ return "face"; }
@property bool empty()const{ return true; }
void popFront()const{ }
void popBack()const{ }
@property inout(TrollFace) save()inout{ return this; }
auto opIndex(size_t index){ return front; }
@property size_t length()inout{ return 0; }
int* x;
}
struct TrollierFace{
TrollFace face;
alias face this;
@disable this(this);
@property inout(TrollierFace) save()inout{ return
inout(TrollierFace)(face); }
}
void main(){
immutable TrollFace a,b,c;
a.retro();
a.stride(2);
chain(a,b,c);
roundRobin(a,b,c);
a.radial();
a.radial(0);
a.take(2);
(immutable(TrollierFace)()).takeExactly(2);
(immutable(TrollierFace)()).takeOne();
(immutable(TrollierFace)()).takeNone();
(immutable(TrollierFace)()).drop(2);
(immutable(TrollierFace)()).dropExactly(0);
(immutable(TrollierFace)()).dropOne();
(immutable(TrollierFace)()).repeat();
a.cycle();
a.zip(b);
lockstep((immutable(TrollierFace)()),b);
a.frontTransversal();
a.transversal(0);
a.indexed([0]);
a.chunks(5);
a.filter!(a=>true);
a.map!(a=>a);
// ... (and so on)
}
More information about the Digitalmars-d
mailing list