Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50620 - in trunk: boost libs/scope_exit libs/scope_exit/test
From: Alexander.Nasonov_at_[hidden]
Date: 2009-01-15 19:02:39


Author: nasonov
Date: 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
New Revision: 50620
URL: http://svn.boost.org/trac/boost/changeset/50620

Log:
Initial commit of ScopeExit.
Added:
   trunk/boost/scope_exit.hpp (contents, props changed)
   trunk/libs/scope_exit/
   trunk/libs/scope_exit/test/
   trunk/libs/scope_exit/test/Jamfile.v2 (contents, props changed)
   trunk/libs/scope_exit/test/emulation.cpp (contents, props changed)
   trunk/libs/scope_exit/test/emulation_const_error.cpp (contents, props changed)
   trunk/libs/scope_exit/test/emulation_cv_error.cpp (contents, props changed)
   trunk/libs/scope_exit/test/emulation_tpl.cpp (contents, props changed)
   trunk/libs/scope_exit/test/emulation_tu_test.cpp (contents, props changed)
   trunk/libs/scope_exit/test/native.cpp (contents, props changed)
   trunk/libs/scope_exit/test/native_const_error.cpp (contents, props changed)
   trunk/libs/scope_exit/test/native_cv_error.cpp (contents, props changed)
   trunk/libs/scope_exit/test/native_tpl.cpp (contents, props changed)
   trunk/libs/scope_exit/test/native_tu1.cpp (contents, props changed)
   trunk/libs/scope_exit/test/native_tu2.cpp (contents, props changed)
   trunk/libs/scope_exit/test/native_tu_test.cpp (contents, props changed)
   trunk/libs/scope_exit/test/tu_test.hpp (contents, props changed)

