Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77748 - in trunk: boost libs/scope_exit/example libs/scope_exit/test
From: lorcaminiti_at_[hidden]
Date: 2012-04-03 16:16:04


Author: lcaminiti
Date: 2012-04-03 16:16:03 EDT (Tue, 03 Apr 2012)
New Revision: 77748
URL: http://svn.boost.org/trac/boost/changeset/77748

Log:
Not added SCOPE_EXIT_ALL_TPL but SCOPE_EXIT_ALL can capture `this_` only on C++11 compilers that allow typename in templates (not MVSC10) -- all SCOPE_EXTIA_ALL can always capture the object using `this` instead of `this_` and SCOPE_EXIT can always capture `this_` even when implemented using C++11 lambdas because there is already a SCOPE_EXIT_TPL.
Added:
   trunk/libs/scope_exit/example/world_cxx11_lambda.cpp
      - copied, changed from r77747, /trunk/libs/scope_exit/example/world_lambda.cpp
   trunk/libs/scope_exit/test/world_void_nova.cpp (contents, props changed)
Removed:
   trunk/libs/scope_exit/example/world_lambda.cpp
Text files modified:
   trunk/boost/scope_exit.hpp | 47 +++++++++-----------
   trunk/libs/scope_exit/example/Jamfile.v2 | 2
   trunk/libs/scope_exit/example/world_cxx11_lambda.cpp | 4
   trunk/libs/scope_exit/test/Jamfile.v2 | 90 +++++++++++++++++----------------------
   trunk/libs/scope_exit/test/world_checkpoint_all.cpp | 10 ++-
   trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp | 6 +-
   6 files changed, 74 insertions(+), 85 deletions(-)

Modified: trunk/boost/scope_exit.hpp
==============================================================================
--- trunk/boost/scope_exit.hpp (original)
+++ trunk/boost/scope_exit.hpp 2012-04-03 16:16:03 EDT (Tue, 03 Apr 2012)
@@ -512,26 +512,13 @@
 #define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_PARAM_TYPE(id) \
     BOOST_PP_CAT(boost_se_lambda_this_capture_t_, id)
 
-#ifndef BOOST_MSVC
-// C++11 allows to freely use `typename` (so no need for `..._ALL_TPL`).
-# define BOOST_SCOPE_EXIT_AUX_LAMBDA_TYPENAME_() \
- typename
-#else
-// C++11 on MSVC cannot freely use `typename` but MSVC does not require
-// typename to begin with (so still no need for `..._ALL_TPL` macro).
-# define BOOST_SCOPE_EXIT_AUX_LAMBDA_TYPENAME_() \
- /* must expand to empty */
-#endif
-
-#define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPE(id) \
- BOOST_SCOPE_EXIT_AUX_LAMBDA_TYPENAME_() \
- BOOST_SCOPE_EXIT_AUX_LAMBDA_PARAMS(id):: \
+#define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPE(id, ty) \
+ ty BOOST_SCOPE_EXIT_AUX_LAMBDA_PARAMS(id):: \
             BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_PARAM_TYPE(id)
 
 // Precondition: HAS_THIS(traits).
-#define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPEDEFS(id, traits) \
- BOOST_SCOPE_EXIT_DETAIL_TYPEDEF_TYPEOF_THIS(id, \
- BOOST_SCOPE_EXIT_AUX_LAMBDA_TYPENAME_(), \
+#define BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPEDEFS(id, ty, traits) \
+ BOOST_SCOPE_EXIT_DETAIL_TYPEDEF_TYPEOF_THIS(id, ty, \
             BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_CAPTURE_TYPE(id)) \
     /* capture type for workaround GCC internal error (even on later C++11) */ \
     struct BOOST_SCOPE_EXIT_AUX_LAMBDA_PARAMS(id) { \
@@ -539,19 +526,19 @@
                 BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_PARAM_TYPE(id); \
     };
 
-#define BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, traits) \
+#define BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, ty, traits) \
     BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
         /* no need for TYPEDEF THIS MSVC workaround on C++11 */ \
         BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPEDEFS \
     , \
- BOOST_PP_TUPLE_EAT(2) \
- )(id, traits) \
+ BOOST_PP_TUPLE_EAT(3) \
+ )(id, ty, traits) \
     ::boost::scope_exit::aux::guard< \
         BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
             BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPE \
         , \
- BOOST_PP_TUPLE_EAT(1) \
- )(id) \
+ BOOST_PP_TUPLE_EAT(2) \
+ )(id, ty) \
> BOOST_SCOPE_EXIT_AUX_GUARD(id) \
         BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
             (this) \
