Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
throwing Copyable versus throwing MoveOnly
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 #include <exception> #include <stdio.h> #include <typeinfo> struct Copyable { Copyable() { puts(" creating"); } Copyable(const Copyable&) { puts(" copying"); } ~Copyable() { puts(" destroying"); } }; struct MoveOnly { MoveOnly() { puts(" creating"); } MoveOnly(MoveOnly&&) { puts(" moving"); } ~MoveOnly() { puts(" destroying"); } }; using TYPE = Copyable; std::exception_ptr ex; int main() { try { printf("Throwing an exception of type %s...\n", typeid(TYPE).name()); throw TYPE(); } catch (...) { puts("Found the catch block."); puts("Now calling current_exception..."); ex = std::current_exception(); try { puts("Now calling rethrow_exception..."); std::rethrow_exception(ex); } catch (...) { puts("Found the next catch block."); } } puts("Now setting ex to nullptr..."); ex = nullptr; puts("Now exiting main()"); }
run
|
edit
|
history
|
help
0
#22.2
infix to postfix v 3.0
postfix eval in c++ - multidigits decimal
defined(FOO)
problem_solution_1
Visual Studio expand modified
Say if number is prime and give its factors
Additional layer of indirection
problem_solution5
fusion adapt 64 members v2