Why is `std::invoke` not constexpr?

只愿长相守 提交于 2019-12-12 10:34:23

问题


Shouldn't std::invoke be constexpr especially after constexpr lambdas in C++17?

Are there any obstacles that will prevent this?


回答1:


Update: P1065 will make it constexpr.


Keep original post for historical reason:

From the proposal:

Although there is possibility to implement standard conforming invoke function template as a constexpr function, the proposed wording does not require such implementation. The main reason is to left it consistent with existing standard function objects, that could have such definition, like std::mem_fn, std::reference_wrapper and operator wrappers. Furthermore imposing such requirement will block the implementation of invoke that refers to std::mem_fn.

This proposal assumes that constexpr addition to the header would be applied consistently by a separate proposal.

Both constexpr and standard library based implementation are presented in Implementability section of the proposal.


Related CWG issue #1581: When are constexpr member functions defined?.



来源:https://stackoverflow.com/questions/40222989/why-is-stdinvoke-not-constexpr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!