rigtorp / MPMCQueue

A bounded multi-producer multi-consumer concurrent queue written in C++11
MIT License
1.15k stars 159 forks source link

Why T can not be std::function<void()>? #22

Closed valaxkong closed 4 years ago

valaxkong commented 4 years ago

My Compiler is gcc 5.4. The static_assert is raised when compile this code : MPMCQueue<std::function<void()>> What did this happen? For my knowledge, std::function is no-throw move assignment, so it should not trigger the static_assert in your code.

rigtorp commented 4 years ago

std::function is not noexcept assignable: https://en.cppreference.com/w/cpp/utility/functional/function/operator%3D

You can make a custom one that is nonexcept movable. The functors destructor would have to be noexcept.

On Sun, May 10, 2020 at 8:21 AM valaxkong notifications@github.com wrote:

My Compiler is gcc 5.4. The static_assert is raised when compile this code : MPMCQueue<std::function<void()>> What did this happen? For my knowledge, std::function is no-throw move assignment, so it should not trigger the static_assert in your code.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rigtorp/MPMCQueue/issues/22, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABLO2Y74UWK2YHCMSGKSZ3RQ3A6XANCNFSM4M5JDYAQ .