【问题标题】:In which ISO C++ version were iterators introduced?在哪个 ISO C++ 版本中引入了迭代器?
【发布时间】:2021-04-06 22:54:05
【问题描述】:

当迭代器被引入 ISO C++ 时,我正在寻找一个参考,我可以注意到在这个例子中它们自 C++98 以来就与向量一起使用,但我从www.isocpp.com 页面读到这不是官方的文档,但仅供参考:http://www.cplusplus.com/reference/vector/vector/vector/

// constructing vectors
#include <iostream>
#include <vector>

int main ()
{
  // constructors used in the same order as described above:
  std::vector<int> first;                                // empty vector of ints
  std::vector<int> second (4,100);                       // four ints with value 100
  std::vector<int> third (second.begin(),second.end());  // iterating through second
  std::vector<int> fourth (third);                       // a copy of third

  // the iterator constructor can also be used to construct from arrays:
  int myints[] = {16,2,77,29};
  std::vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );

  std::cout << "The contents of fifth are:";
  for (std::vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';

  return 0;
}

我也想找一个像ISO版本这样的官方文件,但是我不知道该买哪一个,从哪里买。

是否有按版本列出所有功能的页面?我一直在寻找类似的东西,但我只找到了从 C++11 开始的这个文档:https://en.cppreference.com/w/cpp/compiler_support

【问题讨论】:

  • cppreference 往往有非常具体的版本信息,这是一个很好的参考。
  • 如果在isocpp.org 中没有涵盖从何处获取标准修订版的副本,他们真的错过了营销机会。
  • en.cppreference.com/w/cpp/language/history 说:1998 C++98 (ISO/IEC 14882:1998) New features: RTTI (dynamic_cast, typeid), covariant return types, cast operators, mutable, bool, declarations in conditions, template instantiations, member templates, export Library additions: locales, bitset, valarray, auto_ptr, templatized string, iostream, and complex. Based on STL: containers, algorithms, iterators, function objects
  • 大表回C++03 向下滚动到成员函数表 en.cppreference.com/w/cpp/container
  • 感谢您的评论@tadman,我已经检查了 cppreference,它查找了迭代器和向量,它提到了 C++11 中何时引入了一些特性,但它并没有说它们是可用的C ++ 98,我假设他们这样做,因为它没有指定任何不同。最后,如果有官方文档或参考资料就好了。谢谢!

标签: c++


【解决方案1】:

迭代器一直追溯到 ISO/IEC 14882:1998 (C++98)。使用来自herelink to the C++98 draft,可以看到其中包含第24 章迭代器库1,其中详细说明了迭代器要求,std::iterator_traitsstd::iterator。 p>

1:标准第509页,PDF第535页

【讨论】:

    【解决方案2】:

    在许多其他版本的信息中,https://en.cppreference.com/w/cpp/language/history 说:

    1998 C++98 (ISO/IEC 14882:1998)

    1. 新功能:RTTI(dynamic_cast、typeid)、协变返回类型、强制转换运算符、可变、布尔、条件声明、模板实例化、成员模板、导出
    2. 库添加:语言环境、位集、valarray、auto_ptr、模板化字符串、iostream 和复杂。
    3. 基于 STL:容器、算法、迭代器、函数对象

    因此,迭代器在 1992 年创建的 STL 中,并在 1998 年被标准化。

    【讨论】:

      猜你喜欢
      • 2021-09-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多