dimanche 28 avril 2019

Compilation error while passing queue of packaged_tasks as reference

Having a compilation error when I am trying to pass a queue containing packaged_task objects to a thread as a reference. I modified sample code to pass it to a function and the same compilation error observed

void runtasks(std::queue< packaged_task<int()> >& que)
{
    while(!que.empty())
    {
        auto task = std::move(que.front());
        que.pop();
        task();
    }
}

int main()
{
    std::queue< packaged_task<int()> > que;
    packaged_task<int()> t1(std::bind(factorial,1));
    packaged_task<int()> t2(std::bind(factorial,4));
    que.push(std::move(t1));
    que.push(std::move(t2));
    runtasks(que);
    return 1;
}

/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_construct.h: In instantiation of 'void std::_Construct(_T1*, _Args&& ...) [with _T1 = std::packaged_task; _Args = {const std::packaged_task&}]': /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_uninitialized.h:75:18: required from 'static _ForwardIterator std::__uninitialized_copy<_TrivialValueTypes>::__uninit_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::_Deque_iterator, const std::packaged_task&, const std::packaged_task*>; _ForwardIterator = std::_Deque_iterator, std::packaged_task&, std::packaged_task*>; bool _TrivialValueTypes = false]' /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_uninitialized.h:126:15: required from '_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::_Deque_iterator, const std::packaged_task&, const std::packaged_task*>; _ForwardIterator = std::_Deque_iterator, std::packaged_task&, std::packaged_task*>]' /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_uninitialized.h:281:37: required from '_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = std::_Deque_iterator, const std::packaged_task&, const std::packaged_task*>; _ForwardIterator = std::_Deque_iterator, std::packaged_task&, std::packaged_task*>; _Tp = std::packaged_task]' /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_deque.h:944:36: required from 'std::deque<_Tp, _Alloc>::deque(const std::deque<_Tp, _Alloc>&) [with _Tp = std::packaged_task; _Alloc = std::allocator >]' /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_queue.h:96:11: required from here /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/stl_construct.h:75:7: error: use of deleted function 'std::packaged_task<_Res(_ArgTypes ...)>::packaged_task(const std::packaged_task<_Res(_ArgTypes ...)>&) [with _Res = int; _ArgTypes = {}]' { ::new(static_cast(__p)) _T1(std::forward<_Args>(__args)...); } ^ In file included from ../src/SmartPointers.cpp:16:0: /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/future:1507:7: note: declared here packaged_task(const packaged_task&) = delete; ^ make: *** [src/subdir.mk:23: src/SmartPointers.o] Error 1

Aucun commentaire:

Enregistrer un commentaire