为什么std :: function :: argument_type已被弃用? [英] Why std::function::argument_type has been deprecated?

查看:496
本文介绍了为什么std :: function :: argument_type已被弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 cppreference 上看到 std :: function :: argument_type 在C ++ 17中已被弃用。其背后的原因是什么?

I've seen on cppreference that std::function::argument_type was deprecated in C++17. What is the reason behind it? And what ISO WG21 paper was proposing that?

推荐答案

相关论文 P0005R4 (这是投票成为标准草案的文件)和

The relevant papers are P0005R4 (which is the paper that was voted into the draft standard) and P0090R0 (which is referenced by P0005R4).

P0090R0的引语:

Quotes from P0090R0:


Q2。 result_type等有什么问题?

Q2. What's wrong with result_type, etc.?

A2。这些C ++ 98/03 / TR1时代类型定义了predtype和完美的
转发。以前,通用代码在适应它们之前必须从
函数对象请求信息。现在,手动传递
信息是不必要的。 decltype取代result_type,
,因为编译器可以简单地报告调用带有特定参数的
函数对象的结果。和完美的
转发取代了argument_type家庭,因为适配器可以
只是取/存储/转发任意参数。

A2. These C++98/03/TR1-era typedefs predated decltype and perfect forwarding. Previously, generic code had to request information from function objects before adapting them. Now, manually communicating that information is unnecessary. decltype supersedes result_type, because the compiler can simply report what the result of calling a function object with specific arguments will be. And perfect forwarding supersedes the argument_type family, since adaptors can simply take/store/forward arbitrary arguments.

事实上,这些typedef更糟糕比无用。他们是
适得其反,因为许多可调用对象缺少它们。函数
指针和成员的指针总是缺少它们。 ptr_fun(),
用这些typedef包装函数指针,最近删除了
(再次参见[1])。最重要的是,lambdas总是缺少
这些typedef,它们是
all中最重要的函数对象。通用lambdas甚至更不兼容。

In fact, these typedefs are worse than useless. They're counterproductive, because many callable objects lack them. Function pointers and pointers to members have always lacked them. ptr_fun(), which wrapped function pointers with these typedefs, was recently removed (see [1] again). Most importantly, lambdas have always lacked these typedefs, and they are the most important function objects of all. Generic lambdas are even more incompatible.

这意味着如果用户尝试使用result_type系列typedef写
的通用代码, 't通用
- 它将无法处理lambdas,通用lambdas,函数指针等。

What this means is that if a user attempts to write generic code by using the result_type family of typedefs, their code won't be generic - it'll fail to handle lambdas, generic lambdas, function pointers, etc.

这些typedef应该被删除,因为他们已经成为积极地
对现代代码有害。

These typedefs should be removed because they've become actively harmful to modern code.

这篇关于为什么std :: function :: argument_type已被弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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