Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70240 - sandbox/local/libs/local/example
From: lorcaminiti_at_[hidden]
Date: 2011-03-20 20:16:40


Author: lcaminiti
Date: 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
New Revision: 70240
URL: http://svn.boost.org/trac/boost/changeset/70240

Log:
Reorg examples.
Added:
   sandbox/local/libs/local/example/add_function.cpp
      - copied, changed from r70142, /sandbox/local/libs/local/example/add_num_factor_sum.cpp
   sandbox/local/libs/local/example/add_function_va.cpp
      - copied, changed from r70142, /sandbox/local/libs/local/example/add_num_factor_sum_va.cpp
   sandbox/local/libs/local/example/scope_guards_errno_va.cpp (contents, props changed)
   sandbox/local/libs/local/example/scope_guards_except_va.cpp (contents, props changed)
   sandbox/local/libs/local/example/world_exit.cpp
      - copied, changed from r70142, /sandbox/local/libs/local/example/exit.cpp
   sandbox/local/libs/local/example/world_exit_va.cpp
      - copied, changed from r70142, /sandbox/local/libs/local/example/exit_va.cpp
Removed:
   sandbox/local/libs/local/example/add_num_factor_sum.cpp
   sandbox/local/libs/local/example/add_num_factor_sum_default.cpp
   sandbox/local/libs/local/example/add_num_factor_sum_default_va.cpp
   sandbox/local/libs/local/example/add_num_factor_sum_va.cpp
   sandbox/local/libs/local/example/add_num_factor_sum_with_default_va.cpp
   sandbox/local/libs/local/example/add_num_sum.cpp
   sandbox/local/libs/local/example/add_num_sum_va.cpp
   sandbox/local/libs/local/example/block.cpp
   sandbox/local/libs/local/example/block_va.cpp
   sandbox/local/libs/local/example/exit.cpp
   sandbox/local/libs/local/example/exit_va.cpp
Text files modified:
   sandbox/local/libs/local/example/add_function.cpp | 2 +-
   sandbox/local/libs/local/example/add_function_va.cpp | 2 +-
   sandbox/local/libs/local/example/add_this.cpp | 9 +++++++++
   sandbox/local/libs/local/example/find_if.cpp | 2 ++
   sandbox/local/libs/local/example/find_if_va.cpp | 2 ++
   sandbox/local/libs/local/example/world_exit.cpp | 3 ++-
   sandbox/local/libs/local/example/world_exit_va.cpp | 2 ++
   7 files changed, 19 insertions(+), 3 deletions(-)

Copied: sandbox/local/libs/local/example/add_function.cpp (from r70142, /sandbox/local/libs/local/example/add_num_factor_sum.cpp)
==============================================================================
--- /sandbox/local/libs/local/example/add_num_factor_sum.cpp (original)
+++ sandbox/local/libs/local/example/add_function.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
@@ -4,7 +4,7 @@
 // License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
 // copy at http://www.boost.org/LICENSE_1_0.txt).
 
-//[ add_num_factor_sum_cpp
+//[ add_function_cpp
 #include <boost/local/function.hpp>
 #include <iostream>
 

Copied: sandbox/local/libs/local/example/add_function_va.cpp (from r70142, /sandbox/local/libs/local/example/add_num_factor_sum_va.cpp)
==============================================================================
--- /sandbox/local/libs/local/example/add_num_factor_sum_va.cpp (original)
+++ sandbox/local/libs/local/example/add_function_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
@@ -4,7 +4,7 @@
 // License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
 // copy at http://www.boost.org/LICENSE_1_0.txt).
 
-//[ add_num_factor_sum_va_cpp
+//[ add_function_va_cpp
 #include <boost/local/function.hpp>
 #include <iostream>
 

Deleted: sandbox/local/libs/local/example/add_num_factor_sum.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_num_factor_sum.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,25 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-//[ add_num_factor_sum_cpp
-#include <boost/local/function.hpp>
-#include <iostream>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- void BOOST_LOCAL_FUNCTION_PARAMS( (double num) (const bind factor)
- (bind& sum) ) {
- sum += factor * num;
- std::clog << "Summed: " << sum << std::endl;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- add(100.0);
- return 0;
-}
-//]
-

