是否有“魔法”在STL? [英] Is there "magic" in the STL?

查看:182
本文介绍了是否有“魔法”在STL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我从解释我的意思是魔法开始。我将使用Java中的两个例子:

Let me start with explaining what I mean with "magic". I will use two examples from Java:


  1. 每个类都直接或间接地继承 Object class。

  2. Java不支持运算符重载,但 String定义 + 对象。

  1. Every class inherits (directly or indirectly) the Object class.
  2. Operator overloading is not supported by Java but the + operator is defined for String objects.

这意味着不可能实现在纯(*)Java中的对象 String 类。现在这就是我的意思与魔术:要实现这些类,你将需要一些特殊的支持从编译器。

This means that it is impossible to make an implementation of the Object and String classes in pure(*) Java. Now this is what I mean with "magic": to make an implementation of these classes, you will need some special support from the compiler.

我一直喜欢C ++就是说,就我所知,STL中没有这样的魔术,即可以在纯C ++中实现STL。

What I always liked about C++ is that, as far as I know, there is no such "magic" going on in the STL, i.e. it is possible to implement the STL in pure C++.

现在我的问题是:这是真的吗?或者是STL的某些部分不能在纯C ++中实现,需要一些魔术/特殊的编译器支持?

Now my question is: is this true? Or are there parts of the STL that cannot be implemented in pure C++ and need some "magic"/special compiler support?

(*)对于pure,我的意思是没有使用任何类库。

(*) With "pure" I mean without using any class libraries.

推荐答案

换句话说,编译器允许STL需要工作的特殊情况?

in other words, has anything been done to the compiler to allow for a 'special case' the STL needed to work?

否。

所有实现为纯粹的C ++代码,使用模板的魔力。

It was all implemented as 'pure' C++ code, using the magic of templates.

我已经做了一些工作来改善STL(我正在考虑各种优化),否则,不,你可以写整个STL,如果你真的通缉。有些人没有 - STLPort 是没有任何编译器制造商支持的实施。

There has been some work done to compilers to improve the STL (I'm thinking about various optimisations) but otherwise, no, you could write the entire STL if you really wanted. Some people did - STLPort is an implementation that didn't have the backing of any compiler manufacturer.

这篇关于是否有“魔法”在STL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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