27 Algorithms library [algorithms] 27.2 Algorithms requirements [algorithms.requirements] C++N4910:2022 (656) p1148.cpp

# はじめに(Introduction)

N4910  Working Draft, Standard for Programming Language C++

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/n4910.pdf

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

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

https://stackoverflow.com

http://ja.cppreference.com/

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

https://cpprefjp.github.io/

コンパイラの実装状況

https://cpprefjp.github.io/implementation-status.html

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

## 作業方針(sequence)
Clang++では-std=c++03, C++2bの2種類
g++では-std=c++03, c++2bの２種類
でコンパイルし、

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

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

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

https://qiita.com/kaizen_nagoya/items/fc957ddddd402004bb91

### C++N4741, 2018 Standard Working Draft on ISO/IEC 14882 sample code compile list
https://qiita.com/kaizen_nagoya/items/3294c014044550896010

### 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++
https://qiita.com/kaizen_nagoya/items/685b5c1a2c17c1bf1318

## 編纂器(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.

# 27 Algorithms library [algorithms] 27.2 Algorithms requirements [algorithms.requirements] C++N4910:2022 (656) p1148.cpp

## 算譜(source code)

```c++:p1148.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 = "27 Algorithms library [algorithms] 27.2 Algorithms requirements [algorithms.requirements] C++N4910:2022 (656) p1148.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;

// 27.2 Algorithms requirements [algorithms.requirements]
// All of the algorithms are separated from the particular implementations of data structures and are parame- terized by iterator types. Because of this, they can work with program-defined data structures, as long as these data structures have iterator types satisfying the assumptions on the algorithms. The entities defined in the std::ranges namespace in this Clause 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. Subclause Header
// 27.2 Algorithms requirements
// 27.3 Parallel algorithms
// 27.5 Algorithm result types <algorithm>
// 27.6 Non-modifying sequence operations
// 27.7 Mutating sequence operations
// 27.8 Sorting and related operations
// 27.10 Generalized numeric operations <numeric>
// 27.11 Specialized <memory> algorithms <memory>
// 27.12 C library algorithms <cstdlib>
// [Example 1:
void foo() {
    using namespace std::ranges;
    std::vector<int> vec{1,2,3};
    find(begin(vec), end(vec), 2);
}
// #1
// — If an algorithm’s template parameter is named InputIterator, InputIterator1, or InputIterator2, the template argument shall meet the Cpp17InputIterator requirements (25.3.5.3).
// — If an algorithm’s template parameter is named OutputIterator, OutputIterator1, or Output- Iterator2, the template argument shall meet the Cpp17OutputIterator requirements (25.3.5.4).
// — If an algorithm’s template parameter is named ForwardIterator, ForwardIterator1, or Forward- Iterator2, the template argument shall meet the Cpp17ForwardIterator requirements (25.3.5.5).
// — If an algorithm’s template parameter is named NoThrowForwardIterator, the template argument shall meet the Cpp17ForwardIterator requirements (25.3.5.5), and is required to have the property that no exceptions are thrown from increment, assignment, or comparison of, or indirection through, valid iterators.
// — If an algorithm’s template parameter is named BidirectionalIterator, BidirectionalIterator1, or BidirectionalIterator2, the template argument shall meet the Cpp17BidirectionalIterator re- quirements (25.3.5.6).
// — If an algorithm’s template parameter is named RandomAccessIterator, RandomAccessIterator1, or RandomAccessIterator2, the template argument shall meet the Cpp17RandomAccessIterator require- ments (25.3.5.7).
// If an algorithm’s Effects: element specifies that a value pointed to by any iterator passed as an argument is modified, then that algorithm has an additional type requirement: The type of that argument shall meet the requirements of a mutable iterator (25.3).
// [Note 1: This requirement does not affect arguments that are named OutputIterator, OutputIterator1, or OutputIterator2, because output iterators must always be mutable, nor does it affect arguments that are con- strained, for which mutability requirements are expressed explicitly.
//  Both in-place and copying versions are provided for certain algorithms.220 When such a version is provided for algorithm it is called algorithm_copy. Algorithms that take predicates end with the suffix _if (which follows the suffix _copy).
//  When not otherwise constrained, the Predicate parameter is used whenever an algorithm expects a function object (22.10) that, when applied to the result of dereferencing the corresponding iterator, returns a value testable as true. In other words, if an algorithm takes Predicate pred as its argument and first as its iterator argument with value type T, it should work correctly in the construct pred(*first) contextually converted to bool (7.3). The function object pred shall not apply any non-constant function through the dereferenced iterator. Given a glvalue u of type (possibly const) T that designates the same object as *first, pred(u) shall be a valid expression that is equal to pred(*first).
//  When not otherwise constrained, the BinaryPredicate parameter is used whenever an algorithm expects a function object that when applied to the result of dereferencing two corresponding iterators or to dereferencing an iterator and type T when T is part of the signature returns a value testable as true. In other words, if an algorithm takes BinaryPredicate binary_pred as its argument and first1 and first2 as its iterator argu- ments with respective value types T1 and T2, it should work correctly in the construct binary_pred(*first1,
// *first2) contextually converted to bool (7.3). Unless otherwise specified, BinaryPredicate always takes the first iterator’s value_type as its first argument, that is, in those cases when T value is part of the signature, it should work correctly in the construct binary_pred(*first1, value) contextually converted to bool (7.3). binary_pred shall not apply any non-constant function through the dereferenced iterators. Given a glvalue u of type (possibly const) T1 that designates the same object as *first1, and a glvalue v of type (possibly const) T2 that designates the same object as *first2, binary_pred(u, *first2), binary_pred(*first1, v), and binary_pred(u, v) shall each be a valid expression that is equal to binary_pred(*first1, *first2), and binary_pred(u, value) shall be a valid expression that is equal to binary_pred(*first1, value).
//  The parameters UnaryOperation, BinaryOperation, BinaryOperation1, and BinaryOperation2 are used whenever an algorithm expects a function object (22.10).
//  [Note 2: Unless otherwise specified, algorithms that take function objects as arguments can copy those function objects freely. If object identity is important, a wrapper class that points to a noncopied implementation object such as reference_wrapper<T> (22.10.6), or some equivalent solution, can be used.
//  When the description of an algorithm gives an expression such as *first == value for a condition, the expression shall evaluate to either true or false in boolean contexts.
//  In the description of the algorithms, operator + is used for some of the iterator categories for which it does not have to be defined. In these cases the semantics of a + n are the same as those of
#define a 1
int f() {
    auto tmp = a;
    for (; n < 0; ++n) --tmp;
    for (; n > 0; --n) ++tmp;
    return tmp;
}
// Similarly, operator - is used for some combinations of iterators and sentinel types for which it does not have to be defined. If [a, b) denotes a range, the semantics of b - a in these cases are the same as those of
#define b 1
int g() {
    iter_difference_t<decltype(a)> n = 0;
    for (auto tmp = a; tmp != b; ++tmp) ++n;
    return n;
}
// and if [b, a) denotes a range, the same as those of
int h() {
    iter_difference_t<decltype(b)> n = 0;
    for (auto tmp = b; tmp != a; ++tmp) --n;
    return n;
}
//  In the description of the algorithms, given an iterator a whose difference type is D, and an expression n of integer-like type other than cv D, the semantics of a + n and a - n are, respectively, those of a + D(n) and a - D(n).
//  In the description of algorithm return values, a sentinel value s denoting the end of a range [i, s) is sometimes returned where an iterator is expected. In these cases, the semantics are as if the sentinel is converted into an iterator using ranges::next(i, s).
//  Overloads of algorithms that take range arguments (26.4.2) behave as if they are implemented by calling ranges::begin and ranges::end on the range(s) and dispatching to the overload in namespace ranges that takes separate iterator and sentinel arguments.
//  The well-formedness and behavior of a call to an algorithm with an explicitly-specified template argument list is unspecified, except where explicitly stated otherwise.
// [Note 3: Consequently, an implementation can declare an algorithm with different template parameters than those presented.
int main() {
    f();
    g();
    h();
    cout  <<  n4910 << endl;
    return EXIT_SUCCESS;
}
```

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