Deleted: sandbox/local/libs/local/example/add_num_factor_sum_default.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_num_factor_sum_default.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,25 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-//[ add_num_factor_sum_default_cpp
-#include <boost/local/function.hpp>
-#include <iostream>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- void BOOST_LOCAL_FUNCTION_PARAMS( (double num)(default +1.23)
- (const bind factor) (bind& sum) ) {
- sum += factor * num;
- std::clog << "Summed: " << sum << std::endl;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- add();
- return 0;
-}
-//]
-

Deleted: sandbox/local/libs/local/example/add_num_factor_sum_default_va.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_num_factor_sum_default_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,25 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-//[ add_num_factor_sum_default_va_cpp
-#include <boost/local/function.hpp>
-#include <iostream>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- void BOOST_LOCAL_FUNCTION_PARAMS(double num, default +1.23,
- const bind factor, bind& sum) {
- sum += factor * num;
- std::clog << "Summed: " << sum << std::endl;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- add();
- return 0;
-}
-//]
-

Deleted: sandbox/local/libs/local/example/add_num_factor_sum_va.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_num_factor_sum_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,25 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-//[ add_num_factor_sum_va_cpp
-#include <boost/local/function.hpp>
-#include <iostream>
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- void BOOST_LOCAL_FUNCTION_PARAMS(double num, const bind factor,
- bind& sum) {
- sum += factor * num;
- std::clog << "Summed: " << sum << std::endl;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- add(100.0);
- return 0;
-}
-//]
-

Deleted: sandbox/local/libs/local/example/add_num_factor_sum_with_default_va.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_num_factor_sum_with_default_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,27 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-//[ add_num_factor_sum_with_default_va_cpp
-#include <boost/local/function.hpp>
-#include <iostream>
-
-#define WITH_DEFAULT(value) , default value
-
-int main() {
- double sum = 0.0;
- int factor = 10;
-
- void BOOST_LOCAL_FUNCTION_PARAMS(double num WITH_DEFAULT(+1.23),
- const bind factor, bind& sum) {
- sum += factor * num;
- std::clog << "Summed: " << sum << std::endl;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- add();
- return 0;
-}
-//]
-

Deleted: sandbox/local/libs/local/example/add_num_sum.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_num_sum.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,23 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-//[ add_num_sum_cpp
-#include <boost/local/function.hpp>
-#include <iostream>
-
-int main() {
- double sum = 0.0;
-
- void BOOST_LOCAL_FUNCTION_PARAMS( (double num) (bind& sum) ) {
- sum += num;
- std::clog << "Summed: " << sum << std::endl;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- add(100.0);
- return 0;
-}
-//]
-

Deleted: sandbox/local/libs/local/example/add_num_sum_va.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_num_sum_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,23 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-//[ add_num_sum_va_cpp
-#include <boost/local/function.hpp>
-#include <iostream>
-
-int main() {
- double sum = 0.0;
-
- void BOOST_LOCAL_FUNCTION_PARAMS(double num, bind& sum) {
- sum += num;
- std::clog << "Summed: " << sum << std::endl;
- } BOOST_LOCAL_FUNCTION_NAME(add)
-
- add(100.0);
- return 0;
-}
-//]
-

Modified: sandbox/local/libs/local/example/add_this.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_this.cpp (original)
+++ sandbox/local/libs/local/example/add_this.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
@@ -22,6 +22,15 @@
             std::clog << "Summed: " << this_->sum_ << std::endl;
         } BOOST_LOCAL_FUNCTION_NAME(add)
 
+ BOOST_LOCAL_EXIT( (const bind this) ) {
+ std::clog << "Exiting: " << this_->sum_ << std::endl;
+ } BOOST_LOCAL_EXIT_END
+
+ BOOST_LOCAL_BLOCK( (const bind this) ) {
+ std::clong << "Asserted: " << this_->sum_ << std::endl;
+ assert(this_->sum_ > 0.0);
+ } BOOST_LOCAL_BLOCK_END
+
         std::for_each(nums.begin(), nums.end(), add);
         return sum_;
     }

