Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r69597 - in sandbox/local: . boost/local/aux_/function_macros/code_ libs/local/example
From: lorcaminiti_at_[hidden]
Date: 2011-03-05 20:48:09


Author: lcaminiti
Date: 2011-03-05 20:48:08 EST (Sat, 05 Mar 2011)
New Revision: 69597
URL: http://svn.boost.org/trac/boost/changeset/69597

Log:
Added code/example for nesting.
Added:
   sandbox/local/libs/local/example/nesting.cpp (contents, props changed)
   sandbox/local/libs/local/example/nesting_va.cpp (contents, props changed)
Text files modified:
   sandbox/local/TODO.txt | 2 +-
   sandbox/local/boost/local/aux_/function_macros/code_/functor.hpp | 6 ++++++
   sandbox/local/libs/local/example/Jamfile.jam | 3 +++
   3 files changed, 10 insertions(+), 1 deletions(-)

Modified: sandbox/local/TODO.txt
==============================================================================
--- sandbox/local/TODO.txt (original)
+++ sandbox/local/TODO.txt 2011-03-05 20:48:08 EST (Sat, 05 Mar 2011)
@@ -12,8 +12,8 @@
 
 * Docs: Add D-Stype Scope Guards examples to docs.
 
+* Docs: Document that nesting is (now) possible.
 
-* Code: Try seriously to make nested locals to work...
 
 * Code: Optimize macro expansion code for C++0x, C++03, etc. From John Bytheway:
> Yes, in C++0x local structs can be passed as template parameters.

Modified: sandbox/local/boost/local/aux_/function_macros/code_/functor.hpp
==============================================================================
--- sandbox/local/boost/local/aux_/function_macros/code_/functor.hpp (original)
+++ sandbox/local/boost/local/aux_/function_macros/code_/functor.hpp 2011-03-05 20:48:08 EST (Sat, 05 Mar 2011)
@@ -175,6 +175,12 @@
                 (sign_params, unbinds, const_binds, has_const_bind_this, \
                  binds, has_bind_this, id, typename_keyword) ) \
     private: \
+ /* this allows for nesting (local functions, blocks, and exits) as */ \
+ /* it makes the args variable visible within the body code (which */ \
+ /* cannot be static); this is for compilation only as the args */ \
+ /* variable is actually declared by the 1st enclosing local func */ \
+ boost::scope_exit::aux::undeclared \
+ BOOST_LOCAL_AUX_SYMBOL_ARGS_VARIABLE_NAME; \
         /* this type symbol cannot have ID postfix because it is used */ \
         /* the `NAME` macro (because this symbol is within functor class */ \
         /* it doesn't have to have ID postfix). */ \

Modified: sandbox/local/libs/local/example/Jamfile.jam
==============================================================================
--- sandbox/local/libs/local/example/Jamfile.jam (original)
+++ sandbox/local/libs/local/example/Jamfile.jam 2011-03-05 20:48:08 EST (Sat, 05 Mar 2011)
@@ -64,3 +64,6 @@
 exe transform : transform.cpp ;
 exe transform_va : transform_va.cpp ;
 
+exe nesting : nesting.cpp ;
+exe nesting_va : nesting_va.cpp ;
+

Added: sandbox/local/libs/local/example/nesting.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/nesting.cpp 2011-03-05 20:48:08 EST (Sat, 05 Mar 2011)
@@ -0,0 +1,39 @@
+
+// Local functions, blocks, and exits can be arbitrarily nested into each other.
+
+#include <boost/local/function.hpp>
+#include <boost/local/block.hpp>
+#include <boost/local/exit.hpp>
+#include <iostream>
+#include <cassert>
+
+int main() {
+ int x = 0;
+
+ // Local functions nested into one another.
+ void BOOST_LOCAL_FUNCTION_PARAMS( (bind& x) ) {
+ std::cout << "l: " << x << std::endl;
+
+ void BOOST_LOCAL_FUNCTION_PARAMS( (bind& x) ) {
+ std::cout << "m: " << x << std::endl;
+ } BOOST_LOCAL_FUNCTION_NAME(m)
+
+ x--; m();
+ } BOOST_LOCAL_FUNCTION_NAME(l)
+
+ // Local functions, blocks and exits nested into each other.
+ void BOOST_LOCAL_FUNCTION_PARAMS( (bind& x) ) {
+ BOOST_LOCAL_EXIT( (bind& x) ) {
+ x = 0;
+ BOOST_LOCAL_BLOCK( (const bind& x) ) {
+ assert(x == 0);
+ } BOOST_LOCAL_BLOCK_END
+ } BOOST_LOCAL_EXIT_END
+ std::cout << "n: " << x << std::endl;
+ } BOOST_LOCAL_FUNCTION_NAME(n)
+
+ x--; l();
+ x--; n();
+ return 0;
+}
+

Added: sandbox/local/libs/local/example/nesting_va.cpp
==============================================================================
--- (empty file)
+++ sandbox/local/libs/local/example/nesting_va.cpp 2011-03-05 20:48:08 EST (Sat, 05 Mar 2011)
@@ -0,0 +1,40 @@
+
+// Local functions, blocks, and exits can be arbitrarily nested into each other.
+// Simplified syntax for variadic macros only.
+
+#include <boost/local/function.hpp>
+#include <boost/local/block.hpp>
+#include <boost/local/exit.hpp>
+#include <iostream>
+#include <cassert>
+
+int main() {
+ int x = 0;
+
+ // Local functions nested into one another.
+ void BOOST_LOCAL_FUNCTION_PARAMS(bind& x) {
+ std::cout << "l: " << x << std::endl;
+
+ void BOOST_LOCAL_FUNCTION_PARAMS(bind& x) {
+ std::cout << "m: " << x << std::endl;
+ } BOOST_LOCAL_FUNCTION_NAME(m)
+
+ x--; m();
+ } BOOST_LOCAL_FUNCTION_NAME(l)
+
+ // Local functions, blocks and exits nested into each other.
+ void BOOST_LOCAL_FUNCTION_PARAMS(bind& x) {
+ BOOST_LOCAL_EXIT(bind& x) {
+ x = 0;
+ BOOST_LOCAL_BLOCK(const bind& x) {
+ assert(x == 0);
+ } BOOST_LOCAL_BLOCK_END
+ } BOOST_LOCAL_EXIT_END
+ std::cout << "n: " << x << std::endl;
+ } BOOST_LOCAL_FUNCTION_NAME(n)
+
+ x--; l();
+ x--; n();
+ 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