Index: detail/thread.hpp =================================================================== --- detail/thread.hpp (revision 76011) +++ detail/thread.hpp (working copy) @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include @@ -37,6 +39,33 @@ { namespace detail { + +#ifndef BOOST_NO_RVALUE_REFERENCES + + template + F&& forward(typename boost::remove_reference::type& f) + { + return static_cast(f); + } + template + F&& forward(typename boost::remove_reference::type&& f) + { + return static_cast(f); + } + + template + typename decay::type + decay_copy(T&& t) + { + return forward(t); + } + +#endif + + + + + template class thread_data: public detail::thread_data_base @@ -44,11 +73,13 @@ public: #ifndef BOOST_NO_RVALUE_REFERENCES thread_data(F&& f_): - f(static_cast(f_)) + //f(static_cast(f_)) + f(detail::forward(f_)) {} - thread_data(F& f_): - f(f_) - {} +// This overloading must be removed if we want the packaged_task's tests to pass. +// thread_data(F& f_): +// f(f_) +// {} #else thread_data(F f_): f(f_) @@ -128,11 +159,15 @@ template static inline detail::thread_data_ptr make_thread_info(F&& f) { - return detail::thread_data_ptr(detail::heap_new::type> >(static_cast(f))); + //return detail::thread_data_ptr(detail::heap_new::type> >(static_cast(f))); + return detail::thread_data_ptr(detail::heap_new::type> >( + detail::forward(f))); } static inline detail::thread_data_ptr make_thread_info(void (*f)()) { - return detail::thread_data_ptr(detail::heap_new >(static_cast(f))); + //return detail::thread_data_ptr(detail::heap_new >(static_cast(f))); + return detail::thread_data_ptr(detail::heap_new >( + detail::forward(f))); } #else template @@ -164,9 +199,13 @@ start_thread(); } #else - template - thread(F&& f): - thread_info(make_thread_info(static_cast(f))) + template < + class F, + class Dummy = typename disable_if< is_same::type, thread> >::type + > + explicit thread(F&& f): + //thread_info(make_thread_info(static_cast(f))) + thread_info(make_thread_info(detail::decay_copy(detail::forward(f)))) { start_thread(); }