Deleted: sandbox/local/libs/local/example/block.cpp
==============================================================================
--- sandbox/local/libs/local/example/block.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,36 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-#include <boost/local/block.hpp>
-#include <cassert>
-
-struct c {
- c(): x_(0) {}
-
- void f(int& x) { // Non-const member function so `this` is not const.
- // Non-const `this` but const `x`.
- BOOST_LOCAL_BLOCK( (const bind& x) (bind this) ) {
- this_->x_ = x; // Non-const `this` cant be modified.
- assert(x == this_->x_); // Compiler error if `=` instead of `==`.
-
- return; // Exit local block (not enclosing function).
- assert(false); // Never executed.
- } BOOST_LOCAL_BLOCK_END
-
- x = x_; // Non-const `x` changed outside block.
- }
-
-private:
- int x_;
-};
-
-int main() {
- c cc;
- int x = 1;
- cc.f(x);
- return 0;
-}
-

Deleted: sandbox/local/libs/local/example/block_va.cpp
==============================================================================
--- sandbox/local/libs/local/example/block_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,36 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-#include <boost/local/block.hpp>
-#include <cassert>
-
-struct c {
- c(): x_(0) {}
-
- void f(int& x) { // Non-const member function so `this` is not const.
- // Non-const `this` but const `x`.
- BOOST_LOCAL_BLOCK(const bind& x, bind this) {
- this_->x_ = x; // Non-const `this` cant be modified.
- assert(x == this_->x_); // Compiler error if `=` instead of `==`.
-
- return; // Exit local block (not enclosing function).
- assert(false); // Never executed.
- } BOOST_LOCAL_BLOCK_END
-
- x = x_; // Non-const `x` changed outside block.
- }
-
-private:
- int x_;
-};
-
-int main() {
- c cc;
- int x = 1;
- cc.f(x);
- return 0;
-}
-

Deleted: sandbox/local/libs/local/example/exit.cpp
==============================================================================
--- sandbox/local/libs/local/example/exit.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,103 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-#include <boost/local/exit.hpp>
-#include <boost/foreach.hpp>
-#include <boost/typeof/std/vector.hpp> // Typeof emulation mode.
-#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() // Typeof emulation mode.
-#include <vector>
-#include <ostream>
-#include <iostream>
-#include <cassert>
-
-class world;
-
-class person {
- friend class world;
-public:
- typedef unsigned int id_t;
- typedef unsigned int evolution_t;
-
- person(): id_(0), evolution_(0) {}
-
- friend std::ostream& operator<<(std::ostream& o, person const& p)
- { return o << "person: " << p.id_ << ", " << p.evolution_; }
-
-private:
- id_t id_;
- evolution_t evolution_;
-};
-
-BOOST_TYPEOF_REGISTER_TYPE(person)
-
-class world {
-public:
- typedef unsigned int id_t;
-
- world(): next_id_(1) {}
-
- void add_person(person const& a_person);
-
- friend std::ostream& operator<<(std::ostream& o, world const& w) {
- o << "world: " << w.next_id_ << ", {";
- BOOST_FOREACH(person const& p, w.persons_) {
- o << ' ' << p << ',';
- }
- return o << "}";
- }
-private:
- id_t next_id_;
- std::vector<person> persons_;
-};
-
-BOOST_TYPEOF_REGISTER_TYPE(world)
-
-void world::add_person(person const& a_person) {
- persons_.push_back(a_person);
-
- // This block must be no-throw.
- person& p = persons_.back();
- person::evolution_t checkpoint = p.evolution_;
-
- BOOST_LOCAL_EXIT( (const bind checkpoint) (const bind& p) (bind this) ) {
- if (checkpoint == p.evolution_) this_->persons_.pop_back();
- std::cout << "1st local exit" << std::endl;
- return; // Exit local scope (not enclosing function).
- assert(false);
- } BOOST_LOCAL_EXIT_END
-
- // ...
-
- checkpoint = ++p.evolution_;
-
- // Assign new id to the person.
- world::id_t const prev_id = p.id_;
- p.id_ = next_id_++;
- BOOST_LOCAL_EXIT( (const bind checkpoint) (const bind prev_id)
- (bind& p) (bind& next_id_) ) {
- if (checkpoint == p.evolution_) {
- next_id_ = p.id_;
- p.id_ = prev_id;
- }
- std::cout << "2nd local exit" << std::endl;
- } BOOST_LOCAL_EXIT_END
-
- // ...
-
- checkpoint = ++p.evolution_;
-}
-
-int main() {
- person adamo, eva;
- std::cout << adamo << std::endl;
- std::cout << eva << std::endl;
-
- world w;
- w.add_person(adamo);
- w.add_person(eva);
- std::cout << w << std::endl;
-}
-

