新的迭代器要求 [英] New iterator requirements

查看:57
本文介绍了新的迭代器要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,大多数(如果不是全部)容器现在都需要其 :: iterator 类型来满足 LegacySomethingIterator 而不是 SomethingIterator .

I noticed that most if not all containers now require their ::iterator type to satisfy LegacySomethingIterator instead of SomethingIterator.

例如, std :: vector<> :: iterator

迭代器 LegacyRandomAccessIterator

对于大多数其他容器,这似乎是相同的,所有这些容器都要求其迭代器从 SomethingIterator LegacySomethingIterator .

This seems to be the same for most of the other containers, all requiring their iterators to go from SomethingIterator to LegacySomethingIterator.

也有采用旧要求名称的新"要求,例如 RandomAccessIterator ,为什么要添加这些内容?在我看来,新的变体只不过是传统变体的影子,没有区别.

There are also the "new" requirements that took the names of the old requirements, such as RandomAccessIterator, why were these added? It seems to me that the new variants just shadow the legacy variants, no differences.

为什么首先要创建新的,对我来说它们的要求是相同的.为什么新的不只是替换旧的要求,而不是立即为它们提供两个不同的名称(例如 RandomAccessIterator LegacyRandomAccessIterator )?

Why were new ones created in the first place, their requirements look the same to me. Why don't the new ones just replace the old requirements instead of right now having 2 different names for them (e.g. RandomAccessIterator and LegacyRandomAccessIterator)?

推荐答案

这些不是新事物,因此称为旧版".这就是cppreference站点选择调解C ++ 20将具有两个不同的东西的事实,它们都是概念",称为"RandomAccessIterator"(嗯,直到C ++ 20决定重命名其版本 random_access_iterator ).

These are not new things, hence the term "legacy". This is simply how the cppreference site chooses to reconcile the fact that C++20 will have two different things that are both "concepts" called "RandomAccessIterator" (well, until C++20 decided to rename their version random_access_iterator).

Pre-C ++ 20中,概念"只是标准中的一组要求,代表了某些模板参数的预期行为.在C ++ 20中,由于概念已成为实际的语言功能,因此需要转变.问题在于" RandomAccessIterator "的范围 concept 与"RandomAccessIterator"的旧式"concept" 不相同.

Pre-C++20, a "concept" was just a set of requirements in the standard that represented the behavior expected of certain template parameters. In C++20, with concepts becoming an actual language feature, that needed to shift. The problem is that the Ranges concept of "RandomAccessIterator" is not the same as the old-style "concept" of "RandomAccessIterator".

由于C ++认为它们都是概念"(尽管只有较新的语言是 concept 在语言意义上),因此它们在Wiki上都具有相同的页面名称.而且MediaWiki真的不允许这样做.

Since C++ considers them both to be "concepts" (though only the newer one is a concept in the language sense), they would both have the same page name on the Wiki. And MediaWiki doesn't really allow that.

因此,该站点的维护者决定使用旧版"来区分它们.请注意,实际的 standard 并不使用此旧版"前缀.

So the maintainers of the site settled on using "Legacy" to differentiate them. Note that the actual standard doesn't use this "Legacy" prefix.

请注意,C ++ 20标准确实为较早的概念提供了前缀:"Cpp17".因此,旧概念将是"Cpp17RandomAccessIterator".出于明显的原因,这不适合Cppreference使用.

Note that the C++20 standard does have a prefix for the older concepts: "Cpp17". So the old concept would be "Cpp17RandomAccessIterator". That was not deemed appropriate for Cppreference for obvious reasons.

这篇关于新的迭代器要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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