- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
所有报价均来自N3797 .
4/3 [转化]
An expression e can be implicitly converted to a type T if and only if the declaration T t=e; is well-formed, for some invented temporary variable t
这意味着没有表达式可以隐式转换为 void
,如 void t=e
对所有表达式都是非法的 e
.如果 e
则更是如此。是 void
类型的表达式,如 void(3)
.
所以是 void
类型的表达式不能隐式转换为 void
.
这导致我们:
20.9.2/2 要求 [func.require]
Define INVOKE (f, t1, t2, ..., tN, R) as INVOKE (f, t1, t2, ..., tN) implicitly converted to R .
简而言之,INVOKE(f, t1, t2, ..., tN, R)
在 R
时永远无效是 void
,因为没有任何东西(包括 void
)可以隐式转换为 void
.
因此,所有 std::function<void(Args...)>
有特性!*this
因此不能被调用,因为唯一没有 !*this
的构造函数作为后置条件(或不从同类型的另一个 function
复制此类状态)需要 Callable
参数之一。
20.9.11.2/7 类模板功能[func.wrap.func]
Requires: F shall be CopyConstructible . f shall be Callable ( 20.9.11.2 ) for argument types ArgTypes and return type R . The copy constructor and destructor of A shall not throw exceptions.
20.9.11.2/2 类模板功能[func.wrap.func]
A callable object f of type F is Callable for argument types ArgTypes and return type R if the expres- sion INVOKE (f, declval()..., R) , considered as an unevaluated operand (Clause 5 ), is well formed ( 20.9.2 ).
如上所示,没有Callable
std::function<void(Args...)>
的表达式.
如果有这样的 std::function<void(Args...)>
在哪里找到,调用 operator()
将是不正确的:
调用 [func.wrap.func.inv]
Effects: INVOKE (f, std::forward(args)..., R) ( 20.9.2 ), where f is the target ob- ject ( 20.9.1 ) of *this .
作为 INVOKE(f, std::forward<ArgTypes>(args)..., void)
所有论点和 f
格式错误.
这个推理合理吗?
最佳答案
是的,您的分析是正确的;我得出了同样的结论here .
根据 Daniel Kruegler 的说法,本期 should appear on the library defect list subsequent to the next mailing :
A corresponding library issue has already been submitted, but is not yet visible in the issue list.
希望一旦它变得可见,我们也会对是否允许构建 std::function
有一个决定性的答案。签名返回void
传递带有签名返回非 void (Using `std::function<void(...)>` to call non-void function) 的可调用对象。
更新:输入为 LWG 2420 ,已解决,有利于特殊情况 void
返回类型为static_cast
调用函数的结果为void
.这意味着可调用的返回非 void
可以是 std::function<void(...)>
的目标. LWG2420 作为对 C++14 的发布后更正应用;同时,我所知道的所有编译器都有效地将这种行为作为 C++11 模式的扩展。
关于c++ - 在标准下调用 std::function<void(Args...)> 是否非法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25395605/
我最近在读 CSAPP。在 10.9 节中,它说标准 I/O 不应该与 socket 一起使用,原因如下: (1) The restrictions of standard I/O Restricti
似乎是一个足够标准的问题,可以保证解决方案中的标准设计: 假设我想在文件中写入 x+2(或更少)个字符串。 x 字符串构成一个部分的内容,这两个字符串构成该部分的页眉和页脚。要注意的是,如果内容中没有
代码版本管理 在项目中,代码的版本管理非常重要。每个需求版本的代码开发在版本控制里都应该经过以下几个步骤。 在master分支中拉取该需求版本的两个分支,一个feature分支,
我有以下sql查询,我需要获取相应的hibernate条件查询 SELECT COUNT(DISTINCT employee_id) FROM erp_hr_payment WHERE payment
所以我正在编写一些代码,并且最近遇到了实现一些 mixin 的需要。我的问题是,设计混音的正确方法是什么?我将使用下面的示例代码来说明我的确切查询。 class Projectile(Movable,
我的环境变量包含如下双引号: $echo $CONNECT_SASL_JAAS_CONFIG org.apache.kafka.common.security.plain.PlainLoginModu
示例: /** * This function will determine whether or not one string starts with another string. * @pa
有没有办法在 Grails 中做一个不区分大小写的 in 子句? 我有这个: "in"("name", filters.tags) 我希望它忽略大小写。我想我可以做一个 sqlRestriction
我搜索了很长时间,以查找将哪些boost库添加到std库中,但是我只找到了一个新库的完整列表(如此处:http://open-std.org/jtc1/sc22/wg21/docs/library_t
我已经通过使用这个肮脏的黑客解决了我的问题: ' Filter managerial functions ActiveSheet.Range("$A$1:$BW$2211").Auto
因此,我很难理解我需要遵循的标准,以便我的 Java 程序能够嵌入 HTML。我是否只需将我的主类扩展到 Applet 类,或者我还需要做更多的事情吗?另外,在我见过的每个 Applet 示例中,它都
我对在 Hibernate 中使用限制有疑问。 我必须创建条件,设置一些限制,然后选择日期字段最大值的记录: Criteria query = session.createCriteria(Stora
我有标准: ICriteria criteria = Session.CreateCriteria() .SetFetchMode("Entity1", FetchMo
我很难编写条件来选择所有子集合或孙集合为空的实体。我可以将这些作为单独的条件来执行,但我无法将其组合成一个条件。 类结构: public class Component { p
@Entity class A { @ManyToMany private List list; ... } @Entity class B { ... } 我想使用条件(不是 sql 查询)从 A
我的数据库中有以下表结构: Table A: Table B: Table C: _______________
请帮助我: 我有下一张 table : 单位 ID 姓名 用户 ID 姓名 利率 单位 ID 用户 ID 我不明白如何从 SQL 创建正确的条件结构: 代码: SELECT * FROM Unit W
我正在构建一个包含项目的网站,每个项目都有一个页面,例如: website.com/book/123 website.com/film/456 website.com/game/789 每个项目都可以
我需要使用两个属性的组合来过滤结果列表。一个简单的 SQL 语句如下所示: SELECT TOP 10 * FROM Person WHERE FirstName + ' ' + LastName L
我有一个“ super 实体”SuperEntity 和三个扩展父类(super class)的实体 ChildEntity1、...、ChildEntity3。 搜索数据库中的所有实体很容易,即我们
我是一名优秀的程序员,十分优秀!