0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

25.4 Iterator primitives [iterator.primitives]C++N4910:2022 (646) p995.cpp

Posted at

はじめに(Introduction)

N4910 Working Draft, Standard for Programming Language C++

n4910は、ISO/IEC JTC1 SC22 WG21の作業原案(Working Draft)です。
公式のISO/IEC 14882原本ではありません。
ISO/IEC JTC1 SC22 WG21では、可能な限り作業文書を公開し、幅広い意見を求めています。
一連の記事はコード断片をコンパイルできる形にする方法を検討してコンパイル、リンク、実行して、規格案の原文と処理系(g++, Clang++)との違いを確認し、技術内容を検討し、ISO/IEC JTC1 SC22 WG21にフィードバックするために用います。
また、CERT C++, MISRA C++等のコーディング標準のコード断片をコンパイルする際の参考にさせていただこうと考えています。CERT C++, MISRA C++が標準化の動きとの時間的なずれがあれば確認できれば幸いです。また、boostライブラリとの関連、Linux OS, TOPPERSカーネル、g++(GCC), clang++(LLVM)との関係も調査中です。
何か、抜け漏れ、耳より情報がありましたらおしらせくださると幸いです。

<この項は書きかけです。順次追記します。>

背景(back ground)

C/C++でコンパイルエラーが出ると、途方にくれることがしばしばあります。
何回かに1回は、該当するエラーが検索できます。
ただ、条件が違っていて、そこでの修正方法では目的を達成しないこともしばしばです。いろいろな条件のコンパイルエラーとその対応方法について、広く記録することによって、いつか同じエラーに遭遇した時にやくに立つことを目指しています。

この半年の間で、三度、自分のネットでの記録に助けられたことがあります。
また過去に解決できなかった記録を10種類以上、最近になって解決できたことがあります。それは、主に次の3つの情報に基づいています。

cpprefjp - C++日本語リファレンス

コンパイラの実装状況

また
https://researchmap.jp/joub9b3my-1797580/#_1797580
に記載したサイトのお世話になっています。

作業方針(sequence)

Clang++では-std=c++03, C++2bの2種類
g++では-std=c++03, c++2bの2種類
でコンパイルし、

1)コンパイルエラーを収集する。
2)コンパイルエラーをなくす方法を検討する。
コンパイルエラーになる例を示すだけが目的のコードは、コンパイルエラーをなくすのではなく、コンパイルエラーの種類を収集するだけにする。
文法を示すのが目的のコード場合に、コンパイルエラーをなくすのに手間がかかる場合は、順次作業します。
3)リンクエラーをなくす方法を検討する。
文法を示すのが目的のコード場合に、リンクエラーをなくすのに手間がかかる場合は、順次作業します。
4)意味のある出力を作る。
コンパイル、リンクが通っても、意味のある出力を示そうとすると、コンパイル・リンクエラーが出て収拾できそうにない場合がある。順次作業します。

1)だけのものから4)まで進んだものと色々ある状態です。一歩でも前に進むご助言をお待ちしています。「検討事項」の欄に現状を記録するようにしています。

C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list

C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list

C++N4606, 2016符号断片編纂一覧(example code compile list)

C++N4606, 2016 Working Draft 2016, ISO/IEC 14882, C++ standard(1) Example code compile list
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/

C++N3242, 2011 sample code compile list on clang++ and g++

編纂器(Compiler)

clang++ --version

Debian clang version 14.0.5-++20220610033153+c12386ae247c-1~exp1~20220610153237.151
Target: x86_64-pc-linux-gnu, Thread model: posix, InstalledDir: /usr/bin

g++- --version

g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

25.4 Iterator primitives [iterator.primitives]C++N4910:2022 (646) p995.cpp

算譜(source code)

p995.cpp
// C++N4910 Committee Draft, Standard for Programming Language C++
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf
const char * n4910 = "25.4 Iterator primitives  [iterator.primitives]C++N4910:2022 (646) p995.cpp";
// Debian clang version 14.0.5-++20220610033153+c12386ae247c-
// g++ (GCC) 12.1.0 Copyright (C) 2022 Free Software Foundation, Inc.
// Edited by Dr. OGAWA Kiyoshi. Compile procedure and results record.
// C++N4910:2022 Standard Working Draft on ISO/IEC 14882(0) sample code compile list
// https://qiita.com/kaizen_nagoya/items/fc957ddddd402004bb91

#include "N4910.h"

using namespace std;

