C++11標準ライブラリに新しく追加されたアルゴリズムstd::iota
についてメモ。
- シーケンス要素へ昇順で連続値を代入するアルゴリズム。
- 最初は
itoa
かと思い「なぜに今更?標準化したの?」 - ギリシャ文字の ι/イオタ から来ているらしい。江添さんの本の虫 が詳しい。
- Boost.Rangeライブラリには Rangeベース版iota が存在する。
#include <algorithm> int a[5]; std::iota(a, a+5, 1); // a == {1,2,3,4,5}
#include <boost/range/algorithm_ext/iota.hpp> int a[5]; boost::iota(a, 1); // a == {1,2,3,4,5}
関連URL