Skip to content

Commit b20b2ee

Browse files
committed
Update comment-tricks.md
1 parent fab7ca8 commit b20b2ee

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/articles/comment-tricks.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ int main()
103103
値の切り替えの範囲版です。
104104
スラッシュ / の有無に応じて、前半、後半どちらかの範囲を選択します。
105105

106+
#### パターン 1
107+
106108
``` C++ tab="前半"
107109
#include <iostream>
108110

@@ -145,6 +147,51 @@ int main()
145147
}
146148
```
147149

150+
#### パターン 2
151+
152+
``` C++ tab="前半"
153+
#include <iostream>
154+
155+
int main()
156+
{
157+
//*
158+
int x;
159+
160+
std::cin >> x;
161+
162+
std::cout << x * x;
163+
/*/
164+
int x, y;
165+
166+
std::cin >> x >> y;
167+
168+
std::cout << x + y;
169+
//*/
170+
}
171+
```
172+
173+
``` C++ tab="後半"
174+
#include <iostream>
175+
176+
int main()
177+
{
178+
/*
179+
int x;
180+
181+
std::cin >> x;
182+
183+
std::cout << x * x;
184+
/*/
185+
int x, y;
186+
187+
std::cin >> x >> y;
188+
189+
std::cout << x + y;
190+
//*/
191+
}
192+
```
193+
194+
148195
## 行の入れ替えの防止
149196

150197
リファクタリング時に、コピー&ペーストで行の順番を入れ替えてしまうことを防ぎます。

0 commit comments

Comments
 (0)