|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r70486 - sandbox/local/libs/local/example
From: lorcaminiti_at_[hidden]
Date: 2011-03-23 20:05:35
Author: lcaminiti
Date: 2011-03-23 20:05:33 EDT (Wed, 23 Mar 2011)
New Revision: 70486
URL: http://svn.boost.org/trac/boost/changeset/70486
Log:
Fixed all examples.
Added:
sandbox/local/libs/local/example/add_block_impl.cpp (contents, props changed)
sandbox/local/libs/local/example/add_exit_impl.cpp (contents, props changed)
sandbox/local/libs/local/example/gcc-access.cpp (contents, props changed)
sandbox/local/libs/local/example/gcc-store_va.cpp (contents, props changed)
Added: sandbox/local/libs/local/example/add_block_impl.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/add_block_impl.cpp 2011-03-23 20:05:33 EDT (Wed, 23 Mar 2011)
@@ -0,0 +1,35 @@
+
+// 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_block_impl_cpp
+#include <boost/local/block.hpp>
+#include <iostream>
+#include <cassert>
+
+int main() {
+ double sum = 1975.0;
+
+ // The macro `BOOST_LOCAL_BLOCK( (const bind& sum) )` expands to:
+ void BOOST_LOCAL_FUNCTION_PARAMS( (const bind& sum) )
+
+ // Local block body.
+ {
+ 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.
+ }
+
+ // The macro `BOOST_LOCAL_BLOCK_END` expands to (at line 21):
+ BOOST_LOCAL_FUNCTION_NAME(boost_local_auxXblock_function21)
+ // This local function call executes the local block body code.
+ boost_local_auxXblock_function21();
+
+ return 0;
+}
+//]
+
Added: sandbox/local/libs/local/example/add_exit_impl.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/add_exit_impl.cpp 2011-03-23 20:05:33 EDT (Wed, 23 Mar 2011)
@@ -0,0 +1,38 @@
+
+// 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_exit_impl_cpp
+#include <boost/local/exit.hpp>
+#include <iostream>
+#include <cassert>
+
+int main() {
+ size_t size = 2;
+ double* nums = new double[size];
+
+ // The macro `BOOST_LOCAL_EXIT( (const bind& size) (bind nums) )` expands to:
+ void BOOST_LOCAL_FUNCTION_PARAMS( (const bind& size) (bind nums) )
+
+ // Local exit body.
+ {
+ 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.
+ }
+
+ // The macro `BOOST_LOCAL_EXIT_END` expands to (at line 22):
+ BOOST_LOCAL_FUNCTION_NAME(boost_local_auxXexitXfunction22)
+ // When this object goes out of scope, its destructor calls the specified
+ // local function which in turn executes the local exit body code.
+ ::boost::local::aux::exit_guard boost_local_auxXexitXguard22(
+ boost_local_auxXexitXfunction22);
+
+ return 0;
+}
+//]
+
Added: sandbox/local/libs/local/example/gcc-access.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/gcc-access.cpp 2011-03-23 20:05:33 EDT (Wed, 23 Mar 2011)
@@ -0,0 +1,23 @@
+
+//[gcc_access_cpp
+#include <boost/local/function.hpp>
+#include <iostream>
+
+void bar(int* array, int offset, int size) {
+ int BOOST_LOCAL_FUNCTION_PARAMS( (int* array) (int index)
+ (const bind offset) ) {
+ return array[index + offset];
+ } BOOST_LOCAL_FUNCTION_NAME(access)
+
+ for (int i = 0; i < size; ++i) {
+ std::cout << access(array, i) << std::endl;
+ }
+}
+
+int main() {
+ int nums[3] = {1, 2, 3};
+ bar(nums, 0, 3);
+ return 0;
+}
+//]
+
Added: sandbox/local/libs/local/example/gcc-store_va.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/gcc-store_va.cpp 2011-03-23 20:05:33 EDT (Wed, 23 Mar 2011)
@@ -0,0 +1,22 @@
+
+//[gcc_store_va_cpp
+#include <boost/local/function.hpp>
+
+void intermediate(boost::local::function<void (int, int)> store_func,
+ int size) {
+ store_func(size - 1, -1);
+}
+
+void hack(int* array, int size) {
+ void BOOST_LOCAL_FUNCTION_PARAMS(int index, int value, bind array) {
+ array[index] = value;
+ } BOOST_LOCAL_FUNCTION_NAME(store)
+
+ intermediate(store, size);
+}
+
+int main() {
+ return 0;
+}
+//]
+
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