summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/scope_exit/test/native_this.cpp
blob: e6254786eba4bf3d1549c58312ddd3cd9d247ee2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (C) 2006-2009, 2012 Alexander Nasonov
// Copyright (C) 2012 Lorenzo Caminiti
// Distributed under the Boost Software License, Version 1.0
// (see accompanying file LICENSE_1_0.txt or a copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Home at http://www.boost.org/libs/scope_exit

#include <boost/scope_exit.hpp>
#include <boost/config.hpp>
#include <boost/typeof/typeof.hpp>
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
#include <boost/detail/lightweight_test.hpp>

struct this_tester;
BOOST_TYPEOF_REGISTER_TYPE(this_tester) // Register before `this_` capture.

struct this_tester {
    void check(void) {
        value_ = -1;

        BOOST_SCOPE_EXIT( (this_) ) {
            BOOST_TEST(this_->value_ == 0);
        } BOOST_SCOPE_EXIT_END

#ifndef BOOST_NO_CXX11_LAMBDAS
        BOOST_SCOPE_EXIT_ALL(&, this) {
            BOOST_TEST(this->value_ == 0);
        };
#endif // lambdas

        value_ = 0;
    }

private:
    int value_;
};

int main(void) {
    this_tester().check();
    return boost::report_errors();
}