native_this.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (C) 2006-2009, 2012 Alexander Nasonov
  2. // Copyright (C) 2012 Lorenzo Caminiti
  3. // Distributed under the Boost Software License, Version 1.0
  4. // (see accompanying file LICENSE_1_0.txt or a copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // Home at http://www.boost.org/libs/scope_exit
  7. #include <boost/scope_exit.hpp>
  8. #include <boost/config.hpp>
  9. #include <boost/typeof/typeof.hpp>
  10. #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
  11. #include <boost/detail/lightweight_test.hpp>
  12. struct this_tester;
  13. BOOST_TYPEOF_REGISTER_TYPE(this_tester) // Register before `this_` capture.
  14. struct this_tester {
  15. void check(void) {
  16. value_ = -1;
  17. BOOST_SCOPE_EXIT( (this_) ) {
  18. BOOST_TEST(this_->value_ == 0);
  19. } BOOST_SCOPE_EXIT_END
  20. #ifndef BOOST_NO_CXX11_LAMBDAS
  21. BOOST_SCOPE_EXIT_ALL(&, this) {
  22. BOOST_TEST(this->value_ == 0);
  23. };
  24. #endif // lambdas
  25. value_ = 0;
  26. }
  27. private:
  28. int value_;
  29. };
  30. int main(void) {
  31. this_tester().check();
  32. return boost::report_errors();
  33. }