Added: trunk/boost/scope_exit.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/scope_exit.hpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,238 @@
+// Copyright Alexander Nasonov 2006-2009
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef FILE_boost_scope_exit_hpp_INCLUDED
+#define FILE_boost_scope_exit_hpp_INCLUDED
+
+#include <boost/config.hpp>
+
+#include <boost/detail/workaround.hpp>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/facilities/empty.hpp>
+#include <boost/preprocessor/punctuation/comma_if.hpp>
+#include <boost/preprocessor/seq/cat.hpp>
+#include <boost/preprocessor/seq/elem.hpp>
+#include <boost/preprocessor/seq/for_each_i.hpp>
+#include <boost/typeof/typeof.hpp>
+
+#if defined(__GNUC__) && !defined(BOOST_INTEL)
+# define BOOST_SCOPE_EXIT_AUX_GCC (__GNUC__ * 100 + __GNUC_MINOR__)
+#else
+# define BOOST_SCOPE_EXIT_AUX_GCC 0
+#endif
+
+#if BOOST_WORKAROUND(BOOST_SCOPE_EXIT_AUX_GCC, BOOST_TESTED_AT(413))
+#define BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
+#endif
+
+// Steven Watanabe's trick
+namespace boost { namespace scope_exit { namespace aux {
+
+ template<int> struct declare;
+
+ typedef void* declared;
+ struct undeclared { declared dummy[2]; };
+
+ template<>
+ struct declare<sizeof(undeclared)>
+ {
+ template<int>
+ struct apply
+ {
+ declared value;
+ friend void operator>(bool, const apply&) {}
+ };
+ };
+
+ template<>
+ struct declare<sizeof(declared)>
+ {
+ static const int apply = 0;
+ };
+} } }
+
+extern boost::scope_exit::aux::undeclared boost_scope_exit_args; // undefined
+
+
+namespace boost { namespace scope_exit { namespace aux {
+
+typedef void (*ref_tag)(int&);
+typedef void (*val_tag)(int );
+
+template<class T, class Tag> struct member;
+
+template<class T>
+struct member<T,ref_tag>
+{
+ T& value;
+#ifndef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
+ member(T& ref) : value(ref) {}
+#endif
+};
+
+template<class T>
+struct member<T,val_tag>
+{
+ T value;
+#ifndef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
+ member(T& val) : value(val) {}
+#endif
+};
+
+template<class T> inline T& deref(T* p, ref_tag) { return *p; }
+template<class T> inline T& deref(T& r, val_tag) { return r; }
+
+} } }
+
+#define BOOST_SCOPE_EXIT_AUX_GUARD(id) BOOST_PP_CAT(boost_se_guard_, id)
+#define BOOST_SCOPE_EXIT_AUX_GUARD_T(id) BOOST_PP_CAT(boost_se_guard_t_, id)
+#define BOOST_SCOPE_EXIT_AUX_PARAMS(id) BOOST_PP_CAT(boost_se_params_, id)
+#define BOOST_SCOPE_EXIT_AUX_PARAMS_T(id) BOOST_PP_CAT(boost_se_params_t_, id)
+
+#define BOOST_SCOPE_EXIT_AUX_TAG(id, i) \
+ BOOST_PP_SEQ_CAT( (boost_se_tag_)(i)(_)(id) )
+
+#define BOOST_SCOPE_EXIT_AUX_PARAM(id, i, var) \
+ BOOST_PP_SEQ_CAT( (boost_se_param_)(i)(_)(id) )
+
+#define BOOST_SCOPE_EXIT_AUX_PARAM_T(id, i, var) \
+ BOOST_PP_SEQ_CAT( (boost_se_param_t_)(i)(_)(id) )
+
+#define BOOST_SCOPE_EXIT_AUX_CAPTURE_T(id, i, var) \
+ BOOST_PP_SEQ_CAT( (boost_se_capture_t_)(i)(_)(id) )
+
+#define BOOST_SCOPE_EXIT_AUX_DEREF(id, i, var) \
+ boost::scope_exit::aux::deref(var, (BOOST_SCOPE_EXIT_AUX_TAG(id,i))0)
+
+#define BOOST_SCOPE_EXIT_AUX_MEMBER(r, id, i, var) \
+ boost::scope_exit::aux::member< \
+ BOOST_SCOPE_EXIT_AUX_PARAM_T(id,i,var), \
+ BOOST_SCOPE_EXIT_AUX_TAG(id,i) \
+ > BOOST_SCOPE_EXIT_AUX_PARAM(id,i,var);
+
+// idty is (id)(typename) or (id)()
+#define BOOST_SCOPE_EXIT_AUX_ARG_DECL(r, idty, i, var) \
+ BOOST_PP_COMMA_IF(i) BOOST_PP_SEQ_ELEM(1,idty) \
+ BOOST_SCOPE_EXIT_AUX_PARAMS_T(BOOST_PP_SEQ_ELEM(0,idty)):: \
+ BOOST_SCOPE_EXIT_AUX_PARAM_T(BOOST_PP_SEQ_ELEM(0,idty), i, var) var
+
+#define BOOST_SCOPE_EXIT_AUX_ARG(r, id, i, var) BOOST_PP_COMMA_IF(i) \
+ boost_se_params_->BOOST_SCOPE_EXIT_AUX_PARAM(id,i,var).value
+
+#define BOOST_SCOPE_EXIT_AUX_TAG_DECL(r, id, i, var) \
+ typedef void (*BOOST_SCOPE_EXIT_AUX_TAG(id,i))(int var);
+
+
+#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
+
+#define BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, seq)
+
+#define BOOST_SCOPE_EXIT_AUX_PARAM_INIT(r, id, i, var) \
+ BOOST_PP_COMMA_IF(i) { BOOST_SCOPE_EXIT_AUX_DEREF(id,i,var) }
+
+#define BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, seq) \
+ = { BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_PARAM_INIT, id, seq) };
+
+#else
+
+#define BOOST_SCOPE_EXIT_AUX_CTOR_ARG(r, id, i, var) BOOST_PP_COMMA_IF(i) \
+ BOOST_SCOPE_EXIT_AUX_PARAM_T(id,i,var) & BOOST_PP_CAT(a,i)
+
+#define BOOST_SCOPE_EXIT_AUX_MEMBER_INIT(r, id, i, var) BOOST_PP_COMMA_IF(i) \
+ BOOST_SCOPE_EXIT_AUX_PARAM(id,i,var) ( BOOST_PP_CAT(a,i) )
+
+#define BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, seq) \
+ BOOST_SCOPE_EXIT_AUX_PARAMS_T(id)( \
+ BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_CTOR_ARG, id, seq ) ) \
+ : BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_MEMBER_INIT, id, seq) {}
+
+#define BOOST_SCOPE_EXIT_AUX_PARAM_INIT(r, id, i, var) \
+ BOOST_PP_COMMA_IF(i) BOOST_SCOPE_EXIT_AUX_DEREF(id,i,var)
+
+#define BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, seq) \
+ ( BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_PARAM_INIT, id, seq) );
+
+#endif
+
+#if !defined(BOOST_TYPEOF_EMULATION)
+
+#define BOOST_SCOPE_EXIT_AUX_CAPTURE_DECL(r, idty, i, var) \
+ typedef BOOST_TYPEOF_KEYWORD(BOOST_SCOPE_EXIT_AUX_DEREF( \
+ BOOST_PP_SEQ_ELEM(0,idty), i, var)) \
+ BOOST_SCOPE_EXIT_AUX_CAPTURE_T(BOOST_PP_SEQ_ELEM(0,idty), i, var);
+
+#else
+
+namespace boost { namespace scope_exit { namespace aux {
+
+template<class T>
+struct wrapper
+{
+ typedef T type;
+};
+
+template<class T> wrapper<T> wrap(T&);
+
+} } }
+
+#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::scope_exit::aux::wrapper, 1)
+
+#define BOOST_SCOPE_EXIT_AUX_WRAPPED(id, i) \
+ BOOST_PP_SEQ_CAT( (boost_se_wrapped_t_)(i)(_)(id) )
+
+#define BOOST_SCOPE_EXIT_AUX_CAPTURE_DECL(r, idty, i, var) \
+ struct BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_SEQ_ELEM(0,idty), i) \
+ : BOOST_TYPEOF(boost::scope_exit::aux::wrap( \
+ BOOST_SCOPE_EXIT_AUX_DEREF(BOOST_PP_SEQ_ELEM(0, idty), i, var))) {}; \
+ typedef BOOST_PP_SEQ_ELEM(1,idty) \
+ BOOST_SCOPE_EXIT_AUX_WRAPPED(BOOST_PP_SEQ_ELEM(0,idty), i)::type \
+ BOOST_SCOPE_EXIT_AUX_CAPTURE_T(BOOST_PP_SEQ_ELEM(0,idty), i, var);
+
+#endif
+
+#define BOOST_SCOPE_EXIT_AUX_PARAM_DECL(r, idty, i, var) \
+ typedef BOOST_SCOPE_EXIT_AUX_CAPTURE_T(BOOST_PP_SEQ_ELEM(0,idty), i, var) \
+ BOOST_SCOPE_EXIT_AUX_PARAM_T(BOOST_PP_SEQ_ELEM(0,idty), i, var);
+
+
+#define BOOST_SCOPE_EXIT_AUX_IMPL(id, seq, ty) \
+ BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_TAG_DECL, id, seq) \
+ BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_CAPTURE_DECL, (id)(ty), seq) \
+ struct BOOST_SCOPE_EXIT_AUX_PARAMS_T(id) { \
+ BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_PARAM_DECL, (id)(ty), seq)\
+ BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_MEMBER, id, seq) \
+ BOOST_SCOPE_EXIT_AUX_PARAMS_T_CTOR(id, seq) \
+ } BOOST_SCOPE_EXIT_AUX_PARAMS(id) BOOST_SCOPE_EXIT_AUX_PARAMS_INIT(id, seq)\
+ boost::scope_exit::aux::declare<sizeof(boost_scope_exit_args)> \
+ ::apply<0> boost_scope_exit_args; \
+ boost_scope_exit_args.value = &BOOST_SCOPE_EXIT_AUX_PARAMS(id); \
+ struct BOOST_SCOPE_EXIT_AUX_GUARD_T(id) { \
+ BOOST_SCOPE_EXIT_AUX_PARAMS_T(id)* boost_se_params_; \
+ BOOST_SCOPE_EXIT_AUX_GUARD_T(id) (void* boost_se_params) \
+ : boost_se_params_( \
+ (BOOST_SCOPE_EXIT_AUX_PARAMS_T(id)*)boost_se_params) \
+ {} \
+ ~BOOST_SCOPE_EXIT_AUX_GUARD_T(id)() { boost_se_body( \
+ BOOST_PP_SEQ_FOR_EACH_I(BOOST_SCOPE_EXIT_AUX_ARG, id, seq) ); } \
+ static void boost_se_body(BOOST_PP_SEQ_FOR_EACH_I( \
+ BOOST_SCOPE_EXIT_AUX_ARG_DECL, (id)(ty), seq) )
+
+#define BOOST_SCOPE_EXIT_END } BOOST_SCOPE_EXIT_AUX_GUARD(__LINE__) ( \
+ boost_scope_exit_args.value);
+
+#define BOOST_SCOPE_EXIT(seq) \
+ BOOST_SCOPE_EXIT_AUX_IMPL(__LINE__, seq, BOOST_PP_EMPTY())
+
+#ifdef BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND
+#define BOOST_SCOPE_EXIT_TPL(seq) \
+ BOOST_SCOPE_EXIT_AUX_IMPL(__LINE__, seq, typename)
+#else
+#define BOOST_SCOPE_EXIT_TPL(seq) BOOST_SCOPE_EXIT(seq)
+#endif
+
+#endif // #ifndef FILE_boost_scope_exit_hpp_INCLUDED
+

