2012-04-01から1ヶ月間の記事一覧

Sprout.IO

Sprout に IO を扱うライブラリが追加されたのでちょっと触ってみた。 ちなみにまだ Input はないらしい。 詳細については id:boleros さんの記事を参照して下さい。 Sprout.Io - とりあえず文字列へ変換/コンパイル時のパフォーマンスとバッファサイズの話…

fstream に Boost.Filesystem の path を渡す

Boost.Filesystem に path を受け取る fstream が定義されているらしいです。 [ソース] #include <boost/filesystem.hpp> #include <boost/filesystem/fstream.hpp> int main(int argc, char const* argv[]){ namespace fs = boost::filesystem; fs::path exe = argv[0]; fs::ifstream ifs(exe.parent_path()/"mai</boost/filesystem/fstream.hpp></boost/filesystem.hpp>…

Boost.Xpressive で検索位置を走査する

Boost.Spirit.Qi ではなく、Boost.Xpressive で。 sregex_iterator を使用します。 [ソース] #include <boost/xpressive/xpressive.hpp> #include <functional> #include <string> int main(){ namespace x = boost::xpressive; using x::_; std::string source = " (homu) (mado) (mami)"; // () の位置と中身を</string></functional></boost/xpressive/xpressive.hpp>…

C++ で関数名のエイリアス

C++

たまに欲しくなるので、ちょっと考えてみた。 [ソース] #include <numeric> #include <algorithm> #include <iterator> #include <iostream> #include <type_traits> #define FUNCNAME_ALIASES(target, name) \ struct { \ template<typename ...Args> \ auto \ operator ()(Args&&... args) const \ ->decltype(target(std::forward<Args>(</args></typename></type_traits></iostream></iterator></algorithm></numeric>…

unite-source で soruce 独自の値を初期化する

vim

ちょっと前に教えてもらったので覚書。 unite-source で独自の値を保持する場合、hooks.init で context に対して値を代入すれば初期化する事が出来ます。 [unite-source] let s:RAND_MAX = 32767 let s:seed = 4239 function! s:rand() let s:seed = s:seed…

Boost.Spirit.Qi のセマンティックアクションで std::string を受け取る

