int main() { myclass a(0); if (a.content) std::cout << "This should not be happening" << std::endl; else std::cout << "Vanilla code has a bug" << std::endl; /* //this one is a compile error myclass aa(1); if (aa.content) std::cout << "correct "; else std::cout << "incorrect "; */ //this one should either pass or compile error myprotectedclass b(0); if (b.content) std::cout << "Solution has no bug, note that compilation error is acceptable as well for this case" << std::endl; else std::cout << "This should not be happening" << std::endl; //this one should either pass or compile error myprotectedclass bb(1); if (bb.content) std::cout << "correct "; else std::cout << "incorrect "; std::cout << "Further tests:" << std::endl; myprotectedclass c(boost::none); if (!c.content) std::cout << "correct "; else std::cout << "incorrect "; myprotectedclass d(myint(0)); if (d.content) std::cout << "correct "; else std::cout << "incorrect "; myprotectedclass e(myint(1)); if (e.content) std::cout << "correct "; else std::cout << "incorrect "; boost::optional<myint> foobar = boost::none; myprotectedclass f(foobar); if (!f.content) std::cout << "correct "; else std::cout << "incorrect "; boost::optional<myint> bar = myint(0); myprotectedclass g(bar); if (g.content) std::cout << "correct "; else std::cout << "incorrect "; boost::optional<myint> foo = myint(1); myprotectedclass h(foo); if (h.content) std::cout << "correct "; else std::cout << "incorrect "; }
int main() { /* // now this is a compile error myclass a(0); if (a.content) std::cout << "correct "; else std::cout << "incorrect "; */ /* //this one is a compile error too but that is less surprising myclass c(1); if (c.content) std::cout << "correct "; else std::cout << "incorrect "; */ myclass b(boost::none); if (!b.content) std::cout << "correct "; else std::cout << "incorrect "; myclass d(myint(0)); if (d.content) std::cout << "correct "; else std::cout << "incorrect "; myclass e(myint(1)); if (e.content) std::cout << "correct "; else std::cout << "incorrect "; boost::optional<myint> foobar = boost::none; myclass h(foobar); if (!h.content) std::cout << "correct "; else std::cout << "incorrect "; boost::optional<myint> bar = myint(0); myclass g(bar); if (g.content) std::cout << "correct "; else std::cout << "incorrect "; boost::optional<myint> foo = myint(1); myclass f(foo); if (f.content) std::cout << "correct "; else std::cout << "incorrect "; }
int main() { myclass a(0); if (a.content) std::cout << "correct "; else std::cout << "incorrect "; myclass b(boost::none); if (!b.content) std::cout << "correct "; else std::cout << "incorrect "; myclass c(1); if (c.content) std::cout << "correct "; else std::cout << "incorrect "; myclass d(myint(0)); if (d.content) std::cout << "correct "; else std::cout << "incorrect "; myclass e(myint(1)); if (e.content) std::cout << "correct "; else std::cout << "incorrect "; }
int main () { mycontainer<int> myint (7); mycontainer<char> mychar ('j'); return 0; }
boost::optional<myint> myintctor(int arg) {return myint(arg);}
boost::optional<myint> myintctor(const myint& arg) {return myint(arg);}