int main() { A* am = new B; const A* an = am; B* bm = memoized_cast<B*>(am); XTL_UNUSED(bm); // memoized_cast<B*>(an); const B* bn1 = memoized_cast<const B*>(am); XTL_UNUSED(bn1); const B* bn2 = memoized_cast<const B*>(an); XTL_UNUSED(bn2); const A* a = new A; const B* b = new B; const C* c = new C; const D* d = new D; const E* e = new E; const F* f = new F; const G* g = new G; //A* ca = (C::A*)c dump_hex(*a); dump_hex(*b); dump_hex(*c); dump_hex(*d); dump_hex(*e); dump_hex(*f); dump_hex(*g); const A* a1 = (const B*)(const C*)e; const E* e1 = memoized_cast<const E*>(a1); XTL_UNUSED(e1); const E* e2 = memoized_cast<const E*>(a1); XTL_UNUSED(e2); XTL_ASSERT(e1 == e && e2 == e); }
void time_dummy(Shape& s) { const int N = 10000; int c1,c2; mch::time_stamp liStart1 = mch::get_time_stamp(); for (int i = 0; i < N; ++i) c1 = dummy_vis(&s); mch::time_stamp liFinish1 = mch::get_time_stamp(); mch::time_stamp liStart2 = mch::get_time_stamp(); for (int i = 0; i < N; ++i) c2 = dummy(&s); mch::time_stamp liFinish2 = mch::get_time_stamp(); mch::time_stamp liStart3 = mch::get_time_stamp(); for (int i = 0; i < N; ++i) c2 = dummy_dyn(&s); mch::time_stamp liFinish3 = mch::get_time_stamp(); XTL_ASSERT(c1==c2); XTL_UNUSED(c1); XTL_UNUSED(c2); std::cout << "DummyV Time:" << mch::microseconds(liFinish1-liStart1) << std::endl; std::cout << "DummyD Time:" << mch::microseconds(liFinish3-liStart3) << std::endl; std::cout << "DummyM Time:" << mch::microseconds(liFinish2-liStart2) << std::endl; std::cout << (liFinish3-liStart3)*100/(liFinish1-liStart1)-100 << "% slower" << std::endl; std::cout << (liFinish2-liStart2)*100/(liFinish1-liStart1)-100 << "% slower" << std::endl; }
void test_autodecl(const Shape* shape) { double m = 0.0; Match(shape) { Case(Circle,c,r) std::cout << "Circle" << std::endl; m += r; XTL_UNUSED(c); break; Case(Square,c,s) std::cout << "Square" << std::endl; m += s; XTL_UNUSED(c); break; Case(Triangle,p) std::cout << "Triangle" << std::endl; m += p.first; break; Otherwise() std::cout << "Other" << std::endl; m += 2; break; } EndMatch }
void do_match(const Shape* s0) { const char* text = "unknown"; Match(s0) { Case(const Circle& a) text = "C"; XTL_UNUSED(a); break; Case(const Square& a) text = "S"; XTL_UNUSED(a); break; Case(const Triangle& a) text = "T"; XTL_UNUSED(a); break; Otherwise() text = "other"; break; } EndMatch std::cout << text << std::endl; }
int main() { #ifdef POD_ONLY ADTShape ac = {ADTShape::circle, {{{1,1}, 7}}}; ADTShape as = {ADTShape::square, {{{1,1}, 2}}}; ADTShape at = {ADTShape::triangle, {{{1,1}, 1}}}; #else cloc l00 = {0,0}; cloc l11 = {1,1}; cloc l10 = {1,0}; ADTShape ac(l11, 7); ADTShape as(2, l11); ADTShape at(l11, l10, l00); #endif //ADTShape* adtshapes[] = {&ac,&as,&at}; Shape* c = new Circle(loc(1,1),7); Shape* s = new Square(loc(1,1),2); Shape* t = new Triangle(loc(1,1),loc(1,0),loc(0,0)); const Shape* shapes[] = {c,s,t}; //wildcard _; //double x; mch::var<double> v; loc l; //cloc cl; double m = 0.0; for (size_t i = 0; i < 3; ++i) { MatchF(shapes[i]) { CaseF(Shape) std::cout << "Shape" << std::endl; m += 42; break; CaseF(Circle,_,r) std::cout << "Circle" << std::endl; m += r; XTL_UNUSED(_); break; CaseF(Square,_,r) std::cout << "Square" << std::endl; m += r; XTL_UNUSED(_); break; CaseF(Triangle,p) std::cout << "Triangle" << std::endl; m += p.first; break; } EndMatchF } std::cout << m << std::endl; }
void time_center(Shape& s) { const int N = 10000; loc c1,c2; mch::time_stamp liStart1 = mch::get_time_stamp(); for (int i = 0; i < N; ++i) c1 = center_vis(s); mch::time_stamp liFinish1 = mch::get_time_stamp(); mch::time_stamp liStart2 = mch::get_time_stamp(); for (int i = 0; i < N; ++i) c2 = center(s); mch::time_stamp liFinish2 = mch::get_time_stamp(); XTL_ASSERT(c1==c2); XTL_UNUSED(c1); XTL_UNUSED(c2); std::cout << "CenterV Time:" << mch::microseconds(liFinish1-liStart1) << std::endl; std::cout << "CenterM Time:" << mch::microseconds(liFinish2-liStart2) << std::endl; std::cout << (liFinish2-liStart2)*100/(liFinish1-liStart1)-100 << "% slower" << std::endl; }
void time_area(Shape& s) { const int N = 10000; double a1,a2; mch::time_stamp liStart1 = mch::get_time_stamp(); for (int i = 0; i < N; ++i) a1 = area_vis(s); mch::time_stamp liFinish1 = mch::get_time_stamp(); mch::time_stamp liStart2 = mch::get_time_stamp(); for (int i = 0; i < N; ++i) a2 = area(s); mch::time_stamp liFinish2 = mch::get_time_stamp(); XTL_ASSERT(a1==a2); XTL_UNUSED(a1); XTL_UNUSED(a2); std::cout << "AreaV Time:" << mch::microseconds(liFinish1-liStart1) << std::endl; std::cout << "AreaM Time:" << mch::microseconds(liFinish2-liStart2) << std::endl; std::cout << (liFinish2-liStart2)*100/(liFinish1-liStart1)-100 << "% slower" << std::endl; }
void do_match(const Shape* s0, const Shape* s1) { const char* text = "unknown"; Match(s0,s1) { //Case(const Circle& a, const Circle& b) text = "C,C"; XTL_UNUSED(a); XTL_UNUSED(b); break; Case(const Circle& a, const Square& b) text = "C,S"; XTL_UNUSED(a); XTL_UNUSED(b); break; Case(const Square& a, const Circle& b) text = "S,C"; XTL_UNUSED(a); XTL_UNUSED(b); break; //Case(const Square& a, const Square& b) text = "S,S"; XTL_UNUSED(a); XTL_UNUSED(b); break; Case(const Square& a, const Triangle& b) text = "S,T"; XTL_UNUSED(a); XTL_UNUSED(b); break; Case(const Triangle& a, const Square& b) text = "T,S"; XTL_UNUSED(a); XTL_UNUSED(b); break; Case(const Triangle& a, const Triangle& b) text = "T,T"; XTL_UNUSED(a); XTL_UNUSED(b); break; Case(const Triangle& a, const Circle& b) text = "T,C"; XTL_UNUSED(a); XTL_UNUSED(b); break; Case(const Circle& a, const Triangle& b) text = "C,T"; XTL_UNUSED(a); XTL_UNUSED(b); break; Otherwise() text = "other"; break; }