@@ -563,8 +550,8 @@
         BOOST_PP_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), \
             BOOST_SCOPE_EXIT_AUX_LAMBDA_THIS_TYPE \
         , \
- BOOST_PP_TUPLE_EAT(1) \
- )(id) \
+ BOOST_PP_TUPLE_EAT(2) \
+ )(id, ty) \
         BOOST_PP_EXPR_IIF(BOOST_SCOPE_EXIT_AUX_TRAITS_HAS_THIS(traits), this_) \
     ) mutable /* can change value captures (as with SCOPE_EXIT) */ -> void
 
@@ -574,7 +561,7 @@
         !defined(BOOST_NO_LAMBDAS) // Use lambda for SCOPE_EXIT (not just _ALL).
 
 #define BOOST_SCOPE_EXIT_AUX_IMPL(id, ty, traits) \
- BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, traits)
+ BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, ty, traits)
 
 #else // Not using lambdas.
 
@@ -667,6 +654,11 @@
 # if !defined(BOOST_NO_LAMBDAS)
 # define BOOST_SCOPE_EXIT_ALL_ID(id, seq) \
             BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, \
+ /* C++11 allows to use typename outside templates so */ \
+ /* always typename here and no need for ..._ALL_TPL */ \
+ /* (if a C++11 compiler does not implement this use of */ \
+ /* typename, always use `this` instead of `this_`) */ \
+ typename, \
                     BOOST_SCOPE_EXIT_AUX_TRAITS_ALL( \
                             BOOST_LOCAL_FUNCTION_DETAIL_PP_NON_VOID_LIST(seq)))
 # define BOOST_SCOPE_EXIT_ALL(seq) \
@@ -688,6 +680,11 @@
 # if !defined(BOOST_NO_LAMBDAS)
 # define BOOST_SCOPE_EXIT_ALL_ID(id, ...) \
             BOOST_SCOPE_EXIT_AUX_IMPL_LAMBDA(id, \
+ /* C++11 allows to use typename outside templates so */ \
+ /* always typename here and no need for ..._ALL_TPL */ \
+ /* (if a C++11 compiler does not implement this use of */ \
+ /* typename, always use `this` instead of `this_`) */ \
+ typename, \
                     BOOST_SCOPE_EXIT_AUX_TRAITS_ALL( \
                             BOOST_LOCAL_FUNCTION_DETAIL_PP_NON_VOID_LIST( \
                                     __VA_ARGS__)))

Modified: trunk/libs/scope_exit/example/Jamfile.v2
==============================================================================
--- trunk/libs/scope_exit/example/Jamfile.v2 (original)
+++ trunk/libs/scope_exit/example/Jamfile.v2 2012-04-03 16:16:03 EDT (Tue, 03 Apr 2012)
@@ -16,5 +16,5 @@
 run scope_guard_seq.cpp ;
 run scope_guard_seq_nova.cpp ;
 
-run world_lambda.cpp ;
+run world_cxx11_lambda.cpp ;
 

Copied: trunk/libs/scope_exit/example/world_cxx11_lambda.cpp (from r77747, /trunk/libs/scope_exit/example/world_lambda.cpp)
==============================================================================
--- /trunk/libs/scope_exit/example/world_lambda.cpp (original)
+++ trunk/libs/scope_exit/example/world_cxx11_lambda.cpp 2012-04-03 16:16:03 EDT (Tue, 03 Apr 2012)
@@ -21,7 +21,7 @@
     std::vector<person> persons_;
 };
 
-//[world_lambda
+//[world_cxx11_lambda
 #include <functional>
 
 struct scope_exit {
@@ -53,5 +53,5 @@
     return boost::report_errors();
 }
 
-#endif // lambdas
+#endif // LAMBDAS
 

