为什么`std :: invoke`不是constexpr? [英] Why is `std::invoke` not constexpr?

查看:96
本文介绍了为什么`std :: invoke`不是constexpr?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不应 std :: invoke constexpr ,尤其是在C ++ 17中 constexpr lambdas

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

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

Are there any obstacles that will prevent this?

推荐答案

更新: P1065 将其设置为 constexpr

出于历史原因保留原始帖子:

来自提案


尽管有可能将符合标准的调用函数模板实现为constexpr函数,建议的措辞不需要这种实现。主要原因是使它与可能具有这样的定义的现有标准函数对象保持一致,例如std :: mem_fn,std :: reference_wrapper和运算符包装器。进一步强加这样的要求将阻止引用std :: mem_fn的调用的实现。

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.

该提议假定将constexpr添加到标头中将由一个单独的提议一致地应用。

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

基于constexpr和基于标准库的实现都在提案的可实现性部分中给出。

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




相关的CWG问题#1581:> 何时 constexpr 成员函数已定义?

这篇关于为什么`std :: invoke`不是constexpr?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