Added: trunk/libs/scope_exit/test/Jamfile.v2
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/Jamfile.v2 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,25 @@
+# Copyright Alexander Nasonov 2007
+#
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+# TODO: get rid of dummy .cpp files that only #include other .cpp file.
+
+import testing ;
+
+run native.cpp ../../../libs/test/build//boost_test_exec_monitor : : : <define>BOOST_TYPEOF_NATIVE : ;
+run emulation.cpp ../../../libs/test/build//boost_test_exec_monitor : : : <define>BOOST_TYPEOF_EMULATION : ;
+
+run native_tpl.cpp ../../../libs/test/build//boost_test_exec_monitor : : : <define>BOOST_TYPEOF_NATIVE : ;
+run emulation_tpl.cpp ../../../libs/test/build//boost_test_exec_monitor : : : <define>BOOST_TYPEOF_EMULATION : ;
+
+compile-fail native_const_error.cpp : <define>BOOST_TYPEOF_NATIVE ;
+compile-fail emulation_const_error.cpp : <define>BOOST_TYPEOF_EMULATION ;
+
+compile-fail native_cv_error.cpp : <define>BOOST_TYPEOF_NATIVE ;
+compile-fail emulation_cv_error.cpp : <define>BOOST_TYPEOF_EMULATION ;
+
+run native_tu_test.cpp native_tu1.cpp native_tu2.cpp ../../../libs/test/build//boost_test_exec_monitor : : : <define>BOOST_TYPEOF_NATIVE : ;
+run emulation_tu_test.cpp native_tu1.cpp native_tu2.cpp ../../../libs/test/build//boost_test_exec_monitor : : : <define>BOOST_TYPEOF_EMULATION : ;
+

