简体   繁体   English

可以在编译时对std :: bind进行类型检查吗?

[英]Can std::bind be type checked at compile time?

Is it possible to statically type check the arguments given to std::bind ? 是否可以静态类型检查给予std::bind的参数? I'm tempted to use it, but it lets me away with almost anything; 我很想使用它,但它让我几乎可以带走任何东西; for example, std::bind(1,2); 例如, std::bind(1,2); is accepted. 被接受了。 Alternatively I could roll my own solution using std::result_of . 或者,我可以使用std::result_of滚动我自己的解决方案。

I'm not yet sure whether or not bind could be made to reliably reject such constructs or not. 我还不确定是否可以bind可靠地拒绝这样的结构。 But if it can, doing so would be an extension. 但如果可以,这样做将是一个扩展。

A Requires clause in the standard is telling the client what he has to do to avoid undefined behavior. 标准中的Requires子句告诉客户端他必须做些什么来避免未定义的行为。 It is not telling the vendor what he has to do to be conforming. 它并没有告诉供应商他必须做些什么来进行整合。 So std::bind(1,2) is undefined behavior. 所以std::bind(1,2)是未定义的行为。 It could do anything. 它可以做任何事情。 Causing a compile time error would be a nice undefined behavior to have, but is not required. 导致编译时错误将是一个很好的未定义行为,但不是必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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