```ubuntu:bash
$ clang++ p1148.cpp -std=03 -o p1148l -I. -Wall
In file included from p1148.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 \
 ^
p1148.cpp:27:26: error: expected namespace name
    using namespace std::ranges;
                    ~~~~~^
p1148.cpp:28:25: error: expected ';' at end of declaration
    std::vector<int> vec{1,2,3};
                        ^
                        ;
p1148.cpp:29:10: error: use of undeclared identifier 'begin'
    find(begin(vec), end(vec), 2);
         ^
p1148.cpp:29:22: error: use of undeclared identifier 'end'
    find(begin(vec), end(vec), 2);
                     ^
p1148.cpp:50:1: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto tmp = a;
^
p1148.cpp:51:13: error: use of undeclared identifier 'n'
     for (; n < 0; ++n) --tmp;
            ^
p1148.cpp:51:22: error: use of undeclared identifier 'n'
     for (; n < 0; ++n) --tmp;
                     ^
p1148.cpp:52:13: error: use of undeclared identifier 'n'
     for (; n > 0; --n) ++tmp;
            ^
p1148.cpp:52:22: error: use of undeclared identifier 'n'
     for (; n > 0; --n) ++tmp;
                     ^
p1148.cpp:58:19: error: use of undeclared identifier 'decltype'
iter_difference_t<decltype(a)> n = 0;
                  ^
p1148.cpp:58:1: error: no template named 'iter_difference_t'
iter_difference_t<decltype(a)> n = 0;
^
p1148.cpp:59:11: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
     for (auto tmp = a; tmp != b; ++tmp) ++n;
          ^
p1148.cpp:64:19: error: use of undeclared identifier 'decltype'
iter_difference_t<decltype(b)> n = 0;
                  ^
p1148.cpp:64:1: error: no template named 'iter_difference_t'
iter_difference_t<decltype(b)> n = 0;
^
p1148.cpp:65:11: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
     for (auto tmp = b; tmp != a; ++tmp) --n;
          ^
3 warnings and 13 errors generated.
$ clang++ p1148.cpp -std=2b -o p1148l -I. -Wall
p1148.cpp:29:10: error: reference to 'begin' is ambiguous
    find(begin(vec), end(vec), 2);
         ^
/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>&);
                                    ^
p1148.cpp:29:22: error: reference to 'end' is ambiguous
    find(begin(vec), end(vec), 2);
                     ^
/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>&);
                                    ^
p1148.cpp:51:13: error: use of undeclared identifier 'n'
     for (; n < 0; ++n) --tmp;
            ^
p1148.cpp:51:22: error: use of undeclared identifier 'n'
     for (; n < 0; ++n) --tmp;
                     ^
p1148.cpp:52:13: error: use of undeclared identifier 'n'
     for (; n > 0; --n) ++tmp;
            ^
p1148.cpp:52:22: error: use of undeclared identifier 'n'
     for (; n > 0; --n) ++tmp;
                     ^
6 errors generated.

$ g++ p1148.cpp -std=03 -o p1148g -I. -Wall
In file included from /usr/local/include/c++/12.1.0/atomic:38,
                 from N4910.h:11,
                 from p1148.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 \
      |  ^~~~~
p1148.cpp:58:19: warning: identifier 'decltype' is a keyword in C++11 [-Wc++11-compat]
   58 | iter_difference_t<decltype(a)> n = 0;
      |                   ^~~~~~~~
p1148.cpp: In function 'void foo()':
p1148.cpp:27:26: error: 'ranges' is not a namespace-name
   27 |     using namespace std::ranges;
      |                          ^~~~~~
p1148.cpp:28:25: warning: extended initializer lists only available with '-std=c++11' or '-std=gnu++11' [-Wc++11-extensions]
   28 |     std::vector<int> vec{1,2,3};
      |                         ^
p1148.cpp:28:22: error: in C++98 'vec' must be initialized by constructor, not by '{...}'
   28 |     std::vector<int> vec{1,2,3};
      |                      ^~~
p1148.cpp:28:31: error: no matching function for call to 'std::vector<int>::vector(<brace-enclosed initializer list>)'
   28 |     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:
p1148.cpp:28:30: note:   cannot convert '3' (type 'int') to type 'const std::vector<int>::allocator_type&' {aka 'const std::allocator<int>&'}
   28 |     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 'int' 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
p1148.cpp:29:10: error: 'begin' was not declared in this scope
   29 |     find(begin(vec), end(vec), 2);
      |          ^~~~~
p1148.cpp:29:10: note: 'std::begin' is only available from C++11 onwards
p1148.cpp:29:22: error: 'end' was not declared in this scope
   29 |     find(begin(vec), end(vec), 2);
      |                      ^~~
p1148.cpp:29:22: note: 'std::end' is only available from C++11 onwards
p1148.cpp: In function 'int f()':
p1148.cpp:50:1: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   50 | auto tmp = a;
      | ^~~~
      | ----
p1148.cpp:50:6: error: 'tmp' does not name a type; did you mean 'tm'?
   50 | auto tmp = a;
      |      ^~~
      |      tm
p1148.cpp:51:13: error: 'n' was not declared in this scope; did you mean 'yn'?
   51 |      for (; n < 0; ++n) --tmp;
      |             ^
      |             yn
p1148.cpp:51:27: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   51 |      for (; n < 0; ++n) --tmp;
      |                           ^~~
      |                           tm
p1148.cpp:52:13: error: 'n' was not declared in this scope; did you mean 'yn'?
   52 |      for (; n > 0; --n) ++tmp;
      |             ^
      |             yn
p1148.cpp:52:27: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   52 |      for (; n > 0; --n) ++tmp;
      |                           ^~~
      |                           tm
p1148.cpp:53:13: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   53 |      return tmp;
      |             ^~~
      |             tm
p1148.cpp: In function 'int g()':
p1148.cpp:58:1: error: 'iter_difference_t' was not declared in this scope
   58 | iter_difference_t<decltype(a)> n = 0;
      | ^~~~~~~~~~~~~~~~~
p1148.cpp:58:19: error: 'decltype' was not declared in this scope; did you mean 'wctype'?
   58 | iter_difference_t<decltype(a)> n = 0;
      |                   ^~~~~~~~
      |                   wctype
p1148.cpp:58:32: error: 'n' was not declared in this scope; did you mean 'yn'?
   58 | iter_difference_t<decltype(a)> n = 0;
      |                                ^
      |                                yn
p1148.cpp:59:11: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   59 |      for (auto tmp = a; tmp != b; ++tmp) ++n;
      |           ^~~~
      |           ----
p1148.cpp:59:16: error: 'tmp' does not name a type; did you mean 'tm'?
   59 |      for (auto tmp = a; tmp != b; ++tmp) ++n;
      |                ^~~
      |                tm
p1148.cpp:59:24: error: expected ';' before 'tmp'
   59 |      for (auto tmp = a; tmp != b; ++tmp) ++n;
      |                        ^~~~
      |                        ;
p1148.cpp:59:25: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   59 |      for (auto tmp = a; tmp != b; ++tmp) ++n;
      |                         ^~~
      |                         tm
p1148.cpp: In function 'int h()':
p1148.cpp:64:1: error: 'iter_difference_t' was not declared in this scope
   64 | iter_difference_t<decltype(b)> n = 0;
      | ^~~~~~~~~~~~~~~~~
p1148.cpp:64:19: error: 'decltype' was not declared in this scope; did you mean 'wctype'?
   64 | iter_difference_t<decltype(b)> n = 0;
      |                   ^~~~~~~~
      |                   wctype
p1148.cpp:64:32: error: 'n' was not declared in this scope; did you mean 'yn'?
   64 | iter_difference_t<decltype(b)> n = 0;
      |                                ^
      |                                yn
p1148.cpp:65:11: warning: 'auto' changes meaning in C++11; please remove it [-Wc++11-compat]
   65 |      for (auto tmp = b; tmp != a; ++tmp) --n;
      |           ^~~~
      |           ----
p1148.cpp:65:16: error: 'tmp' does not name a type; did you mean 'tm'?
   65 |      for (auto tmp = b; tmp != a; ++tmp) --n;
      |                ^~~
      |                tm
p1148.cpp:65:24: error: expected ';' before 'tmp'
   65 |      for (auto tmp = b; tmp != a; ++tmp) --n;
      |                        ^~~~
      |                        ;
p1148.cpp:65:25: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   65 |      for (auto tmp = b; tmp != a; ++tmp) --n;
      |                         ^~~
      |                         tm

$ g++ p1148.cpp -std=2b -o p1148g -I. -Wall
p1148.cpp: In function 'void foo()':
p1148.cpp:29:10: error: reference to 'begin' is ambiguous
   29 |     find(begin(vec), end(vec), 2);
      |          ^~~~~
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,
                 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 p1148.cpp:10:
/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
      |     ^~~~~
p1148.cpp:29:22: error: reference to 'end' is ambiguous
   29 |     find(begin(vec), end(vec), 2);
      |                      ^~~
/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
      |     ^~~
p1148.cpp: In function 'int f()':
p1148.cpp:51:13: error: 'n' was not declared in this scope; did you mean 'yn'?
   51 |      for (; n < 0; ++n) --tmp;
      |             ^
      |             yn
p1148.cpp:52:13: error: 'n' was not declared in this scope; did you mean 'yn'?
   52 |      for (; n > 0; --n) ++tmp;
      |             ^
      |             yn

```