Deleted: sandbox/local/libs/local/example/exit_va.cpp
==============================================================================
--- sandbox/local/libs/local/example/exit_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
+++ (empty file)
@@ -1,103 +0,0 @@
-
-// Copyright (C) 2009-2011 Lorenzo Caminiti
-// Use, modification, and distribution is subject to 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).
-
-#include <boost/local/exit.hpp>
-#include <boost/foreach.hpp>
-#include <boost/typeof/std/vector.hpp> // Typeof emulation mode.
-#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() // Typeof emulation mode.
-#include <vector>
-#include <ostream>
-#include <iostream>
-#include <cassert>
-
-class world;
-
-class person {
- friend class world;
-public:
- typedef unsigned int id_t;
- typedef unsigned int evolution_t;
-
- person(): id_(0), evolution_(0) {}
-
- friend std::ostream& operator<<(std::ostream& o, person const& p)
- { return o << "person: " << p.id_ << ", " << p.evolution_; }
-
-private:
- id_t id_;
- evolution_t evolution_;
-};
-
-BOOST_TYPEOF_REGISTER_TYPE(person)
-
-class world {
-public:
- typedef unsigned int id_t;
-
- world(): next_id_(1) {}
-
- void add_person(person const& a_person);
-
- friend std::ostream& operator<<(std::ostream& o, world const& w) {
- o << "world: " << w.next_id_ << ", {";
- BOOST_FOREACH(person const& p, w.persons_) {
- o << ' ' << p << ',';
- }
- return o << "}";
- }
-private:
- id_t next_id_;
- std::vector<person> persons_;
-};
-
-BOOST_TYPEOF_REGISTER_TYPE(world)
-
-void world::add_person(person const& a_person) {
- persons_.push_back(a_person);
-
- // This block must be no-throw.
- person& p = persons_.back();
- person::evolution_t checkpoint = p.evolution_;
-
- BOOST_LOCAL_EXIT(const bind checkpoint, const bind& p, bind this) {
- if (checkpoint == p.evolution_) this_->persons_.pop_back();
- std::cout << "1st local exit" << std::endl;
- return; // Exit local scope (not enclosing function).
- assert(false);
- } BOOST_LOCAL_EXIT_END
-
- // ...
-
- checkpoint = ++p.evolution_;
-
- // Assign new id to the person.
- world::id_t const prev_id = p.id_;
- p.id_ = next_id_++;
- BOOST_LOCAL_EXIT(const bind checkpoint, const bind prev_id,
- bind& p, bind& next_id_) {
- if (checkpoint == p.evolution_) {
- next_id_ = p.id_;
- p.id_ = prev_id;
- }
- std::cout << "2nd local exit" << std::endl;
- } BOOST_LOCAL_EXIT_END
-
- // ...
-
- checkpoint = ++p.evolution_;
-}
-
-int main() {
- person adamo, eva;
- std::cout << adamo << std::endl;
- std::cout << eva << std::endl;
-
- world w;
- w.add_person(adamo);
- w.add_person(eva);
- std::cout << w << std::endl;
-}
-

Modified: sandbox/local/libs/local/example/find_if.cpp
==============================================================================
--- sandbox/local/libs/local/example/find_if.cpp (original)
+++ sandbox/local/libs/local/example/find_if.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
@@ -4,6 +4,7 @@
 // License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
 // copy at http://www.boost.org/LICENSE_1_0.txt).
 
+//[find_if_cpp
 #include <boost/local/function.hpp>
 #include <list>
 #include <algorithm>
@@ -39,4 +40,5 @@
     if (i != employees.end()) { std::cout << i->salary() << std::endl; }
     return 0;
 }
+//]
 

Modified: sandbox/local/libs/local/example/find_if_va.cpp
==============================================================================
--- sandbox/local/libs/local/example/find_if_va.cpp (original)
+++ sandbox/local/libs/local/example/find_if_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
@@ -4,6 +4,7 @@
 // License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
 // copy at http://www.boost.org/LICENSE_1_0.txt).
 