Added: trunk/libs/scope_exit/test/emulation.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/emulation.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,2 @@
+#include "native.cpp"
+

Added: trunk/libs/scope_exit/test/emulation_const_error.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/emulation_const_error.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1 @@
+#include "native_const_error.cpp"

Added: trunk/libs/scope_exit/test/emulation_cv_error.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/emulation_cv_error.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1 @@
+#include "native_cv_error.cpp"

Added: trunk/libs/scope_exit/test/emulation_tpl.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/emulation_tpl.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,2 @@
+#include "native_tpl.cpp"
+

Added: trunk/libs/scope_exit/test/emulation_tu_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/emulation_tu_test.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1 @@
+#include "native_tu_test.cpp"

Added: trunk/libs/scope_exit/test/native.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/native.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,124 @@
+// Copyright Alexander Nasonov 2007-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <iostream>
+#include <ostream>
+#include <string>
+
+#include <boost/scope_exit.hpp>
+
+#include <boost/typeof/typeof.hpp>
+#include <boost/typeof/std/string.hpp>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost::unit_test;
+
+std::string g_str;
+
+template<int Dummy = 0>
+struct Holder
+{
+ static long g_long;
+};
+
+template<int Dummy> long Holder<Dummy>::g_long;
+
+void test_non_local()
+{
+ // ... and one local variable as well:
+ int i = 0;
+
+ {
+ g_str = "";
+ Holder<>::g_long = 1;
+
+ BOOST_SCOPE_EXIT( (&i) )
+ {
+ i = 1;
+ g_str = "g_str";
+ } BOOST_SCOPE_EXIT_END
+
+ BOOST_SCOPE_EXIT( (&i) )
+ try
+ {
+ i = 2;
+ Holder<>::g_long = 2;
+ throw 0;
+ } catch(...) {}
+ BOOST_SCOPE_EXIT_END
+
+ BOOST_CHECK(i == 0);
+ BOOST_CHECK(g_str == "");
+ BOOST_CHECK(Holder<>::g_long == 1);
+ }
+
+ BOOST_CHECK(Holder<>::g_long == 2);
+ BOOST_CHECK(g_str == "g_str");
+ BOOST_CHECK(i == 1); // Check that first declared is executed last
+
+ try
+ {
+ BOOST_SCOPE_EXIT( (&i) )
+ {
+ i = 3;
+ g_str = "try: g_str";
+ } BOOST_SCOPE_EXIT_END
+
+ BOOST_SCOPE_EXIT( (&i) )
+ {
+ i = 4;
+ Holder<>::g_long = 3;
+ } BOOST_SCOPE_EXIT_END
+
+ BOOST_CHECK(i == 1);
+ BOOST_CHECK(g_str == "g_str");
+ BOOST_CHECK(Holder<>::g_long == 2);
+
+ throw 0;
+ }
+ catch(int)
+ {
+ BOOST_CHECK(Holder<>::g_long == 3);
+ BOOST_CHECK(g_str == "try: g_str");
+ BOOST_CHECK(i == 3); // Check that first declared is executed last
+ }
+}
+
+bool foo()
+{
+ return true;
+}
+
+void test_types()
+{
+ bool (*pf)() = &foo;
+ bool (&rf)() = foo;
+ bool results[2] = {};
+
+ {
+ BOOST_SCOPE_EXIT( (&results)(&pf)(&rf) )
+ {
+ results[0] = pf();
+ results[1] = rf();
+ }
+ BOOST_SCOPE_EXIT_END
+
+ BOOST_CHECK(results[0] == false);
+ BOOST_CHECK(results[1] == false);
+ }
+
+ BOOST_CHECK(results[0] == true);
+ BOOST_CHECK(results[1] == true);
+}
+
+test_suite* init_unit_test_suite( int, char* [] )
+{
+ framework::master_test_suite().p_name.value = "Unit test for ScopeExit";
+ framework::master_test_suite().add( BOOST_TEST_CASE( &test_non_local ));
+ framework::master_test_suite().add( BOOST_TEST_CASE( &test_types ));
+ return 0;
+}
+