## 検討事項(agenda)
コンパイルエラーを取るか、コンパイルエラーの理由を解説する。

<!-- リンクエラーの解説をする。clang++とg++の比較。意味のある出力。
コンパイルエラーを取るか、コンパイルエラーの理由を解説する。-->

# 参考資料(reference)


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

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

https://qiita.com/kaizen_nagoya/items/3f3992c9722c1cee2e3a

#include "N4910.h"

https://qiita.com/kaizen_nagoya/items/163a47cef7d6bb1c33a8

C++N4910資料の改善点

https://qiita.com/kaizen_nagoya/items/fb4ceb5d117a54641af3

dockerにclang

https://qiita.com/kaizen_nagoya/items/8829ffeee397eda50e80

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

https://qiita.com/kaizen_nagoya/items/059874ea39c4de64c0f7

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

https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da


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

https://qiita.com/kaizen_nagoya/items/a63fb96d351ac5c16ff7

astyle 使ってみた

https://qiita.com/kaizen_nagoya/items/3c9a87a781d53a1a23f3

DoCAP（ドゥーキャップ）って何ですか？

https://qiita.com/kaizen_nagoya/items/47e0e6509ab792c43327

小川メソッド　覚え（書きかけ）

https://qiita.com/kaizen_nagoya/items/3593d72eca551742df68

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

# 文書履歴(document history)
ver. 0.01 初稿 　20220813