LoginSignup
0
0

More than 5 years have passed since last update.

The C++ Standard Library: clang++とg++でコンパイルしてみた(1) algo

Last updated at Posted at 2018-06-16

The C++ Standard Library - A Tutorial and Reference, 2nd Edition by Nicolai M. Josuttis
http://cppstdlib.com

The C++ Standard Library: clang++とg++でコンパイルしてみた(まとめ)
https://qiita.com/kaizen_nagoya/items/9bdfaa392443d13e5759

目的(purpose)

The C++ Standard Libraryコンパイル記録は、コンパイラおよび対応標準、コンパイラの版により、コンパイルエラーMessageの違いを記録し、どのエラーが出たら、どの版またはどの対応標準にすればエラーが少なくなるかを考察するための資料の第一歩です。

成果(outcome)

(1)コンパイラの種類、対応標準の違いによってエラーの数が違う。
(2)同じエラーであってもMessageの表現が違う。
(3) Error Messageのネットで検索する際に役立つ。

編纂器(compiler)

clang++

clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

g++

g++ (Homebrew GCC 8.1.0) 8.1.0
Copyright (C) 2018 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.

#編纂実行(compile and go)
##algo

```shell-session:algo
clang++ ./algo/accumulate1.cpp -std=c++2a -Wall
1 2 3 4 5 6 7 8 9 
sum: 45
sum: -55
product: 362880
product: 0
g++ ./algo/accumulate1.cpp -std=c++2a -Wall
1 2 3 4 5 6 7 8 9 
sum: 45
sum: -55
product: 362880
product: 0
clang++ ./algo/adjacentdiff1.cpp -std=c++2a -Wall
1 2 3 4 5 6 
1 1 1 1 1 1 
1 3 5 7 9 11 
1 2 6 12 20 30 
g++ ./algo/adjacentdiff1.cpp -std=c++2a -Wall
1 2 3 4 5 6 
1 1 1 1 1 1 
1 3 5 7 9 11 
1 2 6 12 20 30 
clang++ ./algo/adjacentfind1.cpp -std=c++2a -Wall
coll: 1 3 2 4 5 5 0 
first two elements with equal value have position 5
first two elements with second value twice the first have pos. 3
g++ ./algo/adjacentfind1.cpp -std=c++2a -Wall
coll: 1 3 2 4 5 5 0 
first two elements with equal value have position 5
first two elements with second value twice the first have pos. 3
clang++ ./algo/allanynone1.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 
all even?:  false
any even?:  true
none even?: false
g++ ./algo/allanynone1.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 
all even?:  false
any even?:  true
none even?: false
clang++ ./algo/binarysearch1.cpp -std=c++2a -Wall
1 2 3 4 5 6 7 8 9 
5 is present
42 is not present
g++ ./algo/binarysearch1.cpp -std=c++2a -Wall
1 2 3 4 5 6 7 8 9 
5 is present
42 is not present
clang++ ./algo/bounds1.cpp -std=c++2a -Wall
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 
5 could get position 9 up to 11 without breaking the sorting
1 1 2 2 3 3 3 4 4 5 5 6 6 7 7 7 8 8 9 9 
g++ ./algo/bounds1.cpp -std=c++2a -Wall
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 
5 could get position 9 up to 11 without breaking the sorting
1 1 2 2 3 3 3 4 4 5 5 6 6 7 7 7 8 8 9 9 
clang++ ./algo/copy1.cpp -std=c++2a -Wall
Hello this is an example 
example an is this Hello 
g++ ./algo/copy1.cpp -std=c++2a -Wall
Hello this is an example 
example an is this Hello 
clang++ ./algo/copy2.cpp -std=c++2a -Wall
source: . . . . . . . . . . a b c d e f . . . . . . . . . . 
c1:     . . . . . . . a b c d e f d e f . . . . . . . . . . 
c2:     . . . . . . . . . . a b c a b c d e f . . . . . . . 
g++ ./algo/copy2.cpp -std=c++2a -Wall
source: . . . . . . . . . . a b c d e f . . . . . . . . . . 
c1:     . . . . . . . a b c d e f d e f . . . . . . . . . . 
c2:     . . . . . . . . . . a b c a b c d e f . . . . . . . 

copy3.cppでconsole入力待ち。
手作業、続きは別に起動

$clang++ ./algo/copy3.cpp -std=c++2a -Wall
$./a.out
a
a
b
b
^Z
[7]+  Stopped                 ./a.out
$g++ ./algo/copy3.cpp -std=c++2a -Wall
$./a.out
a
a
b
b
^Z
[7]+  Stopped                 ./a.out
$ ../cga.sh algo2a
clang++ count1.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 
number of elements equal to 4:      1
number of elements with even value: 4
number of elements greater than 4:  5
g++ count1.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 
number of elements equal to 4:      1
number of elements with even value: 4
number of elements greater than 4:  5
clang++ equal1.cpp -std=c++2a -Wall
coll1: 1 2 3 4 5 6 7 
coll2: 3 4 5 6 7 8 9 
coll1 != coll2
even and odd elements correspond
g++ equal1.cpp -std=c++2a -Wall
coll1: 1 2 3 4 5 6 7 
coll2: 3 4 5 6 7 8 9 
coll1 != coll2
even and odd elements correspond
clang++ equalrange1.cpp -std=c++2a -Wall
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 
5 could get position 9 up to 11 without breaking the sorting
g++ equalrange1.cpp -std=c++2a -Wall
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 
5 could get position 9 up to 11 without breaking the sorting
clang++ fill1.cpp -std=c++2a -Wall
7.7 7.7 7.7 7.7 7.7 7.7 7.7 7.7 7.7 7.7 
coll: hello hello hello hello hello hello hello hello hello 
coll: again again again again again again again again again 
coll: hi hi hi hi hi hi hi again again 
coll: hi hmmm hmmm hmmm hmmm hmmm hmmm hmmm again 
g++ fill1.cpp -std=c++2a -Wall
7.7 7.7 7.7 7.7 7.7 7.7 7.7 7.7 7.7 7.7 
coll: hello hello hello hello hello hello hello hello hello 
coll: again again again again again again again again again 
coll: hi hi hi hi hi hi hi again again 
coll: hi hmmm hmmm hmmm hmmm hmmm hmmm hmmm again 
clang++ find1.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 
4 5 6 7 8 9 1 2 3 4 
g++ find1.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 
4 5 6 7 8 9 1 2 3 4 
clang++ find2.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 
the 4. element is the first greater than 3
the 3. element is the first divisible by 3
first value >=5: 5
g++ find2.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 
the 4. element is the first greater than 3
the 3. element is the first divisible by 3
first value >=5: 5
clang++ findend1.cpp -std=c++2a -Wall
coll:    1 2 3 4 5 6 7 1 2 3 4 5 6 7 
subcoll: 3 4 5 6 
subcoll found starting with element 10
subcoll found starting with element 3
g++ findend1.cpp -std=c++2a -Wall
coll:    1 2 3 4 5 6 7 1 2 3 4 5 6 7 
subcoll: 3 4 5 6 
subcoll found starting with element 10
subcoll found starting with element 3
clang++ findof1.cpp -std=c++2a -Wall
coll:       1 2 3 4 5 6 7 8 9 10 11 
searchcoll: 3 4 5 
first element of searchcoll in coll is element 3
last element of searchcoll in coll is element 5
g++ findof1.cpp -std=c++2a -Wall
coll:       1 2 3 4 5 6 7 8 9 10 11 
searchcoll: 3 4 5 
first element of searchcoll in coll is element 3
last element of searchcoll in coll is element 5
clang++ foreach1.cpp -std=c++2a -Wall
1 2 3 4 5 6 7 8 9 
g++ foreach1.cpp -std=c++2a -Wall
1 2 3 4 5 6 7 8 9 
clang++ foreach2.cpp -std=c++2a -Wall
11 12 13 14 15 16 17 18 19 
22 23 24 25 26 27 28 29 30 
g++ foreach2.cpp -std=c++2a -Wall
11 12 13 14 15 16 17 18 19 
22 23 24 25 26 27 28 29 30 
clang++ foreach3.cpp -std=c++2a -Wall
mean value: 4.5
g++ foreach3.cpp -std=c++2a -Wall
mean value: 4.5
clang++ generate1.cpp -std=c++2a -Wall
16807 282475249 1622650073 984943658 1144108930 
470211272 101027544 1457850878 1458777923 2007237709 
g++ generate1.cpp -std=c++2a -Wall
16807 282475249 1622650073 984943658 1144108930 
470211272 101027544 1457850878 1458777923 2007237709 
clang++ heap1.cpp -std=c++2a -Wall
on entry:           3 4 5 6 7 5 6 7 8 9 1 2 3 4 
after make_heap():  9 8 6 7 7 5 5 3 6 4 1 2 3 4 
after pop_heap():   8 7 6 6 7 5 5 3 4 4 1 2 3 
after push_heap():  17 7 8 6 7 5 6 3 4 4 1 2 3 5 
after sort_heap():  1 2 3 3 4 4 5 5 6 6 7 7 8 17 
g++ heap1.cpp -std=c++2a -Wall
on entry:           3 4 5 6 7 5 6 7 8 9 1 2 3 4 
after make_heap():  9 8 6 7 7 5 5 3 6 4 1 2 3 4 
after pop_heap():   8 7 6 7 4 5 5 3 6 4 1 2 3 
after push_heap():  17 7 8 7 4 5 6 3 6 4 1 2 3 5 
after sort_heap():  1 2 3 3 4 4 5 5 6 6 7 7 8 17 
clang++ includes1.cpp -std=c++2a -Wall
coll:   1 2 3 4 5 6 7 8 9 
search: 3 4 7 
all elements of search are also in coll
g++ includes1.cpp -std=c++2a -Wall
coll:   1 2 3 4 5 6 7 8 9 
search: 3 4 7 
all elements of search are also in coll
clang++ innerproduct1.cpp -std=c++2a -Wall
1 2 3 4 5 6 
inner product: 91
inner reverse product: 56
product of sums: 46080
g++ innerproduct1.cpp -std=c++2a -Wall
1 2 3 4 5 6 
inner product: 91
inner reverse product: 56
product of sums: 46080
clang++ inplacemerge1.cpp -std=c++2a -Wall
1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 
g++ inplacemerge1.cpp -std=c++2a -Wall
1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 
clang++ iota1.cpp -std=c++2a -Wall
coll: 42 43 44 45 46 47 48 49 50 51 
g++ iota1.cpp -std=c++2a -Wall
coll: 42 43 44 45 46 47 48 49 50 51 
clang++ isheap1.cpp -std=c++2a -Wall
coll1: 9 8 7 7 7 5 4 2 1 
coll2: 5 3 2 1 4 7 9 8 6 
coll1 is heap: true
coll2 is heap: false
first non-heap element: 4
g++ isheap1.cpp -std=c++2a -Wall
coll1: 9 8 7 7 7 5 4 2 1 
coll2: 5 3 2 1 4 7 9 8 6 
coll1 is heap: true
coll2 is heap: false
first non-heap element: 4
clang++ ispartitioned1.cpp -std=c++2a -Wall
coll: 5 3 9 1 3 4 8 2 6 
coll is partitioned
first even element: 4
g++ ispartitioned1.cpp -std=c++2a -Wall
coll: 5 3 9 1 3 4 8 2 6 
coll is partitioned
first even element: 4
clang++ ispermutation1.cpp -std=c++2a -Wall
coll1: 1 1 2 3 4 5 6 7 8 9 
coll2: 1 9 8 7 6 5 4 3 2 1 
coll3: 11 12 13 19 18 17 16 15 14 11 
coll1 and coll2 have equal elements
numbers of even and odd elements match
g++ ispermutation1.cpp -std=c++2a -Wall
coll1: 1 1 2 3 4 5 6 7 8 9 
coll2: 1 9 8 7 6 5 4 3 2 1 
coll3: 11 12 13 19 18 17 16 15 14 11 
coll1 and coll2 have equal elements
numbers of even and odd elements match
clang++ issorted1.cpp -std=c++2a -Wall
coll1: 1 1 2 3 4 5 6 7 8 9 
coll1 is sorted
coll2: [1,Bill] [2,Jim] [3,Nico] [4,Liu] [5,Ai] 
names in coll2 are not sorted
first unsorted name: Liu
g++ issorted1.cpp -std=c++2a -Wall
coll1: 1 1 2 3 4 5 6 7 8 9 
coll1 is sorted
coll2: [1,Bill] [2,Jim] [3,Nico] [4,Liu] [5,Ai] 
names in coll2 are not sorted
first unsorted name: Liu
clang++ lexicocmp1.cpp -std=c++2a -Wall
1 2 3 4 5 7 
1 2 3 4 5 
1 2 3 4 5 2 0 
1 2 3 4 5 2 
1 2 3 4 5 2 0 
1 2 3 4 5 7 
1 2 3 4 5 2 
1 2 3 4 5 

1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5 2 
1 2 3 4 5 2 
1 2 3 4 5 2 0 
1 2 3 4 5 2 0 
1 2 3 4 5 7 
1 2 3 4 5 7 
g++ lexicocmp1.cpp -std=c++2a -Wall
1 2 3 4 5 7 
1 2 3 4 5 
1 2 3 4 5 2 0 
1 2 3 4 5 2 
1 2 3 4 5 2 0 
1 2 3 4 5 7 
1 2 3 4 5 2 
1 2 3 4 5 

1 2 3 4 5 
1 2 3 4 5 
1 2 3 4 5 2 
1 2 3 4 5 2 
1 2 3 4 5 2 0 
1 2 3 4 5 2 0 
1 2 3 4 5 7 
1 2 3 4 5 7 
clang++ merge1.cpp -std=c++2a -Wall
coll1:  1 2 3 4 5 6 
coll2:  3 4 5 6 7 8 
merged: 1 2 3 3 4 4 5 5 6 6 7 8 
g++ merge1.cpp -std=c++2a -Wall
coll1:  1 2 3 4 5 6 
coll2:  3 4 5 6 7 8 
merged: 1 2 3 3 4 4 5 5 6 6 7 8 
clang++ minmax1.cpp -std=c++2a -Wall
2 3 4 5 6 -3 -2 -1 0 1 2 3 4 5 6 
minimum: -3
maximum: 6
min: -3
max: 6
distance: 9
minimum of absolute values: 0
maximum of absolute values: 6
g++ minmax1.cpp -std=c++2a -Wall
2 3 4 5 6 -3 -2 -1 0 1 2 3 4 5 6 
minimum: -3
maximum: 6
min: -3
max: 6
distance: 9
minimum of absolute values: 0
maximum of absolute values: 6
clang++ mismatch1.cpp -std=c++2a -Wall
coll1: 1 2 3 4 5 6 
coll2: 1 2 4 8 16 3 
first mismatch: 3 and 4
not less-or-equal: 6 and 3
g++ mismatch1.cpp -std=c++2a -Wall
coll1: 1 2 3 4 5 6 
coll2: 1 2 4 8 16 3 
first mismatch: 3 and 4
not less-or-equal: 6 and 3
clang++ move1.cpp -std=c++2a -Wall
Hello this is an example 
example an is this Hello 
g++ move1.cpp -std=c++2a -Wall
Hello this is an example 
example an is this Hello 
clang++ nthelement1.cpp -std=c++2a -Wall
3 4 5 6 7 2 3 4 5 6 1 2 3 4 5 
the four lowest elements are:  1 2 2 3 
the four highest elements are: 5 6 6 7 
the four highest elements are: 7 6 6 5 
g++ nthelement1.cpp -std=c++2a -Wall
3 4 5 6 7 2 3 4 5 6 1 2 3 4 5 
the four lowest elements are:  2 1 2 3 
the four highest elements are: 5 6 6 7 
the four highest elements are: 6 7 6 5 
clang++ partialsort1.cpp -std=c++2a -Wall
3 4 5 6 7 2 3 4 5 6 1 2 3 4 5 
1 2 2 3 3 7 6 5 5 6 4 4 3 4 5 
7 6 6 5 5 1 2 2 3 3 4 4 3 4 5 
1 2 2 3 3 3 4 4 4 5 5 5 6 6 7 
g++ partialsort1.cpp -std=c++2a -Wall
3 4 5 6 7 2 3 4 5 6 1 2 3 4 5 
1 2 2 3 3 7 6 5 5 6 4 4 3 4 5 
7 6 6 5 5 1 2 2 3 3 4 4 3 4 5 
1 2 2 3 3 3 4 4 4 5 5 5 6 6 7 
clang++ partialsort2.cpp -std=c++2a -Wall
3 4 5 6 7 2 3 4 5 6 1 2 3 4 5 
1 2 2 3 3 3 
7 6 6 5 5 5 4 4 4 3 3 3 2 2 1 
g++ partialsort2.cpp -std=c++2a -Wall
3 4 5 6 7 2 3 4 5 6 1 2 3 4 5 
1 2 2 3 3 3 
7 6 6 5 5 5 4 4 4 3 3 3 2 2 1 
clang++ partialsum1.cpp -std=c++2a -Wall
1 2 3 4 5 6 
1 3 6 10 15 21 
1 2 6 24 120 720 
g++ partialsum1.cpp -std=c++2a -Wall
1 2 3 4 5 6 
1 3 6 10 15 21 
1 2 6 24 120 720 
clang++ partition1.cpp -std=c++2a -Wall
coll1: 1 2 3 4 5 6 7 8 9 
coll2: 1 2 3 4 5 6 7 8 9 

coll1: 8 2 6 4 5 3 7 1 9 
first odd element: 5
coll2: 2 4 6 8 1 3 5 7 9 
first odd element: 1
g++ partition1.cpp -std=c++2a -Wall
coll1: 1 2 3 4 5 6 7 8 9 
coll2: 1 2 3 4 5 6 7 8 9 

coll1: 8 2 6 4 5 3 7 1 9 
first odd element: 5
coll2: 2 4 6 8 1 3 5 7 9 
first odd element: 1
clang++ partitioncopy1.cpp -std=c++2a -Wall
coll: 1 6 33 7 22 4 11 33 2 7 0 42 5 
evenColl: 6 22 4 2 0 42 
oddColl:  1 33 7 11 33 7 5 
g++ partitioncopy1.cpp -std=c++2a -Wall
coll: 1 6 33 7 22 4 11 33 2 7 0 42 5 
evenColl: 6 22 4 2 0 42 
oddColl:  1 33 7 11 33 7 5 
clang++ permutation1.cpp -std=c++2a -Wall
on entry:  1 2 3 
 1 3 2 
 2 1 3 
 2 3 1 
 3 1 2 
 3 2 1 
afterward: 1 2 3 
now:       3 2 1 
 3 1 2 
 2 3 1 
 2 1 3 
 1 3 2 
 1 2 3 
afterward: 3 2 1 
g++ permutation1.cpp -std=c++2a -Wall
on entry:  1 2 3 
 1 3 2 
 2 1 3 
 2 3 1 
 3 1 2 
 3 2 1 
afterward: 1 2 3 
now:       3 2 1 
 3 1 2 
 2 3 1 
 2 1 3 
 1 3 2 
 1 2 3 
afterward: 3 2 1 
clang++ randomshuffle1.cpp -std=c++2a -Wall
randomshuffle1.cpp:34:5: error: use of undeclared identifier 'random_shuffle'
    random_shuffle (coll.begin(), coll.end(),    // range
    ^
1 error generated.
g++ randomshuffle1.cpp -std=c++2a -Wall
coll:     1 2 3 4 5 6 7 8 9 
shuffled: 8 7 5 6 2 4 9 3 1 
clang++ relabs1.cpp -std=c++2a -Wall
coll:     17 -3 22 13 13 -9 
relative: 17 -20 25 -9 0 -22 
absolute: 17 -3 22 13 13 -9 
g++ relabs1.cpp -std=c++2a -Wall
coll:     17 -3 22 13 13 -9 
relative: 17 -20 25 -9 0 -22 
absolute: 17 -3 22 13 13 -9 
clang++ remove1.cpp -std=c++2a -Wall
coll:               2 3 4 5 6 4 5 6 7 8 9 1 2 3 4 5 6 7 
size not changed:   2 3 4 6 4 6 7 8 9 1 2 3 4 6 7 5 6 7 
size changed:       2 3 4 6 4 6 7 8 9 1 2 3 4 6 7 
<4 removed:         4 6 4 6 7 8 9 4 6 7 
g++ remove1.cpp -std=c++2a -Wall
coll:               2 3 4 5 6 4 5 6 7 8 9 1 2 3 4 5 6 7 
size not changed:   2 3 4 6 4 6 7 8 9 1 2 3 4 6 7 5 6 7 
size changed:       2 3 4 6 4 6 7 8 9 1 2 3 4 6 7 
<4 removed:         4 6 4 6 7 8 9 4 6 7 
clang++ remove2.cpp -std=c++2a -Wall
1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 
1 2 4 5 6 1 2 4 5 6 7 8 9 
1 2 3 4 1 2 3 4 
4 4 5 5 6 6 7 8 9 
g++ remove2.cpp -std=c++2a -Wall
1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 
1 2 4 5 6 1 2 4 5 6 7 8 9 
1 2 3 4 1 2 3 4 
4 4 5 5 6 6 7 8 9 
clang++ replace1.cpp -std=c++2a -Wall
coll: 2 3 4 5 6 7 4 5 6 7 8 9 
coll: 2 3 4 5 42 7 4 5 42 7 8 9 
coll: 0 0 0 5 42 7 0 5 42 7 8 9 
g++ replace1.cpp -std=c++2a -Wall
coll: 2 3 4 5 6 7 4 5 6 7 8 9 
coll: 2 3 4 5 42 7 4 5 42 7 8 9 
coll: 0 0 0 5 42 7 0 5 42 7 8 9 
clang++ replace2.cpp -std=c++2a -Wall
2 3 4 5 6 4 5 6 7 8 9 
2 3 4 55 6 4 55 6 7 8 9 
42 42 42 5 6 42 5 6 7 8 9 
2 0 4 0 6 4 0 6 0 8 0 
g++ replace2.cpp -std=c++2a -Wall
2 3 4 5 6 4 5 6 7 8 9 
2 3 4 55 6 4 55 6 7 8 9 
42 42 42 5 6 42 5 6 7 8 9 
2 0 4 0 6 4 0 6 0 8 0 
clang++ reverse1.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 
coll: 9 8 7 6 5 4 3 2 1 
coll: 9 2 3 4 5 6 7 8 1 
1 8 7 6 5 4 3 2 9 
g++ reverse1.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 
coll: 9 8 7 6 5 4 3 2 1 
coll: 9 2 3 4 5 6 7 8 1 
1 8 7 6 5 4 3 2 9 
clang++ rotate1.cpp -std=c++2a -Wall
coll:      1 2 3 4 5 6 7 8 9 
one left:  2 3 4 5 6 7 8 9 1 
two right: 9 1 2 3 4 5 6 7 8 
4 first:   4 5 6 7 8 9 1 2 3 
g++ rotate1.cpp -std=c++2a -Wall
coll:      1 2 3 4 5 6 7 8 9 
one left:  2 3 4 5 6 7 8 9 1 
two right: 9 1 2 3 4 5 6 7 8 
4 first:   4 5 6 7 8 9 1 2 3 
clang++ rotate2.cpp -std=c++2a -Wall
1 2 3 4 5 6 7 8 9 
2 3 4 5 6 7 8 9 1 
8 9 1 2 3 4 5 6 7 
4 5 6 7 8 9 1 2 3 
g++ rotate2.cpp -std=c++2a -Wall
1 2 3 4 5 6 7 8 9 
2 3 4 5 6 7 8 9 1 
8 9 1 2 3 4 5 6 7 
4 5 6 7 8 9 1 2 3 
clang++ search1.cpp -std=c++2a -Wall
coll:    1 2 3 4 5 6 7 1 2 3 4 5 6 7 
subcoll: 3 4 5 6 
subcoll found starting with element 3
subcoll found starting with element 10
g++ search1.cpp -std=c++2a -Wall
coll:    1 2 3 4 5 6 7 1 2 3 4 5 6 7 
subcoll: 3 4 5 6 
subcoll found starting with element 3
subcoll found starting with element 10
clang++ search2.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 
subrange found starting with element 2
subrange found starting with element 4
subrange found starting with element 6
g++ search2.cpp -std=c++2a -Wall
coll: 1 2 3 4 5 6 7 8 9 
subrange found starting with element 2
subrange found starting with element 4
subrange found starting with element 6
clang++ searchn1.cpp -std=c++2a -Wall
1 2 7 7 6 3 9 5 7 7 7 3 6 
three consecutive elements with value 7 start with 9. element
first four consecutive odd elements are: 3 9 5 7 
g++ searchn1.cpp -std=c++2a -Wall
1 2 7 7 6 3 9 5 7 7 7 3 6 
three consecutive elements with value 7 start with 9. element
first four consecutive odd elements are: 3 9 5 7 
clang++ shuffle1.cpp -std=c++2a -Wall
shuffle1.cpp:23:5: error: use of undeclared identifier 'random_shuffle'
    random_shuffle (coll.begin(), coll.end());
    ^
shuffle1.cpp:32:5: error: unknown type name 'default_random_engine'
    default_random_engine dre;
    ^
2 errors generated.
g++ shuffle1.cpp -std=c++2a -Wall
shuffle1.cpp: In function 'int main()':
shuffle1.cpp:32:5: error: 'default_random_engine' was not declared in this scope
     default_random_engine dre;
     ^~~~~~~~~~~~~~~~~~~~~
shuffle1.cpp:34:14: error: 'dre' was not declared in this scope
              dre);                      // random-number generator
              ^~~
clang++ sort1.cpp -std=c++2a -Wall
on entry: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 
sorted:   1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 
sorted >: 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 
g++ sort1.cpp -std=c++2a -Wall
on entry: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 
sorted:   1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 
sorted >: 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 
clang++ sort2.cpp -std=c++2a -Wall
on entry:
 1xxx 2x 3x 4x 5xx 6xxxx 7xx 8xxx 9xx 10xxx 11 12 13 14xx 15 16 17 

with sort():
 17 2x 3x 4x 16 15 13 12 11 9xx 5xx 7xx 8xxx 1xxx 14xx 6xxxx 10xxx 

with stable_sort():
 2x 3x 4x 11 12 13 15 16 17 5xx 7xx 9xx 1xxx 8xxx 14xx 6xxxx 10xxx 
g++ sort2.cpp -std=c++2a -Wall
on entry:
 1xxx 2x 3x 4x 5xx 6xxxx 7xx 8xxx 9xx 10xxx 11 12 13 14xx 15 16 17 

with sort():
 2x 17 16 15 13 12 11 4x 3x 9xx 7xx 5xx 8xxx 14xx 1xxx 10xxx 6xxxx 

with stable_sort():
 2x 3x 4x 11 12 13 15 16 17 5xx 7xx 9xx 1xxx 8xxx 14xx 6xxxx 10xxx 
clang++ sorted1.cpp -std=c++2a -Wall
c1:                         1 2 2 4 6 7 7 9 
c2:                         2 2 2 3 6 6 8 9 

merge():                    1 2 2 2 2 2 3 4 6 6 6 7 7 8 9 9 
set_union():                1 2 2 2 3 4 6 6 7 7 8 9 
set_intersection():         2 2 6 9 
set_difference():           1 4 7 7 
set_symmetric_difference(): 1 2 3 4 6 7 7 8 
g++ sorted1.cpp -std=c++2a -Wall
c1:                         1 2 2 4 6 7 7 9 
c2:                         2 2 2 3 6 6 8 9 

merge():                    1 2 2 2 2 2 3 4 6 6 6 7 7 8 9 9 
set_union():                1 2 2 2 3 4 6 6 7 7 8 9 
set_intersection():         2 2 6 9 
set_difference():           1 4 7 7 
set_symmetric_difference(): 1 2 3 4 6 7 7 8 
clang++ swapranges1.cpp -std=c++2a -Wall
coll1: 1 2 3 4 5 6 7 8 9 
coll2: 11 12 13 14 15 16 17 18 19 20 21 22 23 

coll1: 11 12 13 14 15 16 17 18 19 
coll2: 1 2 3 4 5 6 7 8 9 20 21 22 23 
first element not modified: 20

coll2: 23 22 21 4 5 6 7 8 9 20 3 2 1 
g++ swapranges1.cpp -std=c++2a -Wall
coll1: 1 2 3 4 5 6 7 8 9 
coll2: 11 12 13 14 15 16 17 18 19 20 21 22 23 

coll1: 11 12 13 14 15 16 17 18 19 
coll2: 1 2 3 4 5 6 7 8 9 20 21 22 23 
first element not modified: 20

coll2: 23 22 21 4 5 6 7 8 9 20 3 2 1 
clang++ transform1.cpp -std=c++2a -Wall
coll1:   1 2 3 4 5 6 7 8 9 
negated: -1 -2 -3 -4 -5 -6 -7 -8 -9 
coll2:   -10 -20 -30 -40 -50 -60 -70 -80 -90 
90 80 70 60 50 40 30 20 10 
g++ transform1.cpp -std=c++2a -Wall
coll1:   1 2 3 4 5 6 7 8 9 
negated: -1 -2 -3 -4 -5 -6 -7 -8 -9 
coll2:   -10 -20 -30 -40 -50 -60 -70 -80 -90 
90 80 70 60 50 40 30 20 10 
clang++ transform2.cpp -std=c++2a -Wall
coll1:   1 2 3 4 5 6 7 8 9 
squared: 1 4 9 16 25 36 49 64 81 
coll2:   82 68 58 52 50 52 58 68 82 
diff:    -81 -64 -49 -36 -25 -16 -9 -4 -1 
g++ transform2.cpp -std=c++2a -Wall
coll1:   1 2 3 4 5 6 7 8 9 
squared: 1 4 9 16 25 36 49 64 81 
coll2:   82 68 58 52 50 52 58 68 82 
diff:    -81 -64 -49 -36 -25 -16 -9 -4 -1 
clang++ unique1.cpp -std=c++2a -Wall
1 4 4 6 1 2 2 3 1 6 6 6 5 7 5 4 4 
1 4 6 1 2 3 1 6 5 7 5 4 

1 4 4 6 1 2 2 3 1 6 6 6 5 7 5 4 4 
1 4 4 6 6 6 6 7 
g++ unique1.cpp -std=c++2a -Wall
1 4 4 6 1 2 2 3 1 6 6 6 5 7 5 4 4 
1 4 6 1 2 3 1 6 5 7 5 4 

1 4 4 6 1 2 2 3 1 6 6 6 5 7 5 4 4 
1 4 4 6 6 6 6 7 
clang++ unique2.cpp -std=c++2a -Wall
1 4 4 6 1 2 2 3 1 6 6 6 5 7 5 4 4 
1 4 6 1 2 3 1 6 5 7 5 4 
1 4 4 6 1 3 1 6 6 6 4 4 
g++ unique2.cpp -std=c++2a -Wall
1 4 4 6 1 2 2 3 1 6 6 6 5 7 5 4 4 
1 4 6 1 2 3 1 6 5 7 5 4 
1 4 4 6 1 3 1 6 6 6 4 4 
clang++ unique3.cpp -std=c++2a -Wall
g++ unique3.cpp -std=c++2a -Wall

台本(script)

毎回コンパイル条件を変えてコンパイルするのに、一気にコンパイルする方法

cga.sh
#!/bin/bash
while read line
do
  echo "clang++ $line -std=c++2a -Wall"
  clang++ $line -std=c++2a -Wall 
  if [  -e a.out ]; then
  ./a.out
  rm a.out
  fi
  echo "g++ $line -std=c++2a -Wall"
  g++ $line -std=c++2a -Wall 
  if [  -e a.out ]; then
  ./a.out
  rm a.out
  fi
done < ./$1
do.sh
#!/bin/bash
while read line
do
 ls ./$line/*.cpp > ./$line/$line
 ./cga.sh ./$line/$line > $line.log.txt &> $line.log.txt
done < ./$1

検討事項(agenda)

1) コンパイルエラーをなくす修正方法
2) 役に立つまたは意味のあるその他の出力
3) 標準入力が必要なプログラムには入力設定できるように
C++N4606コンパイル用スクリプトには存在している。
どう全体の自動化と関係づけるか。
Cmakeする場合にCmake用のファイルをどう自動生成するか。

参考資料(reference)

プログラミング言語教育のXYZ

https://qiita.com/kaizen_nagoya/items/1950c5810fb5c0b07be4
プログラミング言語教育のXYZ(youtube)
https://www.youtube.com/watch?v=He1_tg4px-w&t=486s

C++N4741 2018

Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/n4741.pdf

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

C++N4606 2016

Working Draft, Standard for Programming Language C++
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf

C++N4606, 2016符号断片編纂一覧(example code compile list)
Working Draft 2016, ISO/IEC 14882(1)
https://qiita.com/kaizen_nagoya/items/df5d62c35bd6ed1c3d43/

 CEDD(Compile Error Driven Design)

初めての CEDD(Compile Error Driven Design) 8回直してコンパイル。
https://qiita.com/kaizen_nagoya/items/9494236aa1753f3fd1e1

コンパイルエラーを記録するとよい理由7つ
https://qiita.com/kaizen_nagoya/items/85c0e92b206883140e89
docker gnu(gcc/g++) and llvm(clang/clang++)
https://qiita.com/drafts/059874ea39c4de64c0f7

[C][C++]の国際規格案の例題をコンパイルするときの課題7つ。
https://qiita.com/kaizen_nagoya/items/5f4b155030259497c4de

C++N4606 Working Draft 2016, ISO/IEC 14882, C++ standardのコード断片をコンパイルするためにしていること
https://qiita.com/kaizen_nagoya/items/a8d7ee2f2e29e76c19c1

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da

Clang/Clang++(LLVM) gcc/g++(GNU) コンパイラ警告等比較
https://qiita.com/kaizen_nagoya/items/9a82b958cc3aeef0403f

C++2003とC++2017でコンパイルエラーになるならない事例集
https://qiita.com/kaizen_nagoya/items/a13ea3823441c430edff

Qiitaに投稿するCのStyle例(暫定)
https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d

cpprefjpのdecltypeをコンパイル試験
https://qiita.com/kaizen_nagoya/items/090909af702f0d5d8a67

MISRA C++ 5-0-16
https://qiita.com/kaizen_nagoya/items/7df2d4e05db724752a74

C++ Templates Part1 BASICS Chapter 3. Class Templates 3.2 Use of Class Template Stack stack1test.cpp
https://qiita.com/kaizen_nagoya/items/cd5fc49106fad5a4e9ed

ISO/IEC TS 17961:2013 C Secure Coding Rules(1) All list(to be confirmed)
https://qiita.com/kaizen_nagoya/items/54e056195c4f11b850a1

C言語(C++)に対する誤解、曲解、無理解、爽快。
https://qiita.com/kaizen_nagoya/items/3f3992c9722c1cee2e3a

C Puzzle Bookの有り難み5つ、C言語規格及びCコンパイラの特性を認識
https://qiita.com/kaizen_nagoya/items/d89a48c1536a02ecdec9

'wchar.h' file not found で困った clang++ macOS
https://qiita.com/kaizen_nagoya/items/de15cd46d657517fac11

Open POSIX Test Suiteの使い方を調べはじめました
https://qiita.com/kaizen_nagoya/items/644d5e407f5faf96e6dc

MISRA-C 2012 Referenceに掲載している文献の入手可能性を確認
https://qiita.com/kaizen_nagoya/items/96dc8b125e462d5575bb

どうやって MISRA Example Suiteをコンパイルするか
https://qiita.com/kaizen_nagoya/items/fbdbff5ff696e2ca7f00

MISRA C まとめ #include
https://qiita.com/kaizen_nagoya/items/f1a79a7cbd281607c7c9

「C++完全理解ガイド」の同意できること上位10
https://qiita.com/kaizen_nagoya/items/aa5744e0c4a8618c7671

文献履歴(document history)

ver. 0.10 初稿 20180616
ver. 0.11 まとめURL追記 20180625

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