[[
with_index
]]
Xtal Unofficial Wiki
現在位置:
Xtal Unofficial Wiki
»
Xtal Reference
»
Iterator
»
with_index
文書の表示
以前のリビジョン
最近の変更
サイトマップ
ログイン
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== with_index ====== ===== Description ===== (index, it)を要素とするイテレータを返します。indexの値は//start//から始まって1ずつ増加していきます。 ===== Example ===== 乱数で初期化した配列のうち0.5よりも小さい要素のインデックスを列挙するサンプルです。 with_indexの後にもメソッドを連ねる場合も多いと思うので、それの一例としてfilterを連ねたサンプルも同時に掲載しておきます。 ==== C++ ==== ==== Xtal ==== <code cpp> array : []; 10.times{ array.push_back(math::random()); } array{ it.p; } "-----".p; array.with_index{|i, it| if (it < 0.5){ i.p; } } "-----".p; array.with_index.filter(|i, it| it<0.5){|i, it| i.p; } </code> ==== Output ==== <code> 0.383502 0.519416 0.830965 0.0345721 0.0534616 0.5297 0.671149 0.00769819 0.383416 0.0668422 ----- 0 3 4 7 8 9 ----- 0 3 4 7 8 9 </code>
reference/iterator/with_index.txt · 最終更新: 2011/07/15 09:11 by sukai
文書の表示
以前のリビジョン
文書の先頭へ