Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <type_traits>
- #include <utility>
- #include <memory>
- #include <iostream>
- #include <cstdlib>
- #include <cassert>
- namespace
- {
- template< typename lambda >
- auto
- make_scope_guard(lambda && _lambda)
- {
- struct lambda_caller
- {
- using pointer = std::decay_t< lambda >;
- void
- operator () (pointer l) const noexcept
- {
- std::forward< lambda >(l)();
- }
- };
- return std::unique_ptr< std::decay_t< lambda >, lambda_caller >(std::forward< lambda >(_lambda));
- }
- }
- int
- main()
- {
- std::cout << 1 << std::endl;
- {
- std::cout << 2 << std::endl;
- [[gnu::unused]] auto && guard_ = make_scope_guard([&] { std::cout << __PRETTY_FUNCTION__ << std::endl; });
- std::cout << 3 << std::endl;
- }
- std::cout << 5 << std::endl;
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement