Skip to content

Commit

Permalink
コンパイルエラー、及び実行時の出力が異なるものを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Jul 23, 2013
1 parent dd27c0a commit 3ce4a01
Show file tree
Hide file tree
Showing 43 changed files with 114 additions and 85 deletions.
9 changes: 3 additions & 6 deletions reference/algorithm/copy_n.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,15 @@ OutputIterator copy_n(InputIterator first, Size n, OutputIterator result) {
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>

int main() {
std::copy_n(std::istream_iterator<int>(std::cin), 5, std::ostream_iterator<int>(std::cout, "\n"));
std::vector<int> v = { 3, 1, 5, 2, 4 };
std::copy_n(v.begin(), 5, std::ostream_iterator<int>(std::cout, "\n"));
}
```
* copy_n[color ff0000]

###入力
```
3 1 5 2 4
```

###出力
```
3
Expand Down
2 changes: 1 addition & 1 deletion reference/algorithm/find_if_not.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ InputIterator find_if_not(InputIterator first, InputIterator last, Predicate pre
int main() {
std::vector<int> v = { 3, 1, 4 };
// 3ではない最初の要素を検索する
auto result = std::find_if_not<code style='color:black'>(v.begin(), v.end(), [](int x) { return x == 3; });
auto result = std::find_if_not(v.begin(), v.end(), [](int x) { return x == 3; });
if (result == v.end()) {
std::cout << "not found" << std::endl;
} else {
Expand Down
4 changes: 3 additions & 1 deletion reference/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ int main()

###出力
```
425
4
2
5
```

##バージョン
Expand Down
3 changes: 2 additions & 1 deletion reference/atomic/atomic.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ int main()

###出力例
```
21
2
1
```


Expand Down
3 changes: 2 additions & 1 deletion reference/atomic/atomic_flag.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ int main()

###出力例
```
21
2
1
```


Expand Down
5 changes: 5 additions & 0 deletions reference/atomic/memory_order.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ int main()
* memory_order_acquire[color ff0000]
* memory_order_release[color ff0000]

###出力
```
3
```

[`atomic<bool>`](./atomic.md)型の変数`ready`への読み書きに注目すると、`main()`では変数`ready`に `true` を"release"操作として書き込み、`f()`では"acquire"操作としての読み込みを `true` が返されるまで繰り返している。よって、`f()`の`while`ループを抜けた時点で、`main()`の`ready.store()`と`f()`の`ready.load()`の間に順序付け(happens before関係)が成立している。
ここでさらに変数`data`への読み書き(1), (2)に注目すると、(1)は`ready.store()`より前、(2)は`ready.load()`より後にあるので、以下のようなスレッド間の順序付け(happens before関係)が成立することになる。
(1) → `ready.store()` → `ready.load()` → (2)
Expand Down
2 changes: 1 addition & 1 deletion reference/chrono/system_clock/now.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main()

###出力例
```
Tue Sep 27 14:21:13 2011
1374586804
```

##バージョン
Expand Down
2 changes: 1 addition & 1 deletion reference/climits/char_bit.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
int main()
{
std::cout << CHA_BIT << '\n';
std::cout << CHAR_BIT << '\n';
}
```

Expand Down
1 change: 1 addition & 0 deletions reference/condition_variable/condition_variable_any.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ int main()

###出力
```
process data
```

##バージョン
Expand Down
14 changes: 7 additions & 7 deletions reference/cstddef/nullptr_t.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ namespace std {
int main()
{
std::cout << "sieof(nullptr_t): " << sizeof(std::nullptr_t) << std::endl; // equals to sizeof(void*)
std::cout << "sizeof(nullptr_t): " << sizeof(std::nullptr_t) << std::endl; // equals to sizeof(void*)
std::cout << "is_object<nullptr_t>: " << std::is_object<std::nullptr_t>::value << std::endl;
std::cout << "is_scalar<nullptr_t>: " << std::is_scalar<std::nullptr_t>::value << std::endl; // 0 on VS2012
std::cout << "is_union<nullptr_t>: " << std::is_union<std::nullptr_t>::value << std::endl;
std::cout << "is_array<nullptr_t>: " << std::is_array<std::nullptr_t>::value << std::endl;
std::cout << "is_class<nullptr_t>: " << std::is_class<std::nullptr_t>::value << std::endl;
std::cout << "is_scalar<nullptr_t>: " << std::is_scalar<std::nullptr_t>::value << std::endl; // 0 on VS2012
std::cout << "is_union<nullptr_t>: " << std::is_union<std::nullptr_t>::value << std::endl;
std::cout << "is_array<nullptr_t>: " << std::is_array<std::nullptr_t>::value << std::endl;
std::cout << "is_class<nullptr_t>: " << std::is_class<std::nullptr_t>::value << std::endl;
}
```

###出力
```
sieof(nullptr_t): 4
sizeof(nullptr_t): 4
is_object<nullptr_t>: 1
is_scalar<nullptr_t>: 1
is_union<nullptr_t>: 0
Expand Down
3 changes: 2 additions & 1 deletion reference/deque.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ int main()

###出力
```
31
3
1
```

###参照
Expand Down
3 changes: 2 additions & 1 deletion reference/deque/at.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ int main()

###出力
```
42 42 42 0 0
2
out of range!
```

##参照
Expand Down
3 changes: 1 addition & 2 deletions reference/deque/get_allocator.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ int main ()

###出力
```
42
84
42 84
```

##参照
Expand Down
3 changes: 2 additions & 1 deletion reference/forward_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ int main()

###出力
```
31
3
1
```

##バージョン
Expand Down
3 changes: 2 additions & 1 deletion reference/functional/reference_wrapper/ctor.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ int main()

###出力
```
45
4
5
```

##バージョン
Expand Down
3 changes: 2 additions & 1 deletion reference/functional/reference_wrapper/op_assign.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ int main()

###出力
```
36
3
6
```

##バージョン
Expand Down
3 changes: 2 additions & 1 deletion reference/future/shared_future.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ int main()

###出力
```
33
3
3
```

##バージョン
Expand Down
3 changes: 2 additions & 1 deletion reference/future/shared_future/get.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ int main()

###出力例
```
thread:0 sum:15thread:1 sum:40
thread:0 sum:15
thread:1 sum:40
```

##バージョン
Expand Down
4 changes: 3 additions & 1 deletion reference/iterator/back_insert_iterator.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ int main()

###出力
```
123
1
2
3
```

###参照
Expand Down
4 changes: 3 additions & 1 deletion reference/iterator/front_insert_iterator.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ int main()

###出力
```
321
3
2
1
```

###参照
Expand Down
6 changes: 5 additions & 1 deletion reference/iterator/reverse_iterator.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ int main()

###出力
```
54321
5
4
3
2
1
```

###参照
Expand Down
4 changes: 2 additions & 2 deletions reference/map/find.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ int main()
c.insert(std::make_pair(1,'a'));
cout << (c.find(1) == c.end()) << endl;
cout << (c.find(2) == c.end()) << endl;
cout << (c.find(1) != c.end()) << endl;
cout << (c.find(2) != c.end()) << endl;
return 0;
}
```
Expand Down
3 changes: 2 additions & 1 deletion reference/mutex/unique_lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ int main()

###出力例
```
21
2
1
```

##バージョン
Expand Down
2 changes: 2 additions & 0 deletions reference/mutex/unique_lock/try_lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ int main()

###出力
```
terminate called after throwing an instance of 'std::system_error'
what(): Device or resource busy
```

##バージョン
Expand Down
4 changes: 2 additions & 2 deletions reference/random/discrete_distribution/reset.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ int main()
std::discrete_distribution<> dist = {0.1, 0.2, 0.3};

for (int i = 0; i < 5; ++i) {
dist.reset(); // 前回生成までの状態をリセット
std::cout << dist(engine) << std::endl;
dist.reset(); // 前回生成までの状態をリセット
std::cout << dist(engine) << std::endl;
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions reference/set/find.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ int main()
c.insert(10);
cout << (c.find(10) == c.end()) << endl;
cout << (c.find(42) == c.end()) << endl;
cout << (c.find(10) != c.end()) << endl;
cout << (c.find(42) != c.end()) << endl;
return 0;
}
```
Expand Down
4 changes: 2 additions & 2 deletions reference/stack/emplace.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ int main ()

##出力
```
stack::push 0 copy 1 copy 2 copy 3 copy 4 copy
stack::emplace 0 1 2 3 4
stack::push 0 move 1 move 2 move 3 move 4 move
stack::emplace 0 1 2 3 4
```

##参照
Expand Down
1 change: 1 addition & 0 deletions reference/thread/thread/get_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ id get_id() const noexcept;
##例
```cpp
#include <thread>
#include <cassert>

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion reference/thread/thread/op_assign.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ thread& operator=(thread&& x) noexcept;
##例
```cpp
#include <thread>
#include <cassert>

int main()
{
Expand All @@ -40,7 +41,6 @@ int main()
assert(!th1.joinable() && th2.joinable());

th2.join();
return;
}
```
* th2 = std::move(th1);[color ff0000]
Expand Down
3 changes: 2 additions & 1 deletion reference/thread/thread/thread.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ thread(thread&&) noexcept;
```cpp
#include <memory>
#include <thread>
#include <cassert>
int func(int v, int& ri, std::shared_ptr<int> sp, std::unique_ptr<int> up)
{
Expand All @@ -67,7 +68,7 @@ int func(int v, int& ri, std::shared_ptr<int> sp, std::unique_ptr<int> up)
int main()
{
int i1, i2 = 0; std::shared_ptr<int> sp0 = std::make_shared(5);
int i1, i2 = 0; std::shared_ptr<int> sp0 = std::make_shared<int>(5);
std::unique_ptr<int> up0(new int(2));
std::thread thd( func, i1, std::ref(i2), sp0, std::move(up0) );
Expand Down
4 changes: 2 additions & 2 deletions reference/typeinfo/bad_typeid.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ int main()
Polymorphic* p = 0;
// オブジェクトpは Polymorphic* 型
std::cout << "1: " << typeid(p) << std::endl;
std::cout << "1: " << typeid(p).name() << std::endl;
// ヌルポインタを指すオブジェクトを間接参照してtypeid演算子に渡す...
std::cout << "2: " << typeid(*p) << std::endl;
std::cout << "2: " << typeid(*p).name() << std::endl;
}
catch (std::bad_typeid& e) {
std::cerr << e.what() << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion reference/unordered_map/unordered_map/cend.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main()

mymap um{ { "1st", 1 }, { "2nd", 2 }, { "3rd", 3 }, };

std::for_each(us.cbegin(), us.cend(), [](mymap::value_type p) { std::cout << '{' << p.first << ',' << p.second << "}, "; });
std::for_each(um.cbegin(), um.cend(), [](mymap::value_type p) { std::cout << '{' << p.first << ',' << p.second << "}, "; });
std::cout << std::endl;
}
```
Expand Down
6 changes: 4 additions & 2 deletions reference/unordered_map/unordered_map/empty.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ int main()
// 空
std::cout << um.empty() << std::endl;

um.[emplace](emplace)("1st", 1);
um.emplace("1st", 1);

// 空ではない
std::cout << um.empty() << std::endl;

um.[clear](clear)();
um.clear();

// 空
std::cout << um.empty() << std::endl;
Expand All @@ -49,6 +49,8 @@ int main()
* iostream[link /reference/iostream]
* string[link /reference/string.md]
* unordered_map[link /reference/unordered_map.md]
* emplace[link emplace.md]
* clear[link clear.md]

###出力
```
Expand Down
Loading

0 comments on commit 3ce4a01

Please sign in to comment.