Added: trunk/libs/scope_exit/test/native_const_error.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/native_const_error.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,17 @@
+// Copyright Alexander Nasonov 2007-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/scope_exit.hpp>
+
+int main()
+{
+ int const i = 0;
+ BOOST_SCOPE_EXIT( (&i) )
+ {
+ i = 5;
+ } BOOST_SCOPE_EXIT_END
+}
+

Added: trunk/libs/scope_exit/test/native_cv_error.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/native_cv_error.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,22 @@
+// Copyright Alexander Nasonov 2007-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <string>
+
+#include <boost/scope_exit.hpp>
+
+#include <boost/typeof/typeof.hpp>
+#include <boost/typeof/std/string.hpp>
+
+int main()
+{
+ std::string const volatile s;
+ BOOST_SCOPE_EXIT( (&s) )
+ {
+ s = "";
+ } BOOST_SCOPE_EXIT_END
+}
+

Added: trunk/libs/scope_exit/test/native_tpl.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/native_tpl.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,87 @@
+// Copyright Alexander Nasonov 2007-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <iostream>
+#include <ostream>
+#include <vector>
+
+#include <boost/scope_exit.hpp>
+
+#include <boost/rational.hpp>
+#include <boost/typeof/typeof.hpp>
+#include <boost/typeof/std/vector.hpp>
+#include <boost/test/unit_test.hpp>
+
+using namespace boost::unit_test;
+
+template<class type>
+void tpl_long( type tval
+ , type& t
+ , type const& tc
+ , type volatile& tv
+ , type const volatile& tcv
+ )
+{
+ int i = 0; // non-dependent name
+ type const remember(tval);
+
+ {
+ BOOST_SCOPE_EXIT_TPL( (&tval)(&t)(&tc)(&tv)(&tcv)(&i) )
+ {
+ tval = 1;
+ ++t;
+ ++tv;
+ }
+ BOOST_SCOPE_EXIT_END
+
+ BOOST_CHECK(t == remember);
+ BOOST_CHECK(tval == remember);
+ }
+
+ BOOST_CHECK(tval == 1);
+ BOOST_CHECK(t == remember + 2);
+}
+
+template<class Vector, int Value>
+void tpl_vector( Vector vval
+ , Vector& v
+ , Vector const& vc
+ )
+{
+ Vector const remember(vval);
+
+ {
+ BOOST_SCOPE_EXIT_TPL( (&vval)(&v)(&vc) )
+ {
+ v.push_back(-Value);
+ vval.push_back(Value);
+ }
+ BOOST_SCOPE_EXIT_END
+
+ BOOST_CHECK(v.size() == remember.size());
+ BOOST_CHECK(vval.size() == remember.size());
+ }
+
+ BOOST_CHECK(v.size() == 1 + remember.size());
+ BOOST_CHECK(vval.size() == 1 + remember.size());
+}
+
+void test_tpl()
+{
+ long l = 137;
+ tpl_long(l, l, l, l, l);
+
+ std::vector<int> v(10, 137);
+ tpl_vector<std::vector<int>, 13>(v, v, v);
+}
+
+test_suite* init_unit_test_suite( int, char* [] )
+{
+ framework::master_test_suite().p_name.value = "Unit test for ScopeExit TPL";
+ framework::master_test_suite().add( BOOST_TEST_CASE( &test_tpl ));
+ return 0;
+}
+