// 25.4.1 General [iterator.primitives.general]
// To simplify the use of iterators, the library provides several classes and functions.
// 25.4.2 Standard iterator tags [std.iterator.tags]
//  It is often desirable for a function template specialization to find out what is the most specific cate- gory of its iterator argument, so that the function can select the most efficient algorithm at compile time. To facilitate this, the library introduces category tag classes which are used as compile time tags for algorithm selection. They are: output_iterator_tag, input_iterator_tag, forward_iterator_tag, bidirectional_iterator_tag, random_access_iterator_tag, and contiguous_iterator_tag. For every iterator of type I, iterator_traits<I>::iterator_category shall be defined to be a category tag that describes the iterator’s behavior. Additionally, iterator_traits<I>::iterator_concept may be used to indicate conformance to the iterator concepts (25.3.4).
namespace std {
struct output_iterator_tag { };
struct input_iterator_tag { };
struct forward_iterator_tag: public input_iterator_tag { };
struct bidirectional_iterator_tag: public forward_iterator_tag { };
struct random_access_iterator_tag: public bidirectional_iterator_tag { };
struct contiguous_iterator_tag: public random_access_iterator_tag { };
}
//  [Example 1: A program-defined iterator BinaryTreeIterator can be included into the bidirectional iterator category
by specializing the iterator_traits template:
template<class T> struct iterator_traits<BinaryTreeIterator<T>> {
    using iterator_category = bidirectional_iterator_tag;
    using difference_type = ptrdiff_t;
    using value_type = T;
    using pointer = T*;
    using reference = T&;
};
// [Example 2: If evolve() is well-defined for bidirectional iterators, but can be implemented more efficiently for random
access iterators, then the implementation is as follows:
template<class BidirectionalIterator>
inline void
evolve(BidirectionalIterator first, BidirectionalIterator last) {
    evolve(first, last,
           typename iterator_traits<BidirectionalIterator>::iterator_category());
}
template<class BidirectionalIterator>
void evolve(BidirectionalIterator first, BidirectionalIterator last,
            bidirectional_iterator_tag) {
// more generic, but less efficient algorithm
}
template<class RandomAccessIterator>
void evolve(RandomAccessIterator first, RandomAccessIterator last,
            random_access_iterator_tag) {
// more efficient, but less generic algorithm
}
// 25.4.3 Iterator operations [iterator.operations]
//  Since only random access iterators provide + and - operators, the library provides two function templates advance and distance. These function templates use + and - for random access iterators (and are, therefore, constant time for them); for input, forward and bidirectional iterators they use ++ to provide linear time implementations.
constexpr void ranges::advance(I& i, iter_difference_t<I> n);
// Preconditions: If I does not model bidirectional_iterator, n is not negative. Effects:
// - If I models random_access_iterator, equivalent to i += n.
// — Otherwise, if n is non-negative, increments i by n.
// — Otherwise, decrements i by -n.
template<class InputIterator, class Distance>
constexpr void advance(InputIterator& i, Distance n);
// The library includes the function templates ranges::advance, ranges::distance, ranges::next, and ranges::prev to manipulate iterators. These operations adapt to the set of operators provided by each iterator category to provide the most efficient implementation possible for a concrete iterator type.
// [Example 1: ranges::advance uses the + operator to move a random_access_iterator forward n steps in constant time. For an iterator type that does not model random_access_iterator, ranges::advance instead performs n individual increments with the ++ operator.
//  The function templates defined in 25.4.4 are not found by argument-dependent name lookup (6.5.4). When found by unqualified (6.5.3) name lookup for the postfix-expression in a function call (7.6.1.3), they inhibit argument-dependent name lookup.
// Preconditions: n is negative only for bidirectional iterators.
// Effects: Increments i by n if n is non-negative, and decrements i by -n otherwise.
template<class InputIterator>
constexpr typename iterator_traits<InputIterator>::difference_type
distance(InputIterator first, InputIterator last);
// Preconditions: last is reachable from first, or InputIterator meets the Cpp17RandomAccessIterator requirements and first is reachable from last.
// Effects: If InputIterator meets the Cpp17RandomAccessIterator requirements, returns (last - first); otherwise, increments first until last is reached and returns the number of increments.
template<class InputIterator>
constexpr InputIterator next(InputIterator x,
                             typename iterator_traits<InputIterator>::difference_type n = 1);