Deleted: trunk/libs/scope_exit/example/world_lambda.cpp
==============================================================================
--- trunk/libs/scope_exit/example/world_lambda.cpp 2012-04-03 16:16:03 EDT (Tue, 03 Apr 2012)
+++ (empty file)
@@ -1,57 +0,0 @@
-
-// Copyright (C) 2006-2009, 2012 Alexander Nasonov
-// Copyright (C) 2012 Lorenzo Caminiti
-// Distributed under 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)
-// Home at http://www.boost.org/libs/scope_exit
-
-#include <boost/config.hpp>
-#ifdef BOOST_NO_LAMBDAS
-# error "lambda functions required"
-#else
-
-#include <boost/detail/lightweight_test.hpp>
-#include <vector>
-
-struct person {};
-
-struct world {
- void add_person(person const& a_person);
- std::vector<person> persons_;
-};
-
-//[world_lambda
-#include <functional>
-
-struct scope_exit {
- scope_exit(std::function<void (void)> f) : f_(f) {}
- ~scope_exit(void) { f_(); }
-private:
- std::function<void (void)> f_;
-};
-
-void world::add_person(person const& a_person) {
- bool commit = false;
-
- persons_.push_back(a_person);
- scope_exit on_exit1([&commit, this](void) { // Use C++11 lambda.
- if(!commit) persons_.pop_back(); // `persons_` via captured `this`.
- });
-
- // ...
-
- commit = true;
-}
-//]
-
-int main(void) {
- world w;
- person p;
- w.add_person(p);
- BOOST_TEST(w.persons_.size() == 1);
- return boost::report_errors();
-}
-
-#endif // lambdas
-

Modified: trunk/libs/scope_exit/test/Jamfile.v2
==============================================================================
--- trunk/libs/scope_exit/test/Jamfile.v2 (original)
+++ trunk/libs/scope_exit/test/Jamfile.v2 2012-04-03 16:16:03 EDT (Tue, 03 Apr 2012)
@@ -8,54 +8,44 @@
 
 import testing ;
 
-test-suite doc_tests
- : [ run same_line.cpp ]
- [ run same_line_seq.cpp ]
- [ run same_line_seq_nova.cpp ]
- [ run world.cpp ]
- [ run world_seq.cpp ]
- [ run world_seq_nova.cpp ]
- [ run world_checkpoint.cpp ]
- [ run world_checkpoint_seq.cpp ]
- [ run world_checkpoint_seq_nova.cpp ]
- [ run world_checkpoint_all.cpp ]
- [ run world_checkpoint_all_seq.cpp ]
- [ run world_checkpoint_all_seq_nova.cpp ]
- [ run world_this.cpp ]
- [ run world_this_seq.cpp ]
- [ run world_this_seq_nova.cpp ]
- [ run world_tpl.cpp ]
- [ run world_tpl_seq.cpp ]
- [ run world_tpl_seq_nova.cpp ]
- [ run world_void.cpp ]
- ;
-
-test-suite native_tests
- : [ run native.cpp : : : <define>BOOST_TYPEOF_NATIVE ]
- [ run native_tpl.cpp : : : <define>BOOST_TYPEOF_NATIVE ]
- [ run native_this.cpp : : : <define>BOOST_TYPEOF_NATIVE ]
- [ run native_this_tpl.cpp : : : <define>BOOST_TYPEOF_NATIVE ]
- [ compile-fail native_const_error.cpp : <define>BOOST_TYPEOF_NATIVE ]
- [ compile-fail native_cv_error.cpp : <define>BOOST_TYPEOF_NATIVE ]
- # Following test is known to fail on MSVC 7.1 and 8.0.
- [ run native_tu_test.cpp native_tu1.cpp native_tu2.cpp : : :
- <define>BOOST_TYPEOF_NATIVE ]
- ;
-
-test-suite emulation_tests
- : [ run native.cpp : : : <define>BOOST_TYPEOF_EMULATION : emulation : ]
- [ run native_tpl.cpp : : : <define>BOOST_TYPEOF_EMULATION :
- emulation_tpl : ]
- [ run native_this.cpp : : : <define>BOOST_TYPEOF_EMULATION :
- emulation_this : ]
- [ run native_this_tpl.cpp : : : <define>BOOST_TYPEOF_EMULATION :
- emulation_this_tpl : ]
- [ compile-fail native_const_error.cpp : <define>BOOST_TYPEOF_EMULATION :
- emulation_const_error : ]
- [ compile-fail native_cv_error.cpp : <define>BOOST_TYPEOF_EMULATION :
- emulation_cv_error : ]
- # Following test is known to fail on MSVC 7.1 and 8.0.
- [ run native_tu_test.cpp native_tu1.cpp native_tu2.cpp : : :
- <define>BOOST_TYPEOF_EMULATION : emulation_tu_test : ]
- ;
+rule vaseq ( command target )
+{
+ $(command) $(target).cpp ;
+ $(command) $(target)_seq.cpp ;
+ $(command) $(target)_seq_nova.cpp ;
+}
+
+rule run-typeof ( native_target emulation_target )
+{
+ run $(native_target).cpp : : : <define>BOOST_TYPEOF_NATIVE ;
+ run $(native_target).cpp : : : <define>BOOST_TYPEOF_EMULATION :
+ $(emulation_target) : ;
+}
+
+rule compile-fail-typeof ( native_target emulation_target )
+{
+ compile-fail $(native_target).cpp : <define>BOOST_TYPEOF_NATIVE ;
+ compile-fail $(native_target).cpp : <define>BOOST_TYPEOF_EMULATION :
+ $(emulation_target) : ;
+}
+
+vaseq run same_line ;
+vaseq run world ;
+vaseq run world_checkpoint ;
+vaseq run world_checkpoint_all ;
+vaseq run world_this ;
+vaseq run world_tpl ;
+run world_void.cpp ;
+run world_void_nova.cpp ;
+
+run-typeof native emulation ;
+run-typeof native_tpl emulation_tpl ;
+run-typeof native_this emulation_this ;
+run-typeof native_this_tpl emulation_this_tpl ;
+compile-fail-typeof native_const_error emulation_const_error ;
+compile-fail-typeof native_cv_error emulation_cv_error ;
+run native_tu_test.cpp native_tu1.cpp native_tu2.cpp : : :
+ <define>BOOST_TYPEOF_NATIVE ;
+run native_tu_test.cpp native_tu1.cpp native_tu2.cpp : : :
+ <define>BOOST_TYPEOF_EMULATION : emulation_tu_test : ;
 