Added: trunk/libs/scope_exit/test/native_tu1.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/native_tu1.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,13 @@
+// Copyright Alexander Nasonov 2007-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "tu_test.hpp"
+
+int tu1()
+{
+ return inline_f() + template_f(1);
+}
+

Added: trunk/libs/scope_exit/test/native_tu2.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/native_tu2.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,13 @@
+// Copyright Alexander Nasonov 2007-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "tu_test.hpp"
+
+int tu2()
+{
+ return inline_f() + template_f(2);
+}
+

Added: trunk/libs/scope_exit/test/native_tu_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/native_tu_test.cpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,24 @@
+// Copyright Alexander Nasonov 2007-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include "tu_test.hpp"
+
+#include <boost/test/unit_test.hpp>
+
+using namespace boost::unit_test;
+
+void test()
+{
+ BOOST_CHECK(tu1() == 1);
+ BOOST_CHECK(tu2() == 2);
+}
+
+test_suite* init_unit_test_suite( int, char* [] )
+{
+ framework::master_test_suite().p_name.value = "TU unit test for ScopeExit";
+ framework::master_test_suite().add( BOOST_TEST_CASE( &test ));
+ return 0;
+}

Added: trunk/libs/scope_exit/test/tu_test.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/scope_exit/test/tu_test.hpp 2009-01-15 19:02:37 EST (Thu, 15 Jan 2009)
@@ -0,0 +1,41 @@
+// Copyright Alexander Nasonov 2007-2008
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/scope_exit.hpp>
+
+int tu1();
+int tu2();
+
+inline int inline_f()
+{
+ int i = 99;
+ {
+ BOOST_SCOPE_EXIT( (&i) ) { i = -1; } BOOST_SCOPE_EXIT_END
+ }
+ return i;
+}
+
+#if !defined(BOOST_SCOPE_EXIT_AUX_GCC)
+#error "BOOST_SCOPE_EXIT_AUX_GCC undefined!"
+#elif BOOST_SCOPE_EXIT_AUX_GCC == 0 || BOOST_SCOPE_EXIT_AUX_GCC >= 304
+template<class Int>
+Int template_f(Int i)
+{
+ {
+ BOOST_SCOPE_EXIT_TPL( (&i) ) { ++i; } BOOST_SCOPE_EXIT_END
+ }
+ return i;
+}
+#else
+inline int template_f(int i)
+{
+ {
+ BOOST_SCOPE_EXIT( (&i) ) { ++i; } BOOST_SCOPE_EXIT_END
+ }
+ return i;
+}
+#endif
+


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