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/typeof/std/string.hpp>
11#include <boost/typeof/std/map.hpp>
12#include <map>
13#include <string>
14#include <utility>
15
16int main(void) {
17 bool commit = false;
18 std::string currency("EUR");
19 double rate = 1.3326;
20 std::map<std::string, double> rates;
21 bool currency_rate_inserted =
22 rates.insert(x: std::make_pair(x&: currency, y&: rate)).second;
23
24 BOOST_SCOPE_EXIT( (currency_rate_inserted) (&commit) (&rates)
25 (&currency) ) {
26 if(currency_rate_inserted && !commit) rates.erase(x: currency);
27 } BOOST_SCOPE_EXIT_END
28
29 // ...
30
31 commit = true;
32
33 return 0;
34}
35
36

source code of boost/libs/scope_exit/example/scope_guard_seq.cpp