为什么C ++中没有针对所有C ++标准库类型特征的语言支持? [英] Why is there no language support in C++ for all C++ standard library type traits?

查看:84
本文介绍了为什么C ++中没有针对所有C ++标准库类型特征的语言支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,无法实现某些C ++标准库类型特征,不带编译器内部函数,仅使用C ++语言。特性直接处理C ++类型。根据§17.6.1.3.2,C ++标准库的独立实现必须实现< type_traits> 。这不是有效地意味着C ++标准需要所有支持想要支持独立C ++标准库实现的编译器的非标准语言扩展/编译器内部函数吗?

In C++ it is impossible to implement certain C++ standard library type traits without compiler intrinsics, using the C++ language only. Traits deal directly with C++ types. According to §17.6.1.3.2 freestanding implementations of the C++ standard library must implement <type_traits>. Doesn't this effectively mean that the C++ standard requires non-standard language extensions/compiler intrinsics from all compilers which support want to support freestanding C++ standard library implementations?

为什么在核心语言不支持的情况下将此类类型特征允许进入标准?

推荐答案

有很多方面C ++标准库的 不能在没有编译器支持的情况下实现。例如, type_info 。 独立C ++库实现无法提供这种类型,因为它是基于关键字的表达式的结果: typeid 。唯一可以提供这种东西的人是编译器编写者,因为编译器是必须生成这些对象的人。

There are many aspects of the C++ standard library which cannot be implemented without support from the compiler. For example, type_info. A "freestanding C++ library" implementation can't provide such a type, since it is the result of a keyword-based expression: typeid. The only people who could provide such a thing are compiler writers, since the compiler is the one who has to generate those objects.

标准库。 exception_ptr current_exception initializer_list 等。在C ++标准中,有一个完整的章节

The same is true of many other elements of the standard library. exception_ptr, current_exception(s), initializer_list, etc. There's a whole chapter of this stuff in the C++ standard.

并不是没有编译器支持,也无法实现标准库的所有组件。类型特征仅仅是独立的C ++库无法实现的又一件事。

Not all components of the standard library can be implemented without compiler support. Type traits are simply one more thing which a freestanding C++ library cannot implement. Not in ISO standard C++.

为什么它们不提供实现它们所需的工具?因为那会花费更多时间。请注意,反射甚至还不是一个完整的TS,虽然类型特征已经成为5年的标准了。

As for why they didn't provide the tools needed to implement them? Because that would have taken more time. Note that reflection isn't even a fully-formed TS yet, while type-traits have been standard for 5 years now.

很难指定诸如反射之类的通用工具。确切了解您需要什么行为以及应该如何提供。查看常用用法(如Boost所示)要容易得多,只需使用它们即可。类型特征是反思的低垂果实。

It is difficult to specify general tools like reflection. To know exactly what behavior you need and how it should be provided. It's much easier to look at common usage patterns (as exemplified by Boost) and just use them. Type-traits are the low-hanging fruit of reflection.

这篇关于为什么C ++中没有针对所有C ++标准库类型特征的语言支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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