简体   繁体   中英

Why is std::function itself a copy-constructible type?

我发现规范中的tr.func.require部分要求std::function在C ++ 11中可以复制构造,我已经看到了很多解释为什么这意味着用于构造std::function的函子std::function必须是可复制的,但是为什么C ++ 11标准首先使std::function复制,而不是让它成为一个只移动类型?

std::function was implemented before C++11 when move-semantics were not yet available (it stems from boost::function and was part of TR1 ).

My guess is that std::function was specified (and perhaps voted into the standard) before move semantics. And the didn't have time to review all the rest of the standard in light of this. See also this answer about why shared_ptr deleters have to be CopyConstructible .

Also, for compatibility reasons, it sounds unreasonable to all-of-a-sudden make std::function move constructible and remove its copy-constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM