Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77666 - in trunk: boost/thread libs/thread/doc libs/thread/test libs/thread/test/sync/futures libs/thread/test/sync/futures/future libs/thread/test/sync/futures/promise
From: vicente.botet_at_[hidden]
Date: 2012-03-31 11:19:24


Author: viboes
Date: 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
New Revision: 77666
URL: http://svn.boost.org/trac/boost/changeset/77666

Log:
Thread: Added promise allocator ctor + more tests
Added:
   trunk/libs/thread/test/sync/futures/future/copy_assign_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/futures/future/copy_ctor_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/futures/future/default_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/futures/future/dtor_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/futures/future/get_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/futures/future/move_assign_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/futures/future/move_ctor_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/futures/promise/alloc_ctor_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/futures/promise/copy_ctor_fail.cpp (contents, props changed)
   trunk/libs/thread/test/sync/futures/promise/use_allocator_pass.cpp (contents, props changed)
   trunk/libs/thread/test/sync/futures/test_allocator.hpp (contents, props changed)
Text files modified:
   trunk/boost/thread/future.hpp | 41 ++++++++++++++++-
   trunk/libs/thread/doc/changes.qbk | 2
   trunk/libs/thread/doc/future_ref.qbk | 26 +++++++++-
   trunk/libs/thread/test/Jamfile.v2 | 11 ++++
   trunk/libs/thread/test/sync/futures/promise/copy_assign_fail.cpp | 67 ----------------------------
   trunk/libs/thread/test/sync/futures/promise/default_pass.cpp | 3 -
   trunk/libs/thread/test/sync/futures/promise/dtor_pass.cpp | 8 ---
   trunk/libs/thread/test/sync/futures/promise/get_future_pass.cpp | 38 ++++++++--------
   trunk/libs/thread/test/sync/futures/promise/move_assign_pass.cpp | 95 ++++++++++++++++++++++++++++++---------
   trunk/libs/thread/test/sync/futures/promise/move_ctor_pass.cpp | 88 ++++++++++++++++++++++++++++--------
   10 files changed, 233 insertions(+), 146 deletions(-)

Modified: trunk/boost/thread/future.hpp
==============================================================================
--- trunk/boost/thread/future.hpp (original)
+++ trunk/boost/thread/future.hpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -36,6 +36,10 @@
 #include <boost/chrono/system_clocks.hpp>
 #endif
 
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+#include <boost/thread/detail/memory.hpp>
+#endif
+
 #if BOOST_THREAD_VERSION==1
 #define BOOST_THREAD_FUTURE unique_future
 #else
@@ -556,6 +560,17 @@
             future_object& operator=(future_object const&);
         };
 
+ template<typename T, typename Allocator>
+ struct future_object_alloc: public future_object<T>
+ {
+ typedef future_object<T> base;
+ Allocator alloc_;
+
+ public:
+ explicit future_object_alloc(const Allocator& a)
+ : alloc_(a) {}
+
+ };
         class future_waiter
         {
             struct registered_waiter;
@@ -1257,13 +1272,23 @@
         }
 
     public:
-// template <class Allocator> explicit promise(Allocator a);
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+ template <class Allocator>
+ explicit promise(boost::container::allocator_arg_t, Allocator a)
+ {
+ typedef typename Allocator::template rebind<detail::future_object<R> >::other A2;
+ A2 a2(a);
+ typedef thread_detail::allocator_destructor<A2> D;
 
+ future_ = future_ptr(::new(a2.allocate(1)) detail::future_object<R>(), D(a2, 1) );
+ future_obtained = false;
+ }
+#endif
         promise():
 #if BOOST_THREAD_VERSION==1
             future_(),
 #else
- future_(new detail::future_object<R>),
+ future_(new detail::future_object<R>()),
 #endif
             future_obtained(false)
         {}
@@ -1460,8 +1485,18 @@
 #endif
         }
     public:
-// template <class Allocator> explicit promise(Allocator a);
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+ template <class Allocator>
+ explicit promise(boost::container::allocator_arg_t, Allocator a)
+ {
+ typedef typename Allocator::template rebind<detail::future_object<void> >::other A2;
+ A2 a2(a);
+ typedef thread_detail::allocator_destructor<A2> D;
 
+ future_ = future_ptr(::new(a2.allocate(1)) detail::future_object<void>(), D(a2, 1) );
+ future_obtained = false;
+ }
+#endif
         promise():
 #if BOOST_THREAD_VERSION==1
             future_(),