文字列をパースする場合、*qi::char_ のようなパーサを定義すると思いますが、これだと std::vector で受け取る必要があります。 auto parser = '(' >> *(qi::char_ - ')') >> ')'; test_parser("(madohomu)", parser[[](std::vector<char> const& v){ // }]); こ</char>…

constexpr で Brainfuck

とりあえず、Sprout を使って書いてみました。 Sprout まじ Sprout。 あんまり効率とかは考えないでベタが出来ですが、入力から出力までをコンパイル時に行います。 そういえば constexpr で Brainfuck の実装は見かけたことがないような? [ソース] #includ…

Sprout で配列の指定した位置に値を代入する

sprout::set({cont}, {inx}, {v}); を使用します。 [ソース] #include <sprout/operation/set.hpp> #include <sprout/array.hpp> int main(){ constexpr auto source = sprout::make_array<int>(1, 2, 3, 4); constexpr auto result = sprout::set(source, 3, -1); static_assert(result == sprout::make_array<int></int></int></sprout/array.hpp></sprout/operation/set.hpp>…

Sprout を使った constexpr stringstream

ちょっと欲しかったので簡単に書いてみました。 [ソース] #include <sprout/string.hpp> #include <sprout/operation.hpp> template<std::size_t Size, typename String = sprout::string<Size>> struct basic_stringstream{ constexpr String const& str() const{ return string; } String string; }; typedef basic_stringstream<0> stringstream; …</std::size_t></sprout/operation.hpp></sprout/string.hpp>

Sprout で指定した値で配列の初期化を行う

sprout::fill を使用します。 [ソース] #include <sprout/array.hpp> #include <sprout/algorithm/fill.hpp> #include <sprout/algorithm/fill_n.hpp> #include <sprout/pit.hpp> int main(){ // 今回は、初期化時に fill して欲しいので // 処理結果の型を sprout::pit でラップして引数に渡す static constexpr auto result = sprout::fill(sprout::pit</sprout/pit.hpp></sprout/algorithm/fill_n.hpp></sprout/algorithm/fill.hpp></sprout/array.hpp>

三┌(┌ ^ o^)三┌(┌ ^ o^)三┌(┌ ^ o^)

vim

Vimに這いよるホモォ - KaoriYa ,'.: 〃 ,:1 , __/ // / } , ', __彡ァ 乂_ノ :! ,′ ./ ̄/7=‐.、__ノノ ,'∧ ' .. / /i::, { 彳ア:::抃< ( (、__,/' i } ,'/リ., ,イ ./`¨´i.|:∧. 、 .c弋匕Z_ >、_`ヽ、」 ,' _彡'厶イ./iヽ,′ |:::∧ {?// ア:::抃、 | / / i|:::{: `…

ホモォ…┌(^o^┐)┐三

vim

元ネタ:Vimに這いよる混沌 こうですかわかりません>< [vim-homo-statusline] vim-homo-statusline - github :NeoBundle "git://github.com/osyo-manga/vim-homo-statusline.git" . .: : : : : : : : :: :::: :: :: : :::::::::::::::::::::::::::::::::::…

三┌(┌ ^o^)┐ホモォ…

vim

ついカッとなってやった後悔はしている。 [unite-homo] unite-homo - github :NeoBundle "git://github.com/osyo-manga/unite-homo.git" . .: : : : : : : : :: :::: :: :: : ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: . . : : : :: : :…

unite-u-nya- つくった (」・ω・)」うー!(/・ω・)/にゃー!

vim

(」・ω・)」うー!(/・ω・)/にゃー! [github] unite-u-nya- :NeoBundle "git://github.com/osyo-manga/unite-u-nya-.git" [おまけ] 引数を渡せば好きな文字を出力したり。

コンパイル時 FizzBuzz の出力

コンパイル時に FizzBuzz を処理して出力までするのは中3女子の嗜みですよね! ということでこれを使って、とりあえずコンパイル時にも出力してみた。 Sprout のコードは適当。 [ソース] #include <boost/preprocessor/repetition/enum.hpp> #include <boost/mpl/print.hpp> #include <sprout/algorithm/transform.hpp> #include <sprout/array.hpp> #include <sprout/string.hpp> #include </sprout/string.hpp></sprout/array.hpp></sprout/algorithm/transform.hpp></boost/mpl/print.hpp></boost/preprocessor/repetition/enum.hpp>

quickrun.vim で外部コマンドを非同期で実行する

quickrun.vim では vimproc を使用して、外部コマンドを非同期で実行する事が出来ます。 また outputter を作成することで外部コマンド実行後に任意の Vim script を処理する事も出来ます。 と、いうことで実際に quickrun.vim で c-index-test.exe を非同期…

clang 3.1(trunk) で Concurrency がいくつか実装された

clang 3.1(trunk) で Concurrency がいくつか実装されました。 実装されたのは以下の3つです。 Atomic operations Bidirectional Fences Allow atomics use in signal handlers こっちの方はあまり確認していなかったのでもしかしたら以前から実装されていた…

Vim script で文字列の足し込み

文字列の足し込みは += や -= のように .= という演算子が使えます。 [ソース] let s:sum = "" for var in range(5) let s:sum .= "homu" endfor echo s:sum [出力] homuhomuhomuhomuhomu [注意] この演算子は Vim 7.0 から実装されたらしいので、それ以下の…

Vim script の exists で autoload の関数は判定してはいけない

言われてみればそのとおりなんですが、ちょっとはまったので覚書。 Vim script では、ある変数や関数などが定義されているかを判定するために exists({expr}) という組み込み関数を使用します。 使い方は簡単で引数に定義されている変数名や関数名などを渡し…

clang_complete でランタイムエラーが出た場合の対処方法

clang_complete で libclang.dll を使用する場合に Vim の終了時にランタイムエラーが出るという問題があるそうです。 対処方法は cmake に下記のオプションを追加してビルドして下さい。 [gcc 4.5.x] cmake.exe -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_…

※webapi-vim のネームスペースが変更されました

vim

webapi-vim のネームスペースを変えました。 - Big Sky 先週も告知しましたが webapi-vim のネームスペースが変更されました。 最新版の webapi-vim では以前の関数(http#get 等)が既に削除されていますので、まだ最新版の webapi-vim に対応していないVimプ…

clang_declared.vim を Vimプラグイン化した

[追記] リポジトリ名が typo ってたので変更しました。 既に git clone した方はお手数ですが再度取得し直して下さい。 (ノ∀`)アチャー [追記2] オプション名も typo していたので修正しました。 しにたい。 先日作成した c-index-test を使用した C++ の宣言に飛…

コンパイル時に Sprout.String を出力する

先日行ったやり方で、コンパイル時に Sprout.String の内容を出力してみました。 [ソース] #include <boost/preprocessor/repetition/enum.hpp> #include <sprout/string.hpp> template<std::size_t Index, typename String> constexpr char at_c(String const& str){ return Index >= str.length() ? char('\0') : str[Index]; } template<char... cs> struc…</char...></std::size_t></sprout/string.hpp></boost/preprocessor/repetition/enum.hpp>

Boost.Fusion を使用して構造体から boost::array への変換

Boost.Fusion にアダプトすれば出来るかなーと思って試してみたら問題なく変換されました。 [ソース] #include <boost/array.hpp> #include <boost/fusion/adapted/boost_array.hpp> #include <boost/fusion/adapted/struct/adapt_struct.hpp> #include <boost/fusion/include/adapt_struct.hpp> struct vec{ float x; float y; float z; }; BOOST_FUSION_ADAPT_STR…</boost/fusion/include/adapt_struct.hpp></boost/fusion/adapted/struct/adapt_struct.hpp></boost/fusion/adapted/boost_array.hpp></boost/array.hpp>

文字列から型への変換

C++

mpllibs のコードを見ていて、ふと思いついたのでやってみました。 [ソース] #include <boost/preprocessor/enum.hpp> #include <boost/mpl/vector_c.hpp> #include <boost/mpl/string.hpp> template<std::size_t Index, typename Char, typename std::size_t N> constexpr Char at_c(Char (&str)[N]){ return Index >= N ? Char('\0') : str[Index]; } #d…</std::size_t></boost/mpl/string.hpp></boost/mpl/vector_c.hpp></boost/preprocessor/enum.hpp>

LLVM 3.1 は 5月14日にリリース予定

The LLVM Compiler Infrastructure LLVM 3.1 リリースまでのスケジュールは以下の通り。 4月16日 - Branching for 3.1 release 4月16日〜4月22日 - Phase 1 testing 4月23日〜4月29日 - Bug fixing for Phase 1 issues, all features completed 4月30日〜5月…

Vim で C++ の宣言箇所へ飛ぶ

libclangを使ってみる。 - only 1 truth 上記のサイトで初めて知ったんですが、llvm/clang に含まれている c-index-test という tools を使用すれば C++ で宣言位置を取得する事が出来るみたいなので、Vim script で簡単に実装してみました。 c-index-test.e…

webapi-vimのネームスペースが変更される

vim

webapi-vimのネームスペースを変えようかと思っています。 - Big Sky 既に mattn さんのブログや Twitter で告知されていますが、webapi-vim に対して破壊的な変更が行われます。 わたしのつくったプラグインで影響があるのは『unite-boost-online-doc』だけ…

Metaparse である mpllibs を触ってみる

C++

今年開催される『C++Now! 2012』のセッションの一つに 『テンプレートメタプログラミングによるコンパイル時構文解析』 なるものが存在しているのですが、github でライブラリが公開されていたのでちょっとつついてみました。 mpllibs - github とりあえず、…

闇鍋プログラミング勉強会へのスニーキングミッション

/: : : : : |: : : : : : : : : : : : : : : : : : : :ヽ : : : : : : : |: : : : : : : : : : : : : : : : : :ヽ: : :ヽ : : : : : : : : : {: : : : : : : : ヽ: : : : : : : : : :ヽ: : ヘ /: : : : : : : :{: :ハ: : : : ヽ: : : ヽ: : : : : : :ヽ: : ヘ …