native_tpl.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/rational.hpp>
  9. #include <boost/typeof/typeof.hpp>
  10. #include <boost/typeof/std/vector.hpp>
  11. #include <boost/detail/lightweight_test.hpp>
  12. #include <vector>
  13. template<class type>
  14. void tpl_long(
  15. type tval
  16. , type & t
  17. , type const& tc
  18. , type volatile& tv
  19. , type const volatile& tcv
  20. ) {
  21. int i = 0; // non-dependent name
  22. type const remember(tval);
  23. {
  24. BOOST_SCOPE_EXIT_TPL( (&tval) (&t) (&tc) (&tv) (&tcv) (&i) ) {
  25. tval = 1;
  26. ++t;
  27. ++tv;
  28. } BOOST_SCOPE_EXIT_END
  29. BOOST_TEST(t == remember);
  30. BOOST_TEST(tval == remember);
  31. }
  32. BOOST_TEST(tval == 1);
  33. BOOST_TEST(t == remember + 2);
  34. }
  35. template<class Vector, int Value>
  36. void tpl_vector(
  37. Vector vval
  38. , Vector & v
  39. , Vector const& vc
  40. ) {
  41. Vector const remember(vval);
  42. {
  43. BOOST_SCOPE_EXIT_TPL( (&vval) (&v) (&vc) ) {
  44. v.push_back(-Value);
  45. vval.push_back(Value);
  46. } BOOST_SCOPE_EXIT_END
  47. BOOST_TEST(v.size() == remember.size());
  48. BOOST_TEST(vval.size() == remember.size());
  49. }
  50. BOOST_TEST(v.size() == 1 + remember.size());
  51. BOOST_TEST(vval.size() == 1 + remember.size());
  52. }
  53. int main(void) {
  54. long l = 137;
  55. tpl_long(l, l, l, l, l);
  56. std::vector<int> v(10, 137);
  57. tpl_vector<std::vector<int>, 13>(v, v, v);
  58. return boost::report_errors();
  59. }