// Effects: Equivalent to: advance(x, n); return x;
template<class BidirectionalIterator>
constexpr BidirectionalIterator prev(BidirectionalIterator x,
                                     typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
// Effects: Equivalent to: advance(x, -n); return x;
// 25.4.4 Range iterator operations [range.iter.ops]
// 25.4.4.1 General [range.iter.ops.general]
// [Example 2:
void foo() {
    using namespace std::ranges;
    std::vector<int> vec{1,2,3};
    distance(begin(vec), end(vec));
}
// #1
// The function call expression at #1 invokes std::ranges::distance, not std::distance, despite that (a) the iterator type returned from begin(vec) and end(vec) may be associated with namespace std and (b) std::distance is more specialized (13.7.7.3) than std::ranges::distance since the former requires its first two parameters to have the same type.
//  The number and order of deducible template parameters for the function templates defined in 25.4.4 is unspecified, except where explicitly stated otherwise.
// 25.4.4.2 ranges::advance [range.iter.op.advance] template<input_or_output_iterator I>
template<input_or_output_iterator I, sentinel_for<I> S>
constexpr void ranges::advance(I& i, S bound);
// Preconditions: Either assignable_from<I&, S> || sized_sentinel_for<S, I> is modeled, or [i, bound) denotes a range.
// Effects: — If I and S model assignable_from<I&, S>, equivalent to i = std::move(bound).
// — Otherwise, if S and I model sized_sentinel_for<S, I>, equivalent to ranges::advance(i, bound - i).
// — Otherwise, while bool(i != bound) is true, increments i. template<input_or_output_iterator I, sentinel_for<I> S>
constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
// Preconditions: If n > 0, [i,bound) denotes a range. If n == 0, [i,bound) or [bound,i) denotes a range. If n < 0, [bound, i) denotes a range, I models bidirectional_iterator, and I and S model same_as<I, S>.
// Effects: — If S and I model sized_sentinel_for<S, I>:
// — If |n| ≥ |bound - i|, equivalent to ranges::advance(i, bound).
// — Otherwise, equivalent to ranges::advance(i, n). — Otherwise,
// — if n is non-negative, while bool(i != bound) is true, increments i but at most n times.
// — Otherwise, while bool(i != bound) is true, decrements i but at most -n times. Returns: n - M, where M is the difference between the ending and starting positions of i.
// 25.4.4.3 ranges::distance [range.iter.op.distance]
template<input_or_output_iterator I, sentinel_for<I> S>
requires (!sized_sentinel_for<S, I>)
constexpr iter_difference_t<I> ranges::distance(I first, S last);
// Preconditions: [first, last) denotes a range.
// Effects: Increments first until last is reached and returns the number of increments.
template<input_or_output_iterator I, sized_sentinel_for<I> S>
constexpr iter_difference_t<I> ranges::distance(const I& first, const S& last);
// Effects: Equivalent to: return last - first; template<range R>
constexpr range_difference_t<R> ranges::distance(R&& r);
// Effects: If R models sized_range, equivalent to:
return static_cast<range_difference_t<R>>(ranges::size(r));
// Otherwise, equivalent to:
return ranges::distance(ranges::begin(r), ranges::end(r));
// 25.4.4.4 ranges::next  [range.iter.op.next]
template<input_or_output_iterator I>
constexpr I ranges::next(I x);
// Effects: Equivalent to: ++x; return x; template<input_or_output_iterator I>
constexpr I ranges::next(I x, iter_difference_t<I> n);
// Effects: Equivalent to: ranges::advance(x, n); return x;
template<input_or_output_iterator I, sentinel_for<I> S>
constexpr I ranges::next(I x, S bound);
// Effects: Equivalent to: ranges::advance(x, bound); return x; template<input_or_output_iterator I, sentinel_for<I> S>
constexpr I ranges::next(I x, iter_difference_t<I> n, S bound);
// Effects: Equivalent to: ranges::advance(x, n, bound); return x;
// 25.4.4.5 ranges::prev [range.iter.op.prev]
template<bidirectional_iterator I>
constexpr I ranges::prev(I x);
// Effects: Equivalent to: --x; return x; template<bidirectional_iterator I>
constexpr I ranges::prev(I x, iter_difference_t<I> n);
// Effects: Equivalent to: ranges::advance(x, -n); return x; template<bidirectional_iterator I>
constexpr I ranges::prev(I x, iter_difference_t<I> n, I bound);
// Effects: Equivalent to: ranges::advance(x, -n, bound); return x;
int main() {
    cout  <<  n4910 << endl;
    return EXIT_SUCCESS;
}

編纂・実行結果(compile and go)

bash
$ clang++ p995.cpp -std=03 -o p995l -I. -Wall
In file included from p995.cpp:10:
In file included from ./N4910.h:11:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/atomic:38:
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/c++0x_warning.h:32:2: error: This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \
 ^
p995.cpp:19:15: error: redefinition of 'output_iterator_tag'
       struct output_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:96:10: note: previous definition is here
  struct output_iterator_tag { };
         ^
p995.cpp:20:15: error: redefinition of 'input_iterator_tag'
       struct input_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:93:10: note: previous definition is here
  struct input_iterator_tag { };
         ^
p995.cpp:21:15: error: redefinition of 'forward_iterator_tag'
       struct forward_iterator_tag: public input_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:99:10: note: previous definition is here
  struct forward_iterator_tag : public input_iterator_tag { };
         ^
p995.cpp:22:15: error: redefinition of 'bidirectional_iterator_tag'
       struct bidirectional_iterator_tag: public forward_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:103:10: note: previous definition is here
  struct bidirectional_iterator_tag : public forward_iterator_tag { };
         ^
p995.cpp:23:15: error: redefinition of 'random_access_iterator_tag'
       struct random_access_iterator_tag: public bidirectional_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:107:10: note: previous definition is here
  struct random_access_iterator_tag : public bidirectional_iterator_tag { };
         ^
p995.cpp:27:1: error: unknown type name 'by'
by specializing the iterator_traits template:
^
p995.cpp:27:16: error: expected ';' after top level declarator
by specializing the iterator_traits template:
               ^
               ;
p995.cpp:36:1: error: unknown type name 'access'
access iterators, then the implementation is as follows:
^
p995.cpp:36:23: error: expected ';' after top level declarator
access iterators, then the implementation is as follows:
                      ^
                      ;
p995.cpp:61:6: error: unknown type name 'constexpr'
     constexpr void advance(InputIterator& i, Distance n);
     ^
p995.cpp:68:3: error: unknown type name 'constexpr'
  constexpr typename iterator_traits<InputIterator>::difference_type
  ^
p995.cpp:73:3: error: unknown type name 'constexpr'
  constexpr InputIterator next(InputIterator x,
  ^
p995.cpp:73:13: warning: variable templates are a C++14 extension [-Wc++14-extensions]
  constexpr InputIterator next(InputIterator x,
            ^
p995.cpp:73:26: error: expected ';' at end of declaration
  constexpr InputIterator next(InputIterator x,
                         ^
                         ;
p995.cpp:73:32: error: unknown type name 'InputIterator'
  constexpr InputIterator next(InputIterator x,
                               ^
p995.cpp:73:27: error: C++ requires a type specifier for all declarations
  constexpr InputIterator next(InputIterator x,
                          ^
p995.cpp:77:3: error: unknown type name 'constexpr'
  constexpr BidirectionalIterator prev(BidirectionalIterator x,
  ^
p995.cpp:77:13: warning: variable templates are a C++14 extension [-Wc++14-extensions]
  constexpr BidirectionalIterator prev(BidirectionalIterator x,
            ^
p995.cpp:77:34: error: expected ';' at end of declaration
  constexpr BidirectionalIterator prev(BidirectionalIterator x,
                                 ^
                                 ;
p995.cpp:77:40: error: unknown type name 'BidirectionalIterator'; did you mean 'bidirectional_iterator_tag'?
  constexpr BidirectionalIterator prev(BidirectionalIterator x,
                                       ^~~~~~~~~~~~~~~~~~~~~
                                       bidirectional_iterator_tag
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:103:10: note: 'bidirectional_iterator_tag' declared here
  struct bidirectional_iterator_tag : public forward_iterator_tag { };
         ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
$ clang++ p995.cpp -std=2b -o p995l -I. -Wall
p995.cpp:19:15: error: redefinition of 'output_iterator_tag'
       struct output_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:96:10: note: previous definition is here
  struct output_iterator_tag { };
         ^
p995.cpp:20:15: error: redefinition of 'input_iterator_tag'
       struct input_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:93:10: note: previous definition is here
  struct input_iterator_tag { };
         ^
p995.cpp:21:15: error: redefinition of 'forward_iterator_tag'
       struct forward_iterator_tag: public input_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:99:10: note: previous definition is here
  struct forward_iterator_tag : public input_iterator_tag { };
         ^
p995.cpp:22:15: error: redefinition of 'bidirectional_iterator_tag'
       struct bidirectional_iterator_tag: public forward_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:103:10: note: previous definition is here
  struct bidirectional_iterator_tag : public forward_iterator_tag { };
         ^
p995.cpp:23:15: error: redefinition of 'random_access_iterator_tag'
       struct random_access_iterator_tag: public bidirectional_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:107:10: note: previous definition is here
  struct random_access_iterator_tag : public bidirectional_iterator_tag { };
         ^
p995.cpp:24:15: error: redefinition of 'contiguous_iterator_tag'
       struct contiguous_iterator_tag: public random_access_iterator_tag { };
              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator_base_types.h:111:10: note: previous definition is here
  struct contiguous_iterator_tag : public random_access_iterator_tag { };
         ^
p995.cpp:27:1: error: unknown type name 'by'
by specializing the iterator_traits template:
^
p995.cpp:27:16: error: expected ';' after top level declarator
by specializing the iterator_traits template:
               ^
               ;
p995.cpp:36:1: error: unknown type name 'access'
access iterators, then the implementation is as follows:
^
p995.cpp:36:23: error: expected ';' after top level declarator
access iterators, then the implementation is as follows:
                      ^
                      ;
p995.cpp:86:16: error: reference to 'begin' is ambiguous
      distance(begin(vec), end(vec));
               ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:855:44: note: candidate found by name lookup is 'std::ranges::begin'
    inline constexpr __cust_access::_Begin begin{};
                                           ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/initializer_list:90:5: note: candidate found by name lookup is 'std::begin'
    begin(initializer_list<_Tp> __ils) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:51:5: note: candidate found by name lookup is 'std::begin'
    begin(_Container& __cont) -> decltype(__cont.begin())
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:61:5: note: candidate found by name lookup is 'std::begin'
    begin(const _Container& __cont) -> decltype(__cont.begin())
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:90:5: note: candidate found by name lookup is 'std::begin'
    begin(_Tp (&__arr)[_Nm])
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:107:31: note: candidate found by name lookup is 'std::begin'
  template<typename _Tp> _Tp* begin(valarray<_Tp>&);
                              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:108:37: note: candidate found by name lookup is 'std::begin'
  template<typename _Tp> const _Tp* begin(const valarray<_Tp>&);
                                    ^
p995.cpp:86:28: error: reference to 'end' is ambiguous
      distance(begin(vec), end(vec));
                           ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:856:42: note: candidate found by name lookup is 'std::ranges::end'
    inline constexpr __cust_access::_End end{};
                                         ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/initializer_list:101:5: note: candidate found by name lookup is 'std::end'
    end(initializer_list<_Tp> __ils) noexcept
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:71:5: note: candidate found by name lookup is 'std::end'
    end(_Container& __cont) -> decltype(__cont.end())
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:81:5: note: candidate found by name lookup is 'std::end'
    end(const _Container& __cont) -> decltype(__cont.end())
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:100:5: note: candidate found by name lookup is 'std::end'
    end(_Tp (&__arr)[_Nm])
    ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:109:31: note: candidate found by name lookup is 'std::end'
  template<typename _Tp> _Tp* end(valarray<_Tp>&);
                              ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/range_access.h:110:37: note: candidate found by name lookup is 'std::end'
  template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
                                    ^
p995.cpp:98:29: error: use of undeclared identifier 'I'
constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
                            ^
p995.cpp:98:72: error: use of undeclared identifier 'I'
constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
                                                                       ^
p995.cpp:98:48: error: unknown type name 'I'
constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
                                               ^
p995.cpp:98:78: error: unknown type name 'S'
constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
                                                                             ^
p995.cpp:108:42: error: out-of-line declaration of 'distance' does not match any declaration in namespace 'std::ranges'
  constexpr iter_difference_t<I> ranges::distance(I first, S last);
                                         ^~~~~~~~
p995.cpp:112:42: error: out-of-line declaration of 'distance' does not match any declaration in namespace 'std::ranges'
  constexpr iter_difference_t<I> ranges::distance(const I& first, const S& last);
                                         ^~~~~~~~
p995.cpp:114:32: error: use of undeclared identifier 'R'
  constexpr range_difference_t<R> ranges::distance(R&& r);
                               ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

$ g++ p995.cpp -std=03 -o p995g -I. -Wall
In file included from /usr/local/include/c++/12.1.0/atomic:38,
                 from N4910.h:11,
                 from p995.cpp:10:
/usr/local/include/c++/12.1.0/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
   32 | #error This file requires compiler and library support \
      |  ^~~~~
p995.cpp:55:1: warning: identifier 'constexpr' is a keyword in C++11 [-Wc++11-compat]
   55 | constexpr void ranges::advance(I& i, iter_difference_t<I> n);
      | ^~~~~~~~~
p995.cpp:19:15: error: redefinition of 'struct std::output_iterator_tag'
   19 |        struct output_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~~
In file included from /usr/local/include/c++/12.1.0/string:45,
                 from /usr/local/include/c++/12.1.0/bits/locale_classes.h:40,
                 from /usr/local/include/c++/12.1.0/bits/ios_base.h:41,
                 from /usr/local/include/c++/12.1.0/ios:42,
                 from /usr/local/include/c++/12.1.0/ostream:38,
                 from /usr/local/include/c++/12.1.0/iostream:39,
                 from N4910.h:2:
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:96:10: note: previous definition of 'struct std::output_iterator_tag'
   96 |   struct output_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~~
p995.cpp:20:15: error: redefinition of 'struct std::input_iterator_tag'
   20 |        struct input_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:93:10: note: previous definition of 'struct std::input_iterator_tag'
   93 |   struct input_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~
p995.cpp:21:15: error: redefinition of 'struct std::forward_iterator_tag'
   21 |        struct forward_iterator_tag: public input_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:99:10: note: previous definition of 'struct std::forward_iterator_tag'
   99 |   struct forward_iterator_tag : public input_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~~~
p995.cpp:22:15: error: redefinition of 'struct std::bidirectional_iterator_tag'
   22 |        struct bidirectional_iterator_tag: public forward_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:103:10: note: previous definition of 'struct std::bidirectional_iterator_tag'
  103 |   struct bidirectional_iterator_tag : public forward_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
p995.cpp:23:15: error: redefinition of 'struct std::random_access_iterator_tag'
   23 |        struct random_access_iterator_tag: public bidirectional_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:107:10: note: previous definition of 'struct std::random_access_iterator_tag'
  107 |   struct random_access_iterator_tag : public bidirectional_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
p995.cpp:27:1: error: 'by' does not name a type
   27 | by specializing the iterator_traits template:
      | ^~
p995.cpp:36:1: error: 'access' does not name a type
   36 | access iterators, then the implementation is as follows:
      | ^~~~~~
p995.cpp:55:1: error: 'constexpr' does not name a type
   55 | constexpr void ranges::advance(I& i, iter_difference_t<I> n);
      | ^~~~~~~~~
p995.cpp:55:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:61:6: error: 'constexpr' does not name a type
   61 |      constexpr void advance(InputIterator& i, Distance n);
      |      ^~~~~~~~~
p995.cpp:61:6: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:68:3: error: 'constexpr' does not name a type
   68 |   constexpr typename iterator_traits<InputIterator>::difference_type
      |   ^~~~~~~~~
p995.cpp:68:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:73:3: error: 'constexpr' does not name a type
   73 |   constexpr InputIterator next(InputIterator x,
      |   ^~~~~~~~~
p995.cpp:73:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:77:3: error: 'constexpr' does not name a type
   77 |   constexpr BidirectionalIterator prev(BidirectionalIterator x,
      |   ^~~~~~~~~
p995.cpp:77:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp: In function 'void foo()':
p995.cpp:84:28: error: 'ranges' is not a namespace-name
   84 |       using namespace std::ranges;
      |                            ^~~~~~
p995.cpp:85:27: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   85 |       std::vector<int> vec{1,2,3};
      |                           ^
p995.cpp:85:24: error: in C++98 'vec' must be initialized by constructor, not by '{...}'
   85 |       std::vector<int> vec{1,2,3};
      |                        ^~~
p995.cpp:85:33: error: no matching function for call to 'std::vector<int>::vector(<brace-enclosed initializer list>)'
   85 |       std::vector<int> vec{1,2,3};
      |                                 ^
In file included from /usr/local/include/c++/12.1.0/vector:64,
                 from N4910.h:8:
/usr/local/include/c++/12.1.0/bits/stl_vector.h:711:9: note: candidate: 'template<class _InputIterator> std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>]'
  711 |         vector(_InputIterator __first, _InputIterator __last,
      |         ^~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:711:9: note:   template argument deduction/substitution failed:
p995.cpp:85:32: note:   cannot convert '3' (type 'int') to type 'const std::vector<int>::allocator_type&' {aka 'const std::allocator<int>&'}
   85 |       std::vector<int> vec{1,2,3};
      |                                ^
/usr/local/include/c++/12.1.0/bits/stl_vector.h:596:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]'
  596 |       vector(const vector& __x)
      |       ^~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:596:7: note:   candidate expects 1 argument, 3 provided
/usr/local/include/c++/12.1.0/bits/stl_vector.h:578:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(size_type, const value_type&, const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int; value_type = int; allocator_type = std::allocator<int>]'
  578 |       vector(size_type __n, const value_type& __value = value_type(),
      |       ^~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:579:36: note:   no known conversion for argument 3 from 'in' to 'const std::vector<int>::allocator_type&' {aka 'const std::allocator<int>&'}
  579 |              const allocator_type& __a = allocator_type())
      |              ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:537:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector(const allocator_type&) [with _Tp = int; _Alloc = std::allocator<int>; allocator_type = std::allocator<int>]'
  537 |       vector(const allocator_type& __a) _GLIBCXX_NOEXCEPT
      |       ^~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:537:7: note:   candidate expects 1 argument, 3 provided
/usr/local/include/c++/12.1.0/bits/stl_vector.h:528:7: note: candidate: 'std::vector<_Tp, _Alloc>::vector() [with _Tp = int; _Alloc = std::allocator<int>]'
  528 |       vector() { }
      |       ^~~~~~
/usr/local/include/c++/12.1.0/bits/stl_vector.h:528:7: note:   candidate expects 0 arguments, 3 provided
p995.cpp:86:16: error: 'begin' was not declared in this scope
   86 |       distance(begin(vec), end(vec));
      |                ^~~~~
p995.cpp:86:16: note: 'std::begin' is only available from C++11 onwards
p995.cpp:86:28: error: 'end' was not declared in this scope
   86 |       distance(begin(vec), end(vec));
      |                            ^~~
p995.cpp:86:28: note: 'std::end' is only available from C++11 onwards
p995.cpp: At global scope:
p995.cpp:92:16: error: 'input_or_output_iterator' has not been declared
   92 |       template<input_or_output_iterator I, sentinel_for<I> S>
      |                ^~~~~~~~~~~~~~~~~~~~~~~~
p995.cpp:92:44: error: 'sentinel_for' has not been declared
   92 |       template<input_or_output_iterator I, sentinel_for<I> S>
      |                                            ^~~~~~~~~~~~
p995.cpp:92:56: error: expected '>' before '<' token
   92 |       template<input_or_output_iterator I, sentinel_for<I> S>
      |                                                        ^
p995.cpp:93:9: error: 'constexpr' does not name a type
   93 |         constexpr void ranges::advance(I& i, S bound);
      |         ^~~~~~~~~
p995.cpp:93:9: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:98:1: error: 'constexpr' does not name a type
   98 | constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
      | ^~~~~~~~~
p995.cpp:98:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:106:10: error: 'input_or_output_iterator' has not been declared
  106 | template<input_or_output_iterator I, sentinel_for<I> S>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
p995.cpp:106:38: error: 'sentinel_for' has not been declared
  106 | template<input_or_output_iterator I, sentinel_for<I> S>
      |                                      ^~~~~~~~~~~~
p995.cpp:106:50: error: expected '>' before '<' token
  106 | template<input_or_output_iterator I, sentinel_for<I> S>
      |                                                  ^
p995.cpp:107:12: error: expected constructor, destructor, or type conversion before '(' token
  107 |   requires (!sized_sentinel_for<S, I>)
      |            ^
p995.cpp:111:10: error: 'input_or_output_iterator' has not been declared
  111 | template<input_or_output_iterator I, sized_sentinel_for<I> S>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
p995.cpp:111:38: error: 'sized_sentinel_for' has not been declared
  111 | template<input_or_output_iterator I, sized_sentinel_for<I> S>
      |                                      ^~~~~~~~~~~~~~~~~~
p995.cpp:111:56: error: expected '>' before '<' token
  111 | template<input_or_output_iterator I, sized_sentinel_for<I> S>
      |                                                        ^
p995.cpp:112:3: error: 'constexpr' does not name a type
  112 |   constexpr iter_difference_t<I> ranges::distance(const I& first, const S& last);
      |   ^~~~~~~~~
p995.cpp:112:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:114:3: error: 'constexpr' does not name a type
  114 |   constexpr range_difference_t<R> ranges::distance(R&& r);
      |   ^~~~~~~~~
p995.cpp:114:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:116:1: error: expected unqualified-id before 'return'
  116 | return static_cast<range_difference_t<R>>(ranges::size(r));
      | ^~~~~~
p995.cpp:118:8: error: expected unqualified-id before 'return'
  118 |        return ranges::distance(ranges::begin(r), ranges::end(r));
      |        ^~~~~~
p995.cpp:120:10: error: 'input_or_output_iterator' has not been declared
  120 | template<input_or_output_iterator I>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
p995.cpp:121:3: error: 'constexpr' does not name a type
  121 |   constexpr I ranges::next(I x);
      |   ^~~~~~~~~
p995.cpp:121:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:123:1: error: 'constexpr' does not name a type
  123 | constexpr I ranges::next(I x, iter_difference_t<I> n);
      | ^~~~~~~~~
p995.cpp:123:1: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:125:10: error: 'input_or_output_iterator' has not been declared
  125 | template<input_or_output_iterator I, sentinel_for<I> S>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
p995.cpp:125:38: error: 'sentinel_for' has not been declared
  125 | template<input_or_output_iterator I, sentinel_for<I> S>
      |                                      ^~~~~~~~~~~~
p995.cpp:125:50: error: expected '>' before '<' token
  125 | template<input_or_output_iterator I, sentinel_for<I> S>
      |                                                  ^
p995.cpp:126:3: error: 'constexpr' does not name a type
  126 |   constexpr I ranges::next(I x, S bound);
      |   ^~~~~~~~~
p995.cpp:126:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:128:3: error: 'constexpr' does not name a type
  128 |   constexpr I ranges::next(I x, iter_difference_t<I> n, S bound);
      |   ^~~~~~~~~
p995.cpp:128:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:131:10: error: 'bidirectional_iterator' has not been declared
  131 | template<bidirectional_iterator I>
      |          ^~~~~~~~~~~~~~~~~~~~~~
p995.cpp:132:3: error: 'constexpr' does not name a type
  132 |   constexpr I ranges::prev(I x);
      |   ^~~~~~~~~
p995.cpp:132:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:134:3: error: 'constexpr' does not name a type
  134 |   constexpr I ranges::prev(I x, iter_difference_t<I> n);
      |   ^~~~~~~~~
p995.cpp:134:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'
p995.cpp:136:3: error: 'constexpr' does not name a type
  136 |   constexpr I ranges::prev(I x, iter_difference_t<I> n, I bound);
      |   ^~~~~~~~~
p995.cpp:136:3: note: C++11 'constexpr' only available with '-std=c++11' or '-std=gnu++11'

$ g++ p995.cpp -std=2b -o p995g -I. -Wall
p995.cpp:19:15: error: redefinition of 'struct std::output_iterator_tag'
   19 |        struct output_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~~
In file included from /usr/local/include/c++/12.1.0/bits/stl_construct.h:61,
                 from /usr/local/include/c++/12.1.0/bits/char_traits.h:46,
                 from /usr/local/include/c++/12.1.0/ios:40,
                 from /usr/local/include/c++/12.1.0/ostream:38,
                 from /usr/local/include/c++/12.1.0/iostream:39,
                 from N4910.h:2,
                 from p995.cpp:10:
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:96:10: note: previous definition of 'struct std::output_iterator_tag'
   96 |   struct output_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~~
p995.cpp:20:15: error: redefinition of 'struct std::input_iterator_tag'
   20 |        struct input_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:93:10: note: previous definition of 'struct std::input_iterator_tag'
   93 |   struct input_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~
p995.cpp:21:15: error: redefinition of 'struct std::forward_iterator_tag'
   21 |        struct forward_iterator_tag: public input_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:99:10: note: previous definition of 'struct std::forward_iterator_tag'
   99 |   struct forward_iterator_tag : public input_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~~~
p995.cpp:22:15: error: redefinition of 'struct std::bidirectional_iterator_tag'
   22 |        struct bidirectional_iterator_tag: public forward_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:103:10: note: previous definition of 'struct std::bidirectional_iterator_tag'
  103 |   struct bidirectional_iterator_tag : public forward_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
p995.cpp:23:15: error: redefinition of 'struct std::random_access_iterator_tag'
   23 |        struct random_access_iterator_tag: public bidirectional_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:107:10: note: previous definition of 'struct std::random_access_iterator_tag'
  107 |   struct random_access_iterator_tag : public bidirectional_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~
p995.cpp:24:15: error: redefinition of 'struct std::contiguous_iterator_tag'
   24 |        struct contiguous_iterator_tag: public random_access_iterator_tag { };
      |               ^~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_types.h:111:10: note: previous definition of 'struct std::contiguous_iterator_tag'
  111 |   struct contiguous_iterator_tag : public random_access_iterator_tag { };
      |          ^~~~~~~~~~~~~~~~~~~~~~~
p995.cpp:27:1: error: 'by' does not name a type
   27 | by specializing the iterator_traits template:
      | ^~
p995.cpp:36:1: error: 'access' does not name a type
   36 | access iterators, then the implementation is as follows:
      | ^~~~~~
p995.cpp:55:16: error: variable or field 'advance' declared void
   55 | constexpr void ranges::advance(I& i, iter_difference_t<I> n);
      |                ^~~~~~
p995.cpp:55:32: error: 'I' was not declared in this scope
   55 | constexpr void ranges::advance(I& i, iter_difference_t<I> n);
      |                                ^
p995.cpp:55:35: error: 'i' was not declared in this scope
   55 | constexpr void ranges::advance(I& i, iter_difference_t<I> n);
      |                                   ^
p995.cpp:55:56: error: 'I' was not declared in this scope
   55 | constexpr void ranges::advance(I& i, iter_difference_t<I> n);
      |                                                        ^
p995.cpp:55:57: error: template argument 1 is invalid
   55 | constexpr void ranges::advance(I& i, iter_difference_t<I> n);
      |                                                         ^
p995.cpp: In function 'void foo()':
p995.cpp:86:7: error: reference to 'distance' is ambiguous
   86 |       distance(begin(vec), end(vec));
      |       ^~~~~~~~
p995.cpp:69:1: note: candidates are: 'template<class InputIterator> constexpr typename std::iterator_traits<_Iterator>::difference_type distance(InputIterator, InputIterator)'
   69 | distance(InputIterator first, InputIterator last);
      | ^~~~~~~~
In file included from /usr/local/include/c++/12.1.0/bits/stl_construct.h:62:
/usr/local/include/c++/12.1.0/bits/stl_iterator_base_funcs.h:146:5: note:                 'template<class _InputIterator> constexpr typename std::iterator_traits<_Iterator>::difference_type std::distance(_InputIterator, _InputIterator)'
  146 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
In file included from /usr/local/include/c++/12.1.0/string_view:50,
                 from /usr/local/include/c++/12.1.0/bits/basic_string.h:48,
                 from /usr/local/include/c++/12.1.0/string:53,
                 from /usr/local/include/c++/12.1.0/bits/locale_classes.h:40,
                 from /usr/local/include/c++/12.1.0/bits/ios_base.h:41,
                 from /usr/local/include/c++/12.1.0/ios:42:
/usr/local/include/c++/12.1.0/bits/ranges_base.h:864:34: note:                 'constexpr const std::ranges::__distance_fn std::ranges::distance'
  864 |   inline constexpr __distance_fn distance{};
      |                                  ^~~~~~~~
p995.cpp:86:16: error: reference to 'begin' is ambiguous
   86 |       distance(begin(vec), end(vec));
      |                ^~~~~
/usr/local/include/c++/12.1.0/bits/ranges_base.h:566:44: note: candidates are: 'constexpr const std::ranges::__cust_access::_Begin std::ranges::__cust::begin'
  566 |     inline constexpr __cust_access::_Begin begin{};
      |                                            ^~~~~
In file included from /usr/local/include/c++/12.1.0/string:52:
/usr/local/include/c++/12.1.0/bits/range_access.h:114:37: note:                 'template<class _Tp> const _Tp* std::begin(const valarray<_Tp>&)'
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
/usr/local/include/c++/12.1.0/bits/range_access.h:113:31: note:                 'template<class _Tp> _Tp* std::begin(valarray<_Tp>&)'
  113 |   template<typename _Tp> _Tp* begin(valarray<_Tp>&) noexcept;
      |                               ^~~~~
/usr/local/include/c++/12.1.0/bits/range_access.h:95:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::begin(_Tp (&)[_Nm])'
   95 |     begin(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~~~
/usr/local/include/c++/12.1.0/bits/range_access.h:63:5: note:                 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(const _Container&)'
   63 |     begin(const _Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
/usr/local/include/c++/12.1.0/bits/range_access.h:52:5: note:                 'template<class _Container> constexpr decltype (__cont.begin()) std::begin(_Container&)'
   52 |     begin(_Container& __cont) -> decltype(__cont.begin())
      |     ^~~~~
In file included from /usr/local/include/c++/12.1.0/bits/range_access.h:36:
/usr/local/include/c++/12.1.0/initializer_list:90:5: note:                 'template<class _Tp> constexpr const _Tp* std::begin(initializer_list<_Tp>)'
   90 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
p995.cpp:86:28: error: reference to 'end' is ambiguous
   86 |       distance(begin(vec), end(vec));
      |                            ^~~
/usr/local/include/c++/12.1.0/bits/ranges_base.h:567:42: note: candidates are: 'constexpr const std::ranges::__cust_access::_End std::ranges::__cust::end'
  567 |     inline constexpr __cust_access::_End end{};
      |                                          ^~~
/usr/local/include/c++/12.1.0/bits/range_access.h:116:37: note:                 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/local/include/c++/12.1.0/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/local/include/c++/12.1.0/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/local/include/c++/12.1.0/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/local/include/c++/12.1.0/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/local/include/c++/12.1.0/initializer_list:101:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
  101 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
p995.cpp: At global scope:
p995.cpp:93:53: error: 'void std::ranges::advance(I&, S)' should have been declared inside 'std::ranges'
   93 |         constexpr void ranges::advance(I& i, S bound);
      |                                                     ^
p995.cpp:93:53: error: 'template<class I, class S>  requires (input_or_output_iterator<I>) && (sentinel_for<S, I>) constexpr void std::ranges::advance(I&, S)' redeclared as different kind of entity
/usr/local/include/c++/12.1.0/bits/ranges_base.h:824:33: note: previous declaration 'constexpr const std::ranges::__advance_fn std::ranges::advance'
  824 |   inline constexpr __advance_fn advance{};
      |                                 ^~~~~~~
p995.cpp:98:29: error: 'I' was not declared in this scope
   98 | constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
      |                             ^
p995.cpp:98:30: error: template argument 1 is invalid
   98 | constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
      |                              ^
p995.cpp:98:32: error: conflicting declaration 'constexpr const int std::ranges::advance'
   98 | constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
      |                                ^~~~~~
/usr/local/include/c++/12.1.0/bits/ranges_base.h:824:33: note: previous declaration as 'constexpr const std::ranges::__advance_fn std::ranges::advance'
  824 |   inline constexpr __advance_fn advance{};
      |                                 ^~~~~~~
p995.cpp:98:48: error: 'I' was not declared in this scope
   98 | constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
      |                                                ^
p995.cpp:98:51: error: 'i' was not declared in this scope
   98 | constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
      |                                                   ^
p995.cpp:98:72: error: 'I' was not declared in this scope
   98 | constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
      |                                                                        ^
p995.cpp:98:73: error: template argument 1 is invalid
   98 | constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
      |                                                                         ^
p995.cpp:98:78: error: 'S' was not declared in this scope
   98 | constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
      |                                                                              ^
p995.cpp:108:66: error: 'std::iter_difference_t<_Iter> std::ranges::distance(I, S)' should have been declared inside 'std::ranges'
  108 |   constexpr iter_difference_t<I> ranges::distance(I first, S last);
      |                                                                  ^
p995.cpp:108:66: error: 'template<class I, class S>  requires (input_or_output_iterator<I>) && (sentinel_for<S, I>) && !(sized_sentinel_for<S, I>) constexpr std::iter_difference_t<_Iter> std::ranges::distance(I, S)' redeclared as different kind of entity
/usr/local/include/c++/12.1.0/bits/ranges_base.h:864:34: note: previous declaration 'constexpr const std::ranges::__distance_fn std::ranges::distance'
  864 |   inline constexpr __distance_fn distance{};
      |                                  ^~~~~~~~
p995.cpp:112:80: error: 'std::iter_difference_t<_Iter> std::ranges::distance(const I&, const S&)' should have been declared inside 'std::ranges'
  112 |   constexpr iter_difference_t<I> ranges::distance(const I& first, const S& last);
      |                                                                                ^
p995.cpp:112:80: error: 'template<class I, class S>  requires (input_or_output_iterator<I>) && (sized_sentinel_for<S, I>) constexpr std::iter_difference_t<_Iter> std::ranges::distance(const I&, const S&)' redeclared as different kind of entity
/usr/local/include/c++/12.1.0/bits/ranges_base.h:864:34: note: previous declaration 'constexpr const std::ranges::__distance_fn std::ranges::distance'
  864 |   inline constexpr __distance_fn distance{};
      |                                  ^~~~~~~~
p995.cpp:114:32: error: 'R' was not declared in this scope
  114 |   constexpr range_difference_t<R> ranges::distance(R&& r);
      |                                ^
p995.cpp:114:32: error: 'R' was not declared in this scope
p995.cpp:114:32: error: 'R' was not declared in this scope
p995.cpp:114:32: error: 'R' was not declared in this scope
p995.cpp:114:32: error: 'R' was not declared in this scope
p995.cpp:114:32: error: 'R' was not declared in this scope
p995.cpp:114:32: error: 'R' was not declared in this scope
p995.cpp:114:32: error: 'R' was not declared in this scope
p995.cpp:114:13: error: 'range_difference_t' does not name a type
  114 |   constexpr range_difference_t<R> ranges::distance(R&& r);
      |             ^~~~~~~~~~~~~~~~~~
p995.cpp:116:1: error: expected unqualified-id before 'return'
  116 | return static_cast<range_difference_t<R>>(ranges::size(r));
      | ^~~~~~
p995.cpp:118:8: error: expected unqualified-id before 'return'
  118 |        return ranges::distance(ranges::begin(r), ranges::end(r));
      |        ^~~~~~
p995.cpp:121:31: error: 'I std::ranges::next(I)' should have been declared inside 'std::ranges'
  121 |   constexpr I ranges::next(I x);
      |                               ^
p995.cpp:121:31: error: 'template<class I>  requires  input_or_output_iterator<I> constexpr I std::ranges::next(I)' redeclared as different kind of entity
/usr/local/include/c++/12.1.0/bits/ranges_base.h:907:30: note: previous declaration 'constexpr const std::ranges::__next_fn std::ranges::next'
  907 |   inline constexpr __next_fn next{};
      |                              ^~~~
p995.cpp:123:11: error: 'I' does not name a type
  123 | constexpr I ranges::next(I x, iter_difference_t<I> n);
      |           ^
p995.cpp:126:40: error: 'I std::ranges::next(I, S)' should have been declared inside 'std::ranges'
  126 |   constexpr I ranges::next(I x, S bound);
      |                                        ^
p995.cpp:126:40: error: 'template<class I, class S>  requires (input_or_output_iterator<I>) && (sentinel_for<S, I>) constexpr I std::ranges::next(I, S)' redeclared as different kind of entity
/usr/local/include/c++/12.1.0/bits/ranges_base.h:907:30: note: previous declaration 'constexpr const std::ranges::__next_fn std::ranges::next'
  907 |   inline constexpr __next_fn next{};
      |                              ^~~~
p995.cpp:128:13: error: 'I' does not name a type
  128 |   constexpr I ranges::next(I x, iter_difference_t<I> n, S bound);
      |             ^
p995.cpp:132:31: error: 'I std::ranges::prev(I)' should have been declared inside 'std::ranges'
  132 |   constexpr I ranges::prev(I x);
      |                               ^
p995.cpp:132:31: error: 'template<class I>  requires  bidirectional_iterator<I> constexpr I std::ranges::prev(I)' redeclared as different kind of entity
/usr/local/include/c++/12.1.0/bits/ranges_base.h:941:30: note: previous declaration 'constexpr const std::ranges::__prev_fn std::ranges::prev'
  941 |   inline constexpr __prev_fn prev{};
      |                              ^~~~
p995.cpp:134:13: error: 'I' does not name a type
  134 |   constexpr I ranges::prev(I x, iter_difference_t<I> n);
      |             ^
p995.cpp:136:13: error: 'I' does not name a type
  136 |   constexpr I ranges::prev(I x, iter_difference_t<I> n, I bound);
      |             ^

検討事項(agenda)

コンパイルエラーを取るか、コンパイルエラーの理由を解説する。

参考資料(reference)

関連する自己参照以外は、こちらの先頭に移転。

C言語(C++)に対する誤解、曲解、無理解、爽快。

#include "N4910.h"

C++N4910資料の改善点

dockerにclang

docker gnu(gcc/g++) and llvm(clang/clang++)

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)

C++N4910:2022 tag follower 300人超えました。ありがとうございます。

astyle 使ってみた

DoCAP(ドゥーキャップ)って何ですか?

小川メソッド 覚え(書きかけ)

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>

文書履歴(document history)

ver. 0.01 初稿  20220809

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?