+//[find_if_va_cpp
 #include <boost/local/function.hpp>
 #include <list>
 #include <algorithm>
@@ -39,4 +40,5 @@
     if (i != employees.end()) { std::cout << i->salary() << std::endl; }
     return 0;
 }
+//]
 

Added: sandbox/local/libs/local/example/scope_guards_errno_va.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/scope_guards_errno_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
@@ -0,0 +1,28 @@
+
+//[scope_guards_errno_va_cpp
+#include <boost/local/exit.hpp>
+#include <iostream>
+
+int f() {
+ int error = 0; // No error to start with.
+
+ BOOST_LOCAL_EXIT(void) { // Same as D's `scope(exit)`.
+ std::cout << "exit" << std::endl;
+ } BOOST_LOCAL_EXIT_END
+
+ BOOST_LOCAL_EXIT(const bind& error) { // Sane as D's `scope(success)`.
+ if (!error) std::cout << "success" << std::endl;
+ } BOOST_LOCAL_EXIT_END
+
+ BOOST_LOCAL_EXIT(const bind& error) { // Same as D's `scope(failure)`.
+ if (error) std::cout << "failure" << std::endl;
+ } BOOST_LOCAL_EXIT_END
+
+ return error = -1; // Must set error.
+}
+
+int main() {
+ return f();
+}
+//]
+

Added: sandbox/local/libs/local/example/scope_guards_except_va.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/scope_guards_except_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
@@ -0,0 +1,36 @@
+
+//[scope_guards_except_va_cpp
+#include <boost/local/exit.hpp>
+#include <iostream>
+#include <stdexcept>
+
+void f() {
+ bool error = false; // No error to start with.
+
+ BOOST_LOCAL_EXIT(void) { // Same as D's `scope(exit)`.
+ std::cout << "exit" << std::endl;
+ } BOOST_LOCAL_EXIT_END
+
+ BOOST_LOCAL_EXIT(const bind& error) { // Same as D's `scope(success)`.
+ if (!error) std::cout << "success" << std::endl;
+ } BOOST_LOCAL_EXIT_END
+
+ BOOST_LOCAL_EXIT(const bind& error) { // Same as D's `scope(failure)`.
+ if (error) std::cout << "failure" << std::endl;
+ } BOOST_LOCAL_EXIT_END
+
+ error = true; throw std::runtime_error("some error"); // Must set error.
+}
+
+int main() {
+ // Program cannot terminate with uncaught exception (otherwise local exit
+ // code is not guaranteed to be executed).
+ try {
+ f();
+ return 0;
+ } catch(...) {
+ return -1;
+ }
+}
+//]
+

Copied: sandbox/local/libs/local/example/world_exit.cpp (from r70142, /sandbox/local/libs/local/example/exit.cpp)
==============================================================================
--- /sandbox/local/libs/local/example/exit.cpp (original)
+++ sandbox/local/libs/local/example/world_exit.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
@@ -4,6 +4,7 @@
 // License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
 // copy at http://www.boost.org/LICENSE_1_0.txt).
 
+//[world_exit_cpp
 #include <boost/local/exit.hpp>
 #include <boost/foreach.hpp>
 #include <boost/typeof/std/vector.hpp> // Typeof emulation mode.
@@ -100,4 +101,4 @@
     w.add_person(eva);
     std::cout << w << std::endl;
 }
-
+//]

Copied: sandbox/local/libs/local/example/world_exit_va.cpp (from r70142, /sandbox/local/libs/local/example/exit_va.cpp)
==============================================================================
--- /sandbox/local/libs/local/example/exit_va.cpp (original)
+++ sandbox/local/libs/local/example/world_exit_va.cpp 2011-03-20 20:16:36 EDT (Sun, 20 Mar 2011)
@@ -4,6 +4,7 @@
 // License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a
 // copy at http://www.boost.org/LICENSE_1_0.txt).
 
+//[world_exit_va_cpp
 #include <boost/local/exit.hpp>
 #include <boost/foreach.hpp>
 #include <boost/typeof/std/vector.hpp> // Typeof emulation mode.
@@ -100,4 +101,5 @@
     w.add_person(eva);
     std::cout << w << std::endl;
 }
+//]
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk