null+****@clear*****
null+****@clear*****
2012年 3月 16日 (金) 10:07:17 JST
Kouhei Sutou 2012-03-16 10:07:17 +0900 (Fri, 16 Mar 2012)
New Revision: 3ef9d87a324f17fbd9f224d20ef6a7900b690d95
Log:
doc coding-style: add about increment
Modified files:
doc/source/developer/coding_style.rst
Modified: doc/source/developer/coding_style.rst (+18 -0)
===================================================================
--- doc/source/developer/coding_style.rst 2012-03-16 10:02:21 +0900 (583e0ac)
+++ doc/source/developer/coding_style.rst 2012-03-16 10:07:17 +0900 (d234a1b)
@@ -520,3 +520,21 @@ C++では真偽値に ``bool`` を使うためこのような状況は発生し
name_ = std::string(name);
}
+インクリメント・デクリメント
+---------------------------
+
+前置形式を用いる
+^^^^^^^^^^^^^^^^
+
+後置形式ではオブジェクトのコピーをしなければいけないため非効率である。そのため、できるだけ前置形式を用いる。
+
+よい例( ``int`` だと効率は変わらないので本当はあんまりよい例ではない):
+
+ for (int i = 0; i < 10; ++i) {
+ }
+
+悪い例(後置形式を用いている):
+
+ for (int i = 0; i < 10; ++i) {
+ }
+