C++ Logo


Advanced search

Re: Iterators of the class template std::array

From: chuanqi.xcq <yedeng.yd_at_[hidden]>
Date: Sun, 26 Sep 2021 19:52:39 +0800

It looks like that the bahavior is not defined in the spec: https://eel.is/c++draft/array#overview-5
namespace std {
  template<class T, size_t N>
  struct array {
// ...
using iterator = implementation-defined;
 using const_iterator = implementation-defined;
// ...

From:Vladimir Grigoriev via Std-Discussion <std-discussion_at_[hidden]>
Send Time:2021年9月26日(星期日) 19:27
To:std-discussion <std-discussion_at_[hidden]>
Cc:Vladimir Grigoriev <vlad.moscow_at_[hidden]>
Subject:[std-discussion] Iterators of the class template std::array

I have run the program below using gcc 8.3 and its output is true.
#include <iostream>
#include <array>
#include <type_traits>
int main()
    std::cout << std::is_same<std::array<int, 2>::iterator, std::array<int, 5>::iterator>::value
              << '\n';

    return 0;
Though if I am not mistaken there is nothing said in the Standard whether iterators of two instantiations of the class template std::array std::array<T, N1> and std::array <T, N2> have the same types of iterators.
It would be useful if there was adopted in the Standard that iterators of two instantiations std::array<T, N1> and std::array<T, N2> had the same types of iterators.. In this case we could use lists of iterators for instantiations of std::array that have the same type of the first template parameter.
With best regards,
(Vlad from Moscow)
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com

Received on 2021-09-26 06:52:44