Modified: trunk/libs/thread/doc/changes.qbk
==============================================================================
--- trunk/libs/thread/doc/changes.qbk (original)
+++ trunk/libs/thread/doc/changes.qbk 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -21,6 +21,7 @@
 * [@http://svn.boost.org/trac/boost/ticket/6217 #6217] Enhance Boost.Thread shared mutex interface following Howard Hinnant proposal.
 * [@http://svn.boost.org/trac/boost/ticket/6224 #6224] c++11 compliance: Add the use of standard noexcept on compilers supporting them.
 * [@http://svn.boost.org/trac/boost/ticket/6226 #6226] c++11 compliance: Add explicit bool conversion from locks.
+* [@http://svn.boost.org/trac/boost/ticket/6228 #6228] Add promise constructor with allocator following the standard c++11.
 * [@http://svn.boost.org/trac/boost/ticket/6230 #6230] c++11 compliance: Follows the exception reporting mechanism as defined in the c++11.
 * [@http://svn.boost.org/trac/boost/ticket/6272 #6272] c++11 compliance: Add thread::id hash specialization.
 * [@http://svn.boost.org/trac/boost/ticket/6273 #6273] c++11 compliance: Add cv_status enum class and use it on the conditions wait functions.
@@ -181,7 +182,6 @@
   * [@http://svn.boost.org/trac/boost/ticket/6342 #6342] Breaking change: Adapt the one_flag and call_once to the c++11 interface.
 
   * [@http://svn.boost.org/trac/boost/ticket/6227 #6227] Use of variadic templates on Generic Locking Algorithms on compilers providing them.
- * [@http://svn.boost.org/trac/boost/ticket/6228 #6228] Add promise and futures constructor with allocator following the standard c++11.
   * [@http://svn.boost.org/trac/boost/ticket/6270 #6270] Add thread constructor from movable callable and movable arguments following C++11.
          
 

Modified: trunk/libs/thread/doc/future_ref.qbk
==============================================================================
--- trunk/libs/thread/doc/future_ref.qbk (original)
+++ trunk/libs/thread/doc/future_ref.qbk 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -44,8 +44,10 @@
     template <typename R>
     void swap(promise<R>& x, promise<R>& y) noexcept;
 
- //template <class R, class Alloc>
- //struct uses_allocator<promise<R>, Alloc>; // NOT YET IMPLEMENTED
+ namespace container {
+ template <class R, class Alloc>
+ struct uses_allocator<promise<R>, Alloc>:: true_type;
+ }
 
     template <typename R>
     class future;
@@ -703,7 +705,8 @@
     public:
 
         promise();
- // template <class Allocator> explicit promise(Allocator a); // NOT YET IMPLEMENTED
+ template <class Allocator>
+ explicit promise(allocator_arg_t, Allocator a);
         promise & operator=(const promise & rhs);// = delete;
         promise(const promise & rhs);// = delete;
         ~promise();
@@ -744,6 +747,23 @@
 
 [endsect]
 
+[section:alloc_constructor Allocator Constructor]
+
+ template <class Allocator>
+ explicit promise(allocator_arg_t, Allocator a);
+
+[variablelist
+
+[[Effects:] [Constructs a new __promise__ with no associated result using the allocator `a`.]]
+
+[[Throws:] [Nothing.]]
+
+]
+
+[endsect]
+
+
+
 [section:move_constructor Move Constructor]
 
     promise(promise && other);

Modified: trunk/libs/thread/test/Jamfile.v2
==============================================================================
--- trunk/libs/thread/test/Jamfile.v2 (original)
+++ trunk/libs/thread/test/Jamfile.v2 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -165,13 +165,24 @@
     test-suite futures
     :
     # [ thread-run2 ./sync/futures/async/async_pass.cpp : async__async_p ]
+
           [ thread-compile-fail-V2 ./sync/futures/promise/copy_assign_fail.cpp : : promise__copy_assign_f ]
+ [ thread-compile-fail-V2 ./sync/futures/promise/copy_ctor_fail.cpp : : promise__copy_ctor_f ]
+ [ thread-run2 ./sync/futures/promise/alloc_ctor_pass.cpp : promise__alloc_ctor_p ]
           [ thread-run2 ./sync/futures/promise/default_pass.cpp : promise__default_p ]
           [ thread-run2 ./sync/futures/promise/dtor_pass.cpp : promise__dtor_p ]
           [ thread-run2 ./sync/futures/promise/get_future_pass.cpp : promise__get_future_p ]
           [ thread-run2 ./sync/futures/promise/move_ctor_pass.cpp : promise__move_ctor_p ]
           [ thread-run2 ./sync/futures/promise/move_assign_pass.cpp : promise__move_asign_p ]
+ [ thread-run2 ./sync/futures/promise/use_allocator_pass.cpp : promise__use_allocator_p ]
 
+ [ thread-compile-fail-V2 ./sync/futures/future/copy_assign_fail.cpp : : future__copy_assign_f ]
+ [ thread-compile-fail-V2 ./sync/futures/future/copy_ctor_fail.cpp : : future__copy_ctor_f ]
+ [ thread-run2 ./sync/futures/future/default_pass.cpp : future__default_p ]
+ [ thread-run2 ./sync/futures/future/dtor_pass.cpp : future__dtor_p ]
+ #[ thread-run2 ./sync/futures/future/get_pass.cpp : future__get_p ]
+ [ thread-run2 ./sync/futures/future/move_ctor_pass.cpp : future__move_ctor_p ]
+ [ thread-run2 ./sync/futures/future/move_assign_pass.cpp : future__move_asign_p ]
           [ thread-run2 ./sync/futures/future/share_pass.cpp : future__share_p ]
 
     ;

Added: trunk/libs/thread/test/sync/futures/future/copy_assign_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/future/copy_assign_fail.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,38 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/future.hpp>
+
+// class future<R>
+
+// future& operator=(const future&) = delete;
+
+
+#define BOOST_THREAD_VERSION 2
+#include <boost/thread/future.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ {
+ typedef int T;
+ boost::promise<T> p;
+ boost::future<T> f0 = p.get_future();
+ boost::future<T> f;
+ f = f0;
+ }
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/futures/future/copy_ctor_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/future/copy_ctor_fail.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/future.hpp>
+// class future<R>
+
+// future(const future&) = delete;
+
+
+#define BOOST_THREAD_VERSION 2
+#include <boost/thread/future.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ {
+ typedef int T;
+ boost::promise<T> p;
+ boost::future<T> f0 = p.get_future();
+ boost::future<T> f = f0;
+ }
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/futures/future/default_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/future/default_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/future.hpp>
+
+// class promise<R>
+
+// promise();
+
+#define BOOST_THREAD_VERSION 2
+
+#include <boost/thread/future.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+
+ {
+ boost::promise<int> p;
+ boost::future<int> f = p.get_future();
+ BOOST_TEST(f.valid());
+ }
+ {
+ boost::promise<int&> p;
+ boost::future<int&> f = p.get_future();
+ BOOST_TEST(f.valid());
+ }
+ {
+ boost::promise<void> p;
+ std::cout << __LINE__ << std::endl;
+ boost::future<void> f = p.get_future();
+ std::cout << __LINE__ << std::endl;
+ BOOST_TEST(f.valid());
+ }
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/futures/future/dtor_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/future/dtor_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,80 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/future.hpp>
+
+// class promise<R>
+
+// ~promise();
+
+#define BOOST_THREAD_VERSION 2
+#include <boost/exception/exception.hpp>
+
+#include <boost/thread/future.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+#include <libs/thread/test/sync/futures/test_allocator.hpp>
+#endif
+
+int main()
+{
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ typedef int T;
+ boost::future<T> f;
+ {
+ boost::promise<T> p(boost::container::allocator_arg, test_allocator<T>());
+ BOOST_TEST(test_alloc_base::count == 1);
+ f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ }
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ typedef int& T;
+ boost::future<T> f;
+ {
+ boost::promise<T> p(boost::container::allocator_arg, test_allocator<int>());
+ BOOST_TEST(test_alloc_base::count == 1);
+ f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ }
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ typedef void T;
+ boost::future<T> f;
+ {
+ boost::promise<T> p(boost::container::allocator_arg, test_allocator<T>());
+ BOOST_TEST(test_alloc_base::count == 1);
+ f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ }
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+#endif
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/futures/future/get_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/future/get_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,171 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/future.hpp>
+
+// class promise<R>
+
+// future<R> get_future();
+
+#define BOOST_THREAD_VERSION 2
+
+#include <boost/thread/future.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+namespace boost
+{
+template <typename T>
+struct wrap
+{
+ wrap(T const& v) : value(v){}
+ T value;
+
+};
+
+template <typename T>
+exception_ptr make_exception_ptr(T v) {
+ return copy_exception(wrap<T>(v));
+}
+}
+
+void func1(boost::promise<int> p)
+{
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
+ p.set_value(3);
+}
+
+void func2(boost::promise<int> p)
+{
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
+ p.set_exception(boost::make_exception_ptr(3));
+}
+
+int j = 0;
+
+void func3(boost::promise<int&> p)
+{
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
+ j = 5;
+ p.set_value(j);
+}
+
+void func4(boost::promise<int&> p)
+{
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
+ p.set_exception(boost::make_exception_ptr(3.5));
+}
+
+void func5(boost::promise<void> p)
+{
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
+ p.set_value();
+}
+
+void func6(boost::promise<void> p)
+{
+ boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
+ p.set_exception(boost::make_exception_ptr('c'));
+}
+
+
+int main()
+{
+ {
+ typedef int T;
+ {
+ boost::promise<T> p;
+ boost::future<T> f = p.get_future();
+ boost::thread(func1, boost::move(p)).detach();
+ BOOST_TEST(f.valid());
+ BOOST_TEST(f.get() == 3);
+ BOOST_TEST(!f.valid());
+ }
+ {
+ boost::promise<T> p;
+ boost::future<T> f = p.get_future();
+ boost::thread(func2, boost::move(p)).detach();
+ try
+ {
+ BOOST_TEST(f.valid());
+ BOOST_TEST(f.get() == 3);
+ BOOST_TEST(false);
+ }
+ catch (int i)
+ {
+ BOOST_TEST(i == 3);
+ }
+ BOOST_TEST(!f.valid());
+ }
+ }
+// {
+// typedef int& T;
+// {
+// boost::promise<T> p;
+// boost::future<T> f = p.get_future();
+// boost::thread(func3, boost::move(p)).detach();
+// BOOST_TEST(f.valid());
+// BOOST_TEST(f.get() == 5);
+// BOOST_TEST(!f.valid());
+// }
+// {
+// boost::promise<T> p;
+// boost::future<T> f = p.get_future();
+// boost::thread(func4, boost::move(p)).detach();
+// try
+// {
+// BOOST_TEST(f.valid());
+// BOOST_TEST(f.get() == 3);
+// BOOST_TEST(false);
+// }
+// catch (double i)
+// {
+// BOOST_TEST(i == 3.5);
+// }
+// BOOST_TEST(!f.valid());
+// }
+// }
+// {
+// typedef void T;
+// {
+// boost::promise<T> p;
+// boost::future<T> f = p.get_future();
+// boost::thread(func5, boost::move(p)).detach();
+// BOOST_TEST(f.valid());
+// f.get();
+// BOOST_TEST(!f.valid());
+// }
+// {
+// boost::promise<T> p;
+// boost::future<T> f = p.get_future();
+// boost::thread(func6, boost::move(p)).detach();
+// try
+// {
+// BOOST_TEST(f.valid());
+// f.get();
+// BOOST_TEST(false);
+// }
+// catch (char i)
+// {
+// BOOST_TEST(i == 'c');
+// }
+// BOOST_TEST(!f.valid());
+// }
+// }
+
+
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/futures/future/move_assign_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/future/move_assign_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,88 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <future>
+
+// class promise<R>
+
+// promise& operator=(promise&& rhs);
+
+#define BOOST_THREAD_VERSION 2
+#define BOOST_THREAD_FUTURE_USES_ALLOCATORS
+
+#include <boost/thread/future.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::mutex m0;
+boost::mutex m1;
+
+int main()
+{
+ {
+ typedef int T;
+ boost::promise<T> p;
+ boost::future<T> f0 = p.get_future();
+ boost::future<T> f;
+ f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(f.valid());
+ }
+ {
+ typedef int T;
+ boost::future<T> f0;
+ boost::future<T> f;
+ f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(!f.valid());
+ }
+ {
+ typedef int& T;
+ boost::promise<T> p;
+ boost::future<T> f0 = p.get_future();
+ boost::future<T> f;
+ f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(f.valid());
+ }
+ {
+ typedef int& T;
+ boost::future<T> f0;
+ boost::future<T> f;
+ f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(!f.valid());
+ }
+ {
+ typedef void T;
+ boost::promise<T> p;
+ boost::future<T> f0 = p.get_future();
+ boost::future<T> f;
+ f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(f.valid());
+ }
+ {
+ typedef void T;
+ boost::future<T> f0;
+ boost::future<T> f;
+ f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(!f.valid());
+ }
+
+
+ return boost::report_errors();
+
+}
+

Added: trunk/libs/thread/test/sync/futures/future/move_ctor_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/future/move_ctor_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <future>
+
+// class promise<R>
+
+// promise(promise&& rhs);
+
+#define BOOST_THREAD_VERSION 2
+#define BOOST_THREAD_FUTURE_USES_ALLOCATORS
+
+#include <boost/thread/future.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+boost::mutex m;
+
+int main()
+{
+ {
+ typedef int T;
+ boost::promise<T> p;
+ boost::future<T> f0 = p.get_future();
+ boost::future<T> f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(f.valid());
+ }
+ {
+ typedef int T;
+ boost::future<T> f0;
+ boost::future<T> f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(!f.valid());
+ }
+ {
+ typedef int& T;
+ boost::promise<T> p;
+ boost::future<T> f0 = p.get_future();
+ boost::future<T> f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(f.valid());
+ }
+ {
+ typedef int& T;
+ boost::future<T> f0;
+ boost::future<T> f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(!f.valid());
+ }
+ {
+ typedef void T;
+ boost::promise<T> p;
+ boost::future<T> f0 = p.get_future();
+ boost::future<T> f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(f.valid());
+ }
+ {
+ typedef void T;
+ boost::future<T> f0;
+ boost::future<T> f = boost::move(f0);
+ BOOST_TEST(!f0.valid());
+ BOOST_TEST(!f.valid());
+ }
+
+ return boost::report_errors();
+}
+

Added: trunk/libs/thread/test/sync/futures/promise/alloc_ctor_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/promise/alloc_ctor_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,67 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/future.hpp>
+
+// class promise<R>
+
+// promise(allocator_arg_t, const Allocator& a);
+
+#define BOOST_THREAD_VERSION 2
+
+#include <boost/thread/future.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+#include <libs/thread/test/sync/futures/test_allocator.hpp>
+
+int main()
+{
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ boost::promise<int> p(boost::container::allocator_arg, test_allocator<int>());
+ BOOST_TEST(test_alloc_base::count == 1);
+ boost::future<int> f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ boost::promise<int&> p(boost::container::allocator_arg, test_allocator<int>());
+ BOOST_TEST(test_alloc_base::count == 1);
+ boost::future<int&> f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ boost::promise<void> p(boost::container::allocator_arg, test_allocator<void>());
+ BOOST_TEST(test_alloc_base::count == 1);
+ boost::future<void> f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+
+
+ return boost::report_errors();
+}
+
+#else
+int main()
+{
+ return boost::report_errors();
+}
+#endif
+
+

Modified: trunk/libs/thread/test/sync/futures/promise/copy_assign_fail.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/promise/copy_assign_fail.cpp (original)
+++ trunk/libs/thread/test/sync/futures/promise/copy_assign_fail.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -22,78 +22,11 @@
 
 int main()
 {
-
- //BOOST_TEST(test_alloc_base::count == 0);
   {
- //boost::promise<int> p0(boost::allocator_arg, test_allocator<int>());
- //boost::promise<int> p(boost::allocator_arg, test_allocator<int>());
     boost::promise<int> p0;
     boost::promise<int> p;
- //BOOST_TEST(test_alloc_base::count == 2);
     p = p0;
- //BOOST_TEST(test_alloc_base::count == 1);
- boost::future<int> f = p.get_future();
- //BOOST_TEST(test_alloc_base::count == 1);
- BOOST_TEST(f.valid());
- try
- {
- f = p0.get_future();
- BOOST_TEST(false);
- }
- catch (const boost::future_error& e)
- {
- BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
- }
- //BOOST_TEST(test_alloc_base::count == 1);
   }
- //BOOST_TEST(test_alloc_base::count == 0);
-// {
-// //boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>());
-// //boost::promise<int&> p(boost::allocator_arg, test_allocator<int>());
-// boost::promise<int&> p0;
-// boost::promise<int&> p;
-// //BOOST_TEST(test_alloc_base::count == 2);
-// p = p0;
-// //BOOST_TEST(test_alloc_base::count == 1);
-// boost::future<int&> f = p.get_future();
-// //BOOST_TEST(test_alloc_base::count == 1);
-// BOOST_TEST(f.valid());
-// try
-// {
-// f = p0.get_future();
-// BOOST_TEST(false);
-// }
-// catch (const boost::future_error& e)
-// {
-// BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
-// }
-// //BOOST_TEST(test_alloc_base::count == 1);
-// }
-// //BOOST_TEST(test_alloc_base::count == 0);
-// {
-// //boost::promise<void> p0(boost::allocator_arg, test_allocator<void>());
-// //boost::promise<void> p(boost::allocator_arg, test_allocator<void>());
-// boost::promise<void> p0;
-// boost::promise<void> p;
-// //BOOST_TEST(test_alloc_base::count == 2);
-// p = p0;
-// //BOOST_TEST(test_alloc_base::count == 1);
-// boost::future<void> f = p.get_future();
-// //BOOST_TEST(test_alloc_base::count == 1);
-// BOOST_TEST(f.valid());
-// try
-// {
-// f = p0.get_future();
-// BOOST_TEST(false);
-// }
-// catch (const boost::future_error& e)
-// {
-// BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
-// }
-// //BOOST_TEST(test_alloc_base::count == 1);
-// }
- //BOOST_TEST(test_alloc_base::count == 0);
-
 
   return boost::report_errors();
 }

Added: trunk/libs/thread/test/sync/futures/promise/copy_ctor_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/promise/copy_ctor_fail.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/future.hpp>
+// class promise<R>
+// promise& operator=(const promise& rhs) = delete;
+
+#define BOOST_THREAD_VERSION 2
+#include <boost/thread/future.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ {
+ boost::promise<int> p0;
+ boost::promise<int> p(p0);
+ }
+
+ return boost::report_errors();
+}
+

Modified: trunk/libs/thread/test/sync/futures/promise/default_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/promise/default_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/promise/default_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -25,20 +25,17 @@
 
 int main()
 {
- std::cout << __LINE__ << std::endl;
 
   {
       boost::promise<int> p;
       boost::future<int> f = p.get_future();
       BOOST_TEST(f.valid());
   }
- std::cout << __LINE__ << std::endl;
   {
       boost::promise<int&> p;
       boost::future<int&> f = p.get_future();
       BOOST_TEST(f.valid());
   }
- std::cout << __LINE__ << std::endl;
   {
       boost::promise<void> p;
       std::cout << __LINE__ << std::endl;

Modified: trunk/libs/thread/test/sync/futures/promise/dtor_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/promise/dtor_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/promise/dtor_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -25,7 +25,6 @@
 
 int main()
 {
- std::cout << __LINE__ << std::endl;
   {
       typedef int T;
       boost::future<T> f;
@@ -36,7 +35,6 @@
       }
       BOOST_TEST(f.get() == 3);
   }
- std::cout << __LINE__ << std::endl;
   {
       typedef int T;
       boost::future<T> f;
@@ -54,8 +52,6 @@
           BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
       }
   }
-
- std::cout << __LINE__ << std::endl;
   {
       typedef int& T;
       int i = 4;
@@ -67,7 +63,6 @@
       }
       BOOST_TEST(&f.get() == &i);
   }
- std::cout << __LINE__ << std::endl;
   {
       typedef int& T;
       boost::future<T> f;
@@ -85,8 +80,6 @@
           BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::broken_promise));
       }
   }
-
- std::cout << __LINE__ << std::endl;
   {
       typedef void T;
       boost::future<T> f;
@@ -98,7 +91,6 @@
       f.get();
       BOOST_TEST(true);
   }
- std::cout << __LINE__ << std::endl;
   {
       typedef void T;
       boost::future<T> f;

Modified: trunk/libs/thread/test/sync/futures/promise/get_future_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/promise/get_future_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/promise/get_future_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -25,25 +25,25 @@
 
 int main()
 {
-// {
-// boost::promise<double> p;
-// boost::future<double> f = p.get_future();
-// p.set_value(105.5);
-// BOOST_TEST(f.get() == 105.5);
-// }
-// {
-// boost::promise<double> p;
-// boost::future<double> f = p.get_future();
-// try
-// {
-// f = p.get_future();
-// BOOST_TEST(false);
-// }
-// catch (const boost::future_error& e)
-// {
-// BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::future_already_retrieved));
-// }
-// }
+ {
+ boost::promise<double> p;
+ boost::future<double> f = p.get_future();
+ p.set_value(105.5);
+ BOOST_TEST(f.get() == 105.5);
+ }
+ {
+ boost::promise<double> p;
+ boost::future<double> f = p.get_future();
+ try
+ {
+ f = p.get_future();
+ BOOST_TEST(false);
+ }
+ catch (const boost::future_error& e)
+ {
+ BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::future_already_retrieved));
+ }
+ }
   {
       boost::promise<double> p;
       boost::promise<double> p0 = boost::move(p);

Modified: trunk/libs/thread/test/sync/futures/promise/move_assign_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/promise/move_assign_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/promise/move_assign_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -19,26 +19,92 @@
 // promise& operator=(promise&& rhs);
 
 #define BOOST_THREAD_VERSION 2
+#define BOOST_THREAD_FUTURE_USES_ALLOCATORS
 
 #include <boost/thread/future.hpp>
 #include <boost/detail/lightweight_test.hpp>
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+#include <libs/thread/test/sync/futures/test_allocator.hpp>
+#endif
 
 boost::mutex m0;
 boost::mutex m1;
 
 int main()
 {
- //BOOST_TEST(test_alloc_base::count == 0);
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ boost::promise<int> p0(boost::container::allocator_arg, test_allocator<int>());
+ boost::promise<int> p(boost::container::allocator_arg, test_allocator<int>());
+ BOOST_TEST(test_alloc_base::count == 2);
+ p = boost::move(p0);
+ BOOST_TEST(test_alloc_base::count == 1);
+ boost::future<int> f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ try
+ {
+ f = p0.get_future();
+ BOOST_TEST(false);
+ }
+ catch (const boost::future_error& e)
+ {
+ BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
+ }
+ BOOST_TEST(test_alloc_base::count == 1);
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+
+ {
+ boost::promise<int&> p0(boost::container::allocator_arg, test_allocator<int>());
+ boost::promise<int&> p(boost::container::allocator_arg, test_allocator<int>());
+ BOOST_TEST(test_alloc_base::count == 2);
+ p = boost::move(p0);
+ BOOST_TEST(test_alloc_base::count == 1);
+ boost::future<int&> f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ try
+ {
+ f = p0.get_future();
+ BOOST_TEST(false);
+ }
+ catch (const boost::future_error& e)
+ {
+ BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
+ }
+ BOOST_TEST(test_alloc_base::count == 1);
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ boost::promise<void> p0(boost::container::allocator_arg, test_allocator<void>());
+ boost::promise<void> p(boost::container::allocator_arg, test_allocator<void>());
+ BOOST_TEST(test_alloc_base::count == 2);
+ p = boost::move(p0);
+ BOOST_TEST(test_alloc_base::count == 1);
+ boost::future<void> f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ try
+ {
+ f = p0.get_future();
+ BOOST_TEST(false);
+ }
+ catch (const boost::future_error& e)
+ {
+ BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
+ }
+ BOOST_TEST(test_alloc_base::count == 1);
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+
+#endif
   {
- //boost::promise<int> p0(boost::allocator_arg, test_allocator<int>());
- //boost::promise<int> p(boost::allocator_arg, test_allocator<int>());
     boost::promise<int> p0;
     boost::promise<int> p;
- //BOOST_TEST(test_alloc_base::count == 2);
     p = boost::move(p0);
- //BOOST_TEST(test_alloc_base::count == 1);
     boost::future<int> f = p.get_future();
- //BOOST_TEST(test_alloc_base::count == 1);
     BOOST_TEST(f.valid());
     try
     {
@@ -49,19 +115,13 @@
     {
       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
     }
- //BOOST_TEST(test_alloc_base::count == 1);
   }
- //BOOST_TEST(test_alloc_base::count == 0);
+
   {
- //boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>());
- //boost::promise<int&> p(boost::allocator_arg, test_allocator<int>());
     boost::promise<int&> p0;
     boost::promise<int&> p;
- //BOOST_TEST(test_alloc_base::count == 2);
     p = boost::move(p0);
- //BOOST_TEST(test_alloc_base::count == 1);
     boost::future<int&> f = p.get_future();
- //BOOST_TEST(test_alloc_base::count == 1);
     BOOST_TEST(f.valid());
     try
     {
@@ -72,19 +132,12 @@
     {
       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
     }
- //BOOST_TEST(test_alloc_base::count == 1);
   }
- //BOOST_TEST(test_alloc_base::count == 0);
   {
- //boost::promise<void> p0(boost::allocator_arg, test_allocator<void>());
- //boost::promise<void> p(boost::allocator_arg, test_allocator<void>());
     boost::promise<void> p0;
     boost::promise<void> p;
- //BOOST_TEST(test_alloc_base::count == 2);
     p = boost::move(p0);
- //BOOST_TEST(test_alloc_base::count == 1);
     boost::future<void> f = p.get_future();
- //BOOST_TEST(test_alloc_base::count == 1);
     BOOST_TEST(f.valid());
     try
     {
@@ -95,9 +148,7 @@
     {
       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
     }
- //BOOST_TEST(test_alloc_base::count == 1);
   }
- //BOOST_TEST(test_alloc_base::count == 0);
 
   return boost::report_errors();
 

Modified: trunk/libs/thread/test/sync/futures/promise/move_ctor_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/promise/move_ctor_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/promise/move_ctor_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -19,26 +19,89 @@
 // promise(promise&& rhs);
 
 #define BOOST_THREAD_VERSION 2
+#define BOOST_THREAD_FUTURE_USES_ALLOCATORS
 
 #include <boost/thread/future.hpp>
 #include <boost/detail/lightweight_test.hpp>
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+#include <libs/thread/test/sync/futures/test_allocator.hpp>
+#endif
 
 boost::mutex m;
 
 int main()
 {
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ boost::promise<int> p0(boost::container::allocator_arg, test_allocator<int>());
+ boost::promise<int> p(boost::move(p0));
+ BOOST_TEST(test_alloc_base::count == 1);
+ std::cout << __LINE__ << std::endl;
+ boost::future<int> f = p.get_future();
+ std::cout << __LINE__ << std::endl;
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ std::cout << __LINE__ << std::endl;
+ try
+ {
+ f = p0.get_future();
+ BOOST_TEST(false);
+ }
+ catch (const boost::future_error& e)
+ {
+ BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
+ }
+ std::cout << __LINE__ << std::endl;
+ BOOST_TEST(test_alloc_base::count == 1);
+ }
   std::cout << __LINE__ << std::endl;
- //BOOST_TEST(test_alloc_base::count == 0);
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ boost::promise<int&> p0(boost::container::allocator_arg, test_allocator<int>());
+ boost::promise<int&> p(boost::move(p0));
+ BOOST_TEST(test_alloc_base::count == 1);
+ boost::future<int&> f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ try
+ {
+ f = p0.get_future();
+ BOOST_TEST(false);
+ }
+ catch (const boost::future_error& e)
+ {
+ BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
+ }
+ BOOST_TEST(test_alloc_base::count == 1);
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ boost::promise<void> p0(boost::container::allocator_arg, test_allocator<void>());
+ boost::promise<void> p(boost::move(p0));
+ BOOST_TEST(test_alloc_base::count == 1);
+ boost::future<void> f = p.get_future();
+ BOOST_TEST(test_alloc_base::count == 1);
+ BOOST_TEST(f.valid());
+ try
+ {
+ f = p0.get_future();
+ BOOST_TEST(false);
+ }
+ catch (const boost::future_error& e)
+ {
+ BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
+ }
+ BOOST_TEST(test_alloc_base::count == 1);
+ }
+ BOOST_TEST(test_alloc_base::count == 0);
+#endif
   {
- //boost::promise<int> p0(boost::allocator_arg, test_allocator<int>());
- //boost::promise<int> p(boost::move(p0));
     boost::promise<int> p0;
     boost::promise<int> p(boost::move(p0));
- //BOOST_TEST(test_alloc_base::count == 1);
     std::cout << __LINE__ << std::endl;
     boost::future<int> f = p.get_future();
     std::cout << __LINE__ << std::endl;
- //BOOST_TEST(test_alloc_base::count == 1);
     BOOST_TEST(f.valid());
     std::cout << __LINE__ << std::endl;
     try
@@ -51,18 +114,12 @@
       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
     }
     std::cout << __LINE__ << std::endl;
- //BOOST_TEST(test_alloc_base::count == 1);
   }
   std::cout << __LINE__ << std::endl;
- //BOOST_TEST(test_alloc_base::count == 0);
   {
- //boost::promise<int&> p0(boost::allocator_arg, test_allocator<int>());
- //boost::promise<int&> p(boost::move(p0));
     boost::promise<int&> p0;
     boost::promise<int&> p(boost::move(p0));
- //BOOST_TEST(test_alloc_base::count == 1);
     boost::future<int&> f = p.get_future();
- //BOOST_TEST(test_alloc_base::count == 1);
     BOOST_TEST(f.valid());
     try
     {
@@ -73,17 +130,11 @@
     {
       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
     }
- //BOOST_TEST(test_alloc_base::count == 1);
   }
- //BOOST_TEST(test_alloc_base::count == 0);
   {
- //boost::promise<void> p0(boost::allocator_arg, test_allocator<void>());
- //boost::promise<void> p(boost::move(p0));
     boost::promise<void> p0;
     boost::promise<void> p(boost::move(p0));
- //BOOST_TEST(test_alloc_base::count == 1);
     boost::future<void> f = p.get_future();
- //BOOST_TEST(test_alloc_base::count == 1);
     BOOST_TEST(f.valid());
     try
     {
@@ -94,10 +145,7 @@
     {
       BOOST_TEST(e.code() == boost::system::make_error_code(boost::future_errc::no_state));
     }
- //BOOST_TEST(test_alloc_base::count == 1);
   }
- //BOOST_TEST(test_alloc_base::count == 0);
-
 
   return boost::report_errors();
 }

Added: trunk/libs/thread/test/sync/futures/promise/use_allocator_pass.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/promise/use_allocator_pass.cpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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)
+
+// <boost/thread/future.hpp>
+
+// class promise<R>
+
+// promise(allocator_arg_t, const Allocator& a);
+
+#define BOOST_THREAD_VERSION 2
+
+#include <boost/thread/future.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/static_assert.hpp>
+
+#if defined BOOST_THREAD_FUTURE_USES_ALLOCATORS
+#include <libs/thread/test/sync/futures/test_allocator.hpp>
+
+int main()
+{
+
+ BOOST_STATIC_ASSERT_MSG((boost::container::uses_allocator<boost::promise<int>, test_allocator<int> >::value), "");
+ BOOST_STATIC_ASSERT_MSG((boost::container::uses_allocator<boost::promise<int&>, test_allocator<int> >::value), "");
+ BOOST_STATIC_ASSERT_MSG((boost::container::uses_allocator<boost::promise<void>, test_allocator<void> >::value), "");
+
+ return boost::report_errors();
+}
+
+#else
+int main()
+{
+ return boost::report_errors();
+}
+#endif
+
+

Added: trunk/libs/thread/test/sync/futures/test_allocator.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/thread/test/sync/futures/test_allocator.hpp 2012-03-31 11:19:22 EDT (Sat, 31 Mar 2012)
@@ -0,0 +1,166 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Copyright (C) 2011 Vicente J. Botet Escriba
+//
+// 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 BOOST_THREAD_TEST_ALLOCATOR_HPP
+#define BOOST_THREAD_TEST_ALLOCATOR_HPP
+
+#include <cstddef>
+#include <boost/type_traits.hpp>
+#include <boost/thread/detail/move.hpp>
+#include <cstdlib>
+#include <new>
+#include <climits>
+
+class test_alloc_base
+{
+public:
+ static int count;
+public:
+ static int throw_after;
+};
+
+int test_alloc_base::count = 0;
+int test_alloc_base::throw_after = INT_MAX;
+
+template <class T>
+class test_allocator
+ : public test_alloc_base
+{
+ int data_;
+
+ template <class U> friend class test_allocator;
+public:
+
+ typedef unsigned size_type;
+ typedef int difference_type;
+ typedef T value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef typename boost::add_lvalue_reference<value_type>::type reference;
+ typedef typename boost::add_lvalue_reference<const value_type>::type const_reference;
+
+ template <class U> struct rebind {typedef test_allocator<U> other;};
+
+ test_allocator() throw() : data_(-1) {}
+ explicit test_allocator(int i) throw() : data_(i) {}
+ test_allocator(const test_allocator& a) throw()
+ : data_(a.data_) {}
+ template <class U> test_allocator(const test_allocator<U>& a) throw()
+ : data_(a.data_) {}
+ ~test_allocator() throw() {data_ = 0;}
+ pointer address(reference x) const {return &x;}
+ const_pointer address(const_reference x) const {return &x;}
+ pointer allocate(size_type n, const void* = 0)
+ {
+ if (count >= throw_after)
+ throw std::bad_alloc();
+ ++count;
+ return (pointer)std::malloc(n * sizeof(T));
+ }
+ void deallocate(pointer p, size_type n)
+ {--count; std::free(p);}
+ size_type max_size() const throw()
+ {return UINT_MAX / sizeof(T);}
+ void construct(pointer p, const T& val)
+ {::new(p) T(val);}
+
+#ifndef BOOST_NO_RVALUE_REFERENCES
+ void construct(pointer p, T&& val)
+ {::new(p) T(boost::move(val));}
+#elif defined BOOST_THREAD_USES_MOVE
+ void construct(pointer p, ::boost::rv<T>& val)
+ {::new(p) T(boost::move(val));}
+#else
+ void construct(pointer p, ::boost::detail::thread_move_t<T> val)
+ {::new(p) T(boost::move(val));}
+#endif // BOOST_NO_RVALUE_REFERENCES
+
+ void destroy(pointer p) {p->~T();}
+
+ friend bool operator==(const test_allocator& x, const test_allocator& y)
+ {return x.data_ == y.data_;}
+ friend bool operator!=(const test_allocator& x, const test_allocator& y)
+ {return !(x == y);}
+};
+
+template <>
+class test_allocator<void>
+ : public test_alloc_base
+{
+ int data_;
+
+ template <class U> friend class test_allocator;
+public:
+
+ typedef unsigned size_type;
+ typedef int difference_type;
+ typedef void value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+
+ template <class U> struct rebind {typedef test_allocator<U> other;};
+
+ test_allocator() throw() : data_(-1) {}
+ explicit test_allocator(int i) throw() : data_(i) {}
+ test_allocator(const test_allocator& a) throw()
+ : data_(a.data_) {}
+ template <class U> test_allocator(const test_allocator<U>& a) throw()
+ : data_(a.data_) {}
+ ~test_allocator() throw() {data_ = 0;}
+
+ friend bool operator==(const test_allocator& x, const test_allocator& y)
+ {return x.data_ == y.data_;}
+ friend bool operator!=(const test_allocator& x, const test_allocator& y)
+ {return !(x == y);}
+};
+
+template <class T>
+class other_allocator
+{
+ int data_;
+
+ template <class U> friend class other_allocator;
+
+public:
+ typedef T value_type;
+
+ other_allocator() : data_(-1) {}
+ explicit other_allocator(int i) : data_(i) {}
+ template <class U> other_allocator(const other_allocator<U>& a)
+ : data_(a.data_) {}
+ T* allocate(std::size_t n)
+ {return (T*)std::malloc(n * sizeof(T));}
+ void deallocate(T* p, std::size_t n)
+ {std::free(p);}
+
+ other_allocator select_on_container_copy_construction() const
+ {return other_allocator(-2);}
+
+ friend bool operator==(const other_allocator& x, const other_allocator& y)
+ {return x.data_ == y.data_;}
+ friend bool operator!=(const other_allocator& x, const other_allocator& y)
+ {return !(x == y);}
+
+ typedef boost::true_type propagate_on_container_copy_assignment;
+ typedef boost::true_type propagate_on_container_move_assignment;
+ typedef boost::true_type propagate_on_container_swap;
+
+#ifdef BOOST_NO_SFINAE_EXPR
+ std::size_t max_size() const
+ {return UINT_MAX / sizeof(T);}
+#endif // BOOST_NO_SFINAE_EXPR
+
+};
+
+#endif // BOOST_THREAD_TEST_ALLOCATOR_HPP


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