Created
April 13, 2014 12:50
-
-
Save usagi/10582793 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <boost/scope_exit.hpp> | |
| // test scope 1 | |
| auto main() -> int | |
| { | |
| BOOST_SCOPE_EXIT_ALL() | |
| { std::cerr << "scope 1 exit 1\n"; }; | |
| BOOST_SCOPE_EXIT_ALL() | |
| { std::cerr << "scope 1 exit 2\n"; }; | |
| // test scope 2 | |
| { | |
| auto s2a = new double(1.23); | |
| BOOST_SCOPE_EXIT_ALL(s2a) | |
| { std::cerr << "scope 2 exit 1 with delete (=,s2a)\n"; delete s2a; }; | |
| auto s2b = 0; | |
| BOOST_SCOPE_EXIT_ALL(&s2b) | |
| { std::cerr << "scope 2 exit 2 with ++ (&,s2b): " << ++s2b << "\n"; }; | |
| BOOST_SCOPE_EXIT_ALL(&s2b) | |
| { std::cerr << "scope 2 exit 3 with ++ (&,s2b): " << ++s2b << "\n"; }; | |
| } | |
| BOOST_SCOPE_EXIT_ALL() | |
| { std::cerr << "scope 1 exit 3\n"; }; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| scope 2 exit 3 with ++ (&,s2b): 1 | |
| scope 2 exit 2 with ++ (&,s2b): 2 | |
| scope 2 exit 1 with delete (=,s2a) | |
| scope 1 exit 3 | |
| scope 1 exit 2 | |
| scope 1 exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment