c++ - 为什么 `std::invoke` 不是 constexpr?

标签 c++ std invoke constexpr c++17

不应该std::invoke成为 constexpr 尤其是在 constexpr lambdas in C++17 之后?

是否有任何障碍可以阻止这种情况发生?

最佳答案

更新: P1065将使它成为 constexpr


由于历史原因保留原帖:

来自 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.


相关 CWG 问题 #1581:When are constexpr member functions defined? .

关于c++ - 为什么 `std::invoke` 不是 constexpr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40222989/

相关文章:

c++ - OS X 上的链接器错误 "ld: framework not found SFML"

c++ - std vector 迭代器不支持地址运算?

VB.NET 委托(delegate)和调用 - 有人可以向我解释这些吗?

C++如何知道对象何时被销毁

c++ - 定义不评估 POD?

c++ - 大小为 1 的 char 数组和 strcat 的问题

c++ - std::map<whatever,double> 是否自动将值归零?

c++ - 将对象序列化为加密的 std::fstream (C++)

C# 使用预先创建的对象调用 Powershell

C# 自定义 Invoke 方法调用各种其他方法