Modified: trunk/libs/scope_exit/test/world_checkpoint_all.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_checkpoint_all.cpp (original)
+++ trunk/libs/scope_exit/test/world_checkpoint_all.cpp 2012-04-03 16:16:03 EDT (Tue, 03 Apr 2012)
@@ -63,9 +63,10 @@
     // This block must be no-throw.
     person& p = persons_.back();
     person::evolution_t checkpoint = p.evolution;
- BOOST_SCOPE_EXIT_ALL(&, checkpoint, this_) { // Capture all by ref (C++11).
- if(checkpoint == p.evolution) this_->persons_.pop_back();
- }; // Use `;` instead of `SCOPE_EXIT_END` for `BOOST_SCOPE_EXIT_ALL`.
+ // Capture all by reference `&`, but `checkpoint` and `this` (C++11 only).
+ BOOST_SCOPE_EXIT_ALL(&, checkpoint, this) { // Use `this` (not `this_`).
+ if(checkpoint == p.evolution) this->persons_.pop_back();
+ }; // Use `;` (not `SCOPE_EXIT_END`).
 
     // ...
 
@@ -74,7 +75,8 @@
     // Assign new identifier to the person.
     person::id_t const prev_id = p.id;
     p.id = next_id_++;
- BOOST_SCOPE_EXIT_ALL(=, &p, this) { // Capture all by value, `this` (C++11).
+ // Capture all by value `=`, but `p` (C++11 only).
+ BOOST_SCOPE_EXIT_ALL(=, &p) {
         if(checkpoint == p.evolution) {
             this->next_id_ = p.id;
             p.id = prev_id;

Modified: trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp
==============================================================================
--- trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp (original)
+++ trunk/libs/scope_exit/test/world_checkpoint_all_seq.cpp 2012-04-03 16:16:03 EDT (Tue, 03 Apr 2012)
@@ -60,8 +60,8 @@
     // This block must be no-throw.
     person& p = persons_.back();
     person::evolution_t checkpoint = p.evolution;
- BOOST_SCOPE_EXIT_ALL( (&) (checkpoint) (this_) ) {
- if(checkpoint == p.evolution) this_->persons_.pop_back();
+ BOOST_SCOPE_EXIT_ALL( (&) (checkpoint) (this) ) {
+ if(checkpoint == p.evolution) this->persons_.pop_back();
     };
 
     // ...
@@ -71,7 +71,7 @@
     // Assign new identifier to the person.
     person::id_t const prev_id = p.id;
     p.id = next_id_++;
- BOOST_SCOPE_EXIT_ALL( (=) (&p) (this) ) {
+ BOOST_SCOPE_EXIT_ALL( (=) (&p) ) {
         if(checkpoint == p.evolution) {
             this->next_id_ = p.id;
             p.id = prev_id;

Added: trunk/libs/scope_exit/test/world_void_nova.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/world_void_nova.cpp 2012-04-03 16:16:03 EDT (Tue, 03 Apr 2012)
@@ -0,0 +1,11 @@
+
+// Copyright (C) 2006-2009, 2012 Alexander Nasonov
+// Copyright (C) 2012 Lorenzo Caminiti
+// Distributed under 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)
+// Home at http://www.boost.org/libs/scope_exit
+
+#include "nova.hpp"
+#include "world_void.cpp"
+


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