Ticket #6174: detail_thread.hpp.diff

File detail_thread.hpp.diff, 3.3 KB (added by viboes, 11 years ago)

Use of forward to try to solve the issue

  • detail/thread.hpp

     
    2525#include <boost/utility/enable_if.hpp>
    2626#include <boost/type_traits/remove_reference.hpp>
    2727#include <boost/io/ios_state.hpp>
     28#include <boost/type_traits/is_same.hpp>
     29#include <boost/type_traits/decay.hpp>
    2830
    2931#include <boost/config/abi_prefix.hpp>
    3032
     
    3739{
    3840    namespace detail
    3941    {
     42
     43#ifndef BOOST_NO_RVALUE_REFERENCES
     44
     45      template <typename F>
     46      F&& forward(typename boost::remove_reference<F>::type& f)
     47      {
     48        return static_cast<F&&>(f);
     49      }
     50      template <typename F>
     51      F&& forward(typename boost::remove_reference<F>::type&& f)
     52      {
     53        return static_cast<F&&>(f);
     54      }
     55
     56      template <class T>
     57      typename decay<T>::type
     58      decay_copy(T&& t)
     59      {
     60          return forward<T>(t);
     61      }
     62
     63#endif
     64
     65
     66
     67
     68
    4069        template<typename F>
    4170        class thread_data:
    4271            public detail::thread_data_base
     
    4473        public:
    4574#ifndef BOOST_NO_RVALUE_REFERENCES
    4675            thread_data(F&& f_):
    47                 f(static_cast<F&&>(f_))
     76              //f(static_cast<F&&>(f_))
     77              f(detail::forward<F>(f_))
    4878            {}
    49             thread_data(F& f_):
    50                 f(f_)
    51             {}
     79// This overloading must be removed if we want the packaged_task's tests to pass.
     80//            thread_data(F& f_):
     81//                f(f_)
     82//            {}
    5283#else
    5384            thread_data(F f_):
    5485                f(f_)
     
    128159        template<typename F>
    129160        static inline detail::thread_data_ptr make_thread_info(F&& f)
    130161        {
    131             return detail::thread_data_ptr(detail::heap_new<detail::thread_data<typename boost::remove_reference<F>::type> >(static_cast<F&&>(f)));
     162          //return detail::thread_data_ptr(detail::heap_new<detail::thread_data<typename boost::remove_reference<F>::type> >(static_cast<F&&>(f)));
     163            return detail::thread_data_ptr(detail::heap_new<detail::thread_data<typename boost::remove_reference<F>::type> >(
     164                detail::forward<F>(f)));
    132165        }
    133166        static inline detail::thread_data_ptr make_thread_info(void (*f)())
    134167        {
    135             return detail::thread_data_ptr(detail::heap_new<detail::thread_data<void(*)()> >(static_cast<void(*&&)()>(f)));
     168            //return detail::thread_data_ptr(detail::heap_new<detail::thread_data<void(*)()> >(static_cast<void(*&&)()>(f)));
     169            return detail::thread_data_ptr(detail::heap_new<detail::thread_data<void(*)()> >(
     170                detail::forward<void(*)()>(f)));
    136171        }
    137172#else
    138173        template<typename F>
     
    164199            start_thread();
    165200        }
    166201#else
    167         template <class F>
    168         thread(F&& f):
    169             thread_info(make_thread_info(static_cast<F&&>(f)))
     202        template <
     203          class F,
     204          class Dummy = typename disable_if< is_same<typename decay<F>::type, thread> >::type
     205        >
     206        explicit thread(F&& f):
     207          //thread_info(make_thread_info(static_cast<F&&>(f)))
     208          thread_info(make_thread_info(detail::decay_copy(detail::forward<F>(f))))
    170209        {
    171210            start_thread();
    172211        }