$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r69231 - sandbox/local/libs/local/example
From: lorcaminiti_at_[hidden]
Date: 2011-02-23 23:02:32
Author: lcaminiti
Date: 2011-02-23 23:02:25 EST (Wed, 23 Feb 2011)
New Revision: 69231
URL: http://svn.boost.org/trac/boost/changeset/69231
Log:
Added more variadic examples.
Added:
   sandbox/local/libs/local/example/add_block_va.cpp   (contents, props changed)
   sandbox/local/libs/local/example/add_except_va.cpp   (contents, props changed)
   sandbox/local/libs/local/example/add_exit_va.cpp   (contents, props changed)
Text files modified: 
   sandbox/local/libs/local/example/add_block.cpp  |     2 +-                                      
   sandbox/local/libs/local/example/add_except.cpp |    14 ++++++--------                          
   sandbox/local/libs/local/example/add_exit.cpp   |     2 +-                                      
   3 files changed, 8 insertions(+), 10 deletions(-)
Modified: sandbox/local/libs/local/example/add_block.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_block.cpp	(original)
+++ sandbox/local/libs/local/example/add_block.cpp	2011-02-23 23:02:25 EST (Wed, 23 Feb 2011)
@@ -15,7 +15,7 @@
 int main() {
     double sum = 1975.0;
 
-    BOOST_LOCAL_BLOCK( (const bind)((&sum)) ) {
+    BOOST_LOCAL_BLOCK( (const bind& sum) ) {
         assert(sum == 1975.0); // OK: Complier error if `==` confused with `=`.
         std::clog << "Asserted summation: " << sum << std::endl;
 
Added: sandbox/local/libs/local/example/add_block_va.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/add_block_va.cpp	2011-02-23 23:02:25 EST (Wed, 23 Feb 2011)
@@ -0,0 +1,30 @@
+
+// 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).
+
+// Simple local block used by the documentation.
+// Simplified syntax for variadic macros.
+
+//[ add_block_cpp
+#include <boost/local/block.hpp>
+#include <iostream>
+#include <cassert>
+
+int main() {
+    double sum = 1975.0;
+
+    BOOST_LOCAL_BLOCK(const bind& sum) {
+        assert(sum == 1975.0); // OK: Complier error if `==` confused with `=`.
+        std::clog << "Asserted summation: " << sum << std::endl;
+
+        return; // Return this local block (and not the enclosing scope).
+        assert(false); // OK: Never executed.
+    } BOOST_LOCAL_BLOCK_END
+
+    return 0;
+}
+//]
+
Modified: sandbox/local/libs/local/example/add_except.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_except.cpp	(original)
+++ sandbox/local/libs/local/example/add_except.cpp	2011-02-23 23:02:25 EST (Wed, 23 Feb 2011)
@@ -19,25 +19,23 @@
     double sum = 0.0;
     int factor = 10;
 
-    BOOST_LOCAL_FUNCTION(
-    (void) (add)( (double)(num) (const bind)((factor)) (bind)((&sum)) )
-    ) throw (std::runtime_error, std::logic_error) { // Throw two exceptions.
+    void BOOST_LOCAL_FUNCTION_PARAMS( (double num)
+            (const bind factor) (bind& sum) )
+            throw (std::runtime_error, std::logic_error) { // Throw two except.
         sum += factor * num;
-    } BOOST_LOCAL_FUNCTION_END(add)
+    } BOOST_LOCAL_FUNCTION_NAME(add)
     add(100.0);
 
     size_t size = 2;
     double* nums = new double[size];
-    // Throw nothing.
-    BOOST_LOCAL_EXIT( (const bind)((&size)) (bind)((nums)) ) throw() {
+    BOOST_LOCAL_EXIT( (const bind& size) (bind nums) ) throw() { // Throw none.
         if (size && nums) delete[] nums;
     } BOOST_LOCAL_EXIT_END
 
     nums[0] = 90.5; nums[1] = 7.0;
     std::for_each(nums, nums + size, add);
 
-    // Throw one exception.
-    BOOST_LOCAL_BLOCK( (const bind)((&sum)) ) throw(std::exception) {
+    BOOST_LOCAL_BLOCK( (const bind& sum) ) throw(std::exception) { // Thow one.
         assert(sum == 1975.0);
     } BOOST_LOCAL_BLOCK_END
 
Added: sandbox/local/libs/local/example/add_except_va.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/add_except_va.cpp	2011-02-23 23:02:25 EST (Wed, 23 Feb 2011)
@@ -0,0 +1,46 @@
+
+// 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).
+
+// Use local functions, blocks, and exits from template scope.
+// Simplified syntax for variadic macros only.
+
+//[add_except_cpp
+#include <boost/local/function.hpp>
+#include <boost/local/block.hpp>
+#include <boost/local/exit.hpp>
+#include <stdexcept>
+#include <algorithm>
+#include <cassert>
+
+int main() {
+    double sum = 0.0;
+    int factor = 10;
+
+    void BOOST_LOCAL_FUNCTION_PARAMS(double num,
+            const bind factor, bind& sum)
+            throw (std::runtime_error, std::logic_error) { // Throw two except.
+        sum += factor * num;
+    } BOOST_LOCAL_FUNCTION_NAME(add)
+    add(100.0);
+
+    size_t size = 2;
+    double* nums = new double[size];
+    BOOST_LOCAL_EXIT(const bind& size, bind nums) throw() { // Throw none.
+        if (size && nums) delete[] nums;
+    } BOOST_LOCAL_EXIT_END
+
+    nums[0] = 90.5; nums[1] = 7.0;
+    std::for_each(nums, nums + size, add);
+
+    BOOST_LOCAL_BLOCK(const bind& sum) throw(std::exception) { // Thow one.
+        assert(sum == 1975.0);
+    } BOOST_LOCAL_BLOCK_END
+
+    return 0;
+}
+//]
+
Modified: sandbox/local/libs/local/example/add_exit.cpp
==============================================================================
--- sandbox/local/libs/local/example/add_exit.cpp	(original)
+++ sandbox/local/libs/local/example/add_exit.cpp	2011-02-23 23:02:25 EST (Wed, 23 Feb 2011)
@@ -16,7 +16,7 @@
     size_t size = 2;
     double* nums = new double[size];
     
-    BOOST_LOCAL_EXIT( (const bind)((&size)) (bind)((nums)) ) {
+    BOOST_LOCAL_EXIT( (const bind& size) (bind nums) ) {
         if (size && nums) delete[] nums;
         std::clog << "Freed array: " << nums << std::endl;
 
Added: sandbox/local/libs/local/example/add_exit_va.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/add_exit_va.cpp	2011-02-23 23:02:25 EST (Wed, 23 Feb 2011)
@@ -0,0 +1,31 @@
+
+// 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).
+
+// Simple local exit used by the documentation.
+// Simplified syntax for variadic macros only.
+
+//[ add_exit_va_cpp
+#include <boost/local/exit.hpp>
+#include <iostream>
+#include <cassert>
+
+int main() {
+    size_t size = 2;
+    double* nums = new double[size];
+    
+    BOOST_LOCAL_EXIT(const bind& size, bind nums) {
+        if (size && nums) delete[] nums;
+        std::clog << "Freed array: " << nums << std::endl;
+
+        return; // Return this local exit (and not the enclosing scope).
+        assert(false); // OK: Never executed.
+    } BOOST_LOCAL_EXIT_END
+
+    return 0;
+}
+//]
+