native_this_tpl.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. template<typename T>
  13. struct this_tester;
  14. BOOST_TYPEOF_REGISTER_TEMPLATE(this_tester, 1) // Before`this_` capture.
  15. template<typename T>
  16. struct this_tester {
  17. void check(void) {
  18. value_ = -1;
  19. BOOST_SCOPE_EXIT_TPL( (this_) ) {
  20. BOOST_TEST(this_->value_ == 0);
  21. } BOOST_SCOPE_EXIT_END
  22. #ifndef BOOST_NO_CXX11_LAMBDAS
  23. BOOST_SCOPE_EXIT_ALL(&, this) {
  24. BOOST_TEST(this->value_ == 0);
  25. };
  26. #endif // lambdas
  27. value_ = 0;
  28. }
  29. private:
  30. T value_;
  31. };
  32. int main(void) {
  33. this_tester<int>().check();
  34. return boost::report_errors();
  35. }