1
2// Copyright (C) 2006-2009, 2012 Alexander Nasonov
3// Copyright (C) 2012 Lorenzo Caminiti
4// Distributed under the Boost Software License, Version 1.0
5// (see accompanying file LICENSE_1_0.txt or a copy at
6// http://www.boost.org/LICENSE_1_0.txt)
7// Home at http://www.boost.org/libs/scope_exit
8
9#include <boost/scope_exit.hpp>
10#include <boost/rational.hpp>
11#include <boost/typeof/typeof.hpp>
12#include <boost/typeof/std/vector.hpp>
13#include <boost/detail/lightweight_test.hpp>
14#include <vector>
15
16template<class type>
17void tpl_long(
18 type tval
19 , type & t
20 , type const& tc
21 , type volatile& tv
22 , type const volatile& tcv
23) {
24 int i = 0; // non-dependent name
25 type const remember(tval);
26
27 {
28 BOOST_SCOPE_EXIT_TPL( (&tval) (&t) (&tc) (&tv) (&tcv) (&i) ) {
29 tval = 1;
30 ++t;
31 ++tv;
32 } BOOST_SCOPE_EXIT_END
33
34 BOOST_TEST(t == remember);
35 BOOST_TEST(tval == remember);
36 }
37
38 BOOST_TEST(tval == 1);
39 BOOST_TEST(t == remember + 2);
40}
41
42template<class Vector, int Value>
43void tpl_vector(
44 Vector vval
45 , Vector & v
46 , Vector const& vc
47) {
48 Vector const remember(vval);
49
50 {
51 BOOST_SCOPE_EXIT_TPL( (&vval) (&v) (&vc) ) {
52 v.push_back(-Value);
53 vval.push_back(Value);
54 } BOOST_SCOPE_EXIT_END
55
56 BOOST_TEST(v.size() == remember.size());
57 BOOST_TEST(vval.size() == remember.size());
58 }
59
60 BOOST_TEST(v.size() == 1 + remember.size());
61 BOOST_TEST(vval.size() == 1 + remember.size());
62}
63
64int main(void) {
65 long l = 137;
66 tpl_long(tval: l, t&: l, tc: l, tv&: l, tcv: l);
67
68 std::vector<int> v(10, 137);
69 tpl_vector<std::vector<int>, 13>(vval: v, v, vc: v);
70
71 return boost::report_errors();
72}
73
74

source code of boost/libs/scope_exit/test/native_tpl.cpp