Sprout を使った簡単な constexpr counting_iterator

Sprout の index_iterator で簡単に実装出来そうだったのでちょっと試してみた。

[ソース]

#define SPROUT_CONFIG_SUPPORT_TEMPORARY_CONTAINER_ITERATION
#include <sprout/algorithm/transform.hpp>
#include <sprout/iterator/index_iterator.hpp>
#include <sprout/array.hpp>
#include <sprout/pit.hpp>
#include <iostream>

template<typename IndexType>
struct dummy : sprout::array<IndexType, 1>{
    typedef IndexType reference;
    typedef IndexType size_type;

    constexpr IndexType
    at(IndexType i) const{
        return i;
    }

    constexpr IndexType
    operator[](IndexType i) const{
        return i;
    }
};

template<typename IndexType>
constexpr sprout::index_iterator<dummy<IndexType>>
counting_iterator(IndexType index){
    return { dummy<IndexType>{}, index };
}

constexpr int
twice(int n){
    return n + n;
}

int
main(){
    static constexpr auto result = sprout::transform(
        counting_iterator(-5),
        counting_iterator(5),
        sprout::pit<sprout::array<int, 10>>(),
        twice
    );

    for(auto&& n : result){
        std::cout << n << std::endl;
    }

    return 0;
}

[出力]

-10
-8
-6
-4
-2
0
2
4
6
8

とりあえず、簡単に書いてみた。
型を定義するのが手間だったので、sprout:array を継承してごまかしている。

[コンパイラ]

  • g++ (GCC) 4.7.0 20111210 (experimental)

unite-checking-global-variables

名前が無駄に長いんですが、0 と 1 のグローバル変数を unite.vim で編集する unite-source です。
要はチェックボックスですね。
元々は unite.vimチェックボックスを記述する為のテストソースとして書いていたんですが、そのままでも使えそうだったのでプラグインにしてみました。
(既にその手のプラグインはありそうですが。

[Vimプラグイン]

NeoBundle "git://github.com/osyo-manga/checking-global-variables.git"

[使い方]

:Unite checking-global-variables

で選択した変数の ON/OFF(0/1) が設定されます。
unite.vim を終了する場合は q で。


[既存の問題]

アクションメニュー(a) から action を選ぶと画面が更新されません。
で手動更新して下さい。
(この場合に更新するタイミングが分からなかったのよね…。
修正しました。
あとソートを行う関係で [x] で絞り込みも出来ません。