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

clang_complete で insert 時に する問題が修正された

関連:最新の clang_complete で insert 時に <CR> するとエラーになる clang_complete 側で修正されたみたいなので vimrc で再マッピングしなくてもエラーは出なくなりました。 早めに対応してもらってよかった。</cr>

C++11 むずい

C++

問.次のコードを実行すると何が出力されるでしょうか。 [ソース] #include <iostream> template<typename T> void func(T&&){ std::cout << "T&&" << std::endl; } struct X{}; void func(X const&){ std::cout << "X const&" << std::endl; } int main(){ X x; func(x); func(X{}</typename></iostream>…

Sprout::Weed の lim を短くする

特定の文字列をパースする場合に Sprout::Weed の lim を使用して *w::lim<4>(w::char_ - ':') >> ":" >> *w::lim<2>(w::char_) の様なパーサを定義するんですが、これだと若干長くなってしまいます。 これはこれで汎用性があっていいのですが、簡単なパーサ…

C++11 で boost::mpl::identity

C++

元々は std::identity として標準ライブラリに入る予定だったんですが、残念ながら削除されてしまいました。 と、いうことで現行の仕様だと std::common_type で代替出来ると聞いたのでやってみました。 [ソース] #include <type_traits> #include <iostream> char func(int n){ ret</iostream></type_traits>…

最新の clang_complete で insert 時に するとエラーになる

clang_complete で insert 時に するとマッピングによってはエラーが出る場合があるみたいです。 原因はここら辺ぽい。 特に neocomplcache を使用していると inoremap <expr><CR> neocomplcache#close_popup() . "\<CR>" とマッピングしている人がいると思うので、この場</cr></cr></expr>…

Sprout.Weed で複数行のパース

[ソース] #include <sprout/weed.hpp> int main(){ namespace w = sprout::weed; using sprout::make_common_array; using sprout::to_string; static constexpr auto width = 16; static constexpr auto height = 16; static constexpr auto string = *w::lim<width>(w::char_ - w::</width></sprout/weed.hpp>…

Vim でスワップファイルの削除

vim

大量にファイルを開いている時に Vim が死ぬととても悲しい事になるので簡単な Vim script を書きました。 [ソース] function! s:remove_swapfile() let target = &directory let list = split(glob(target."**/*.*.sw{p,o}"), '\n') echo "remove" for file…

Experimental Clang Binaries for Mingw32/x86 でコンパイラが死んだ\(^o^)/

[再現コード] template<typename T, int N> struct array{ T elems[ N ]; }; template<typename T, typename ...Args> array<T, sizeof...(Args)> make_array(Args... args){ return {{ args... }}; } int main(){ make_array<int>(1, 2, 3, 4); return 0; } [コンパイル出力] Assertion failed: isa<LabelDecl>(D) && "declaration not…</labeldecl></int></t,></typename></typename>

LLVM 3.1 がリリース

予定であれば先週リリース予定であった LLVM 3.1 がやっとこさリリースされました!!! これでもう llvm.org を F5 アタックする簡単なお仕事が終わりました。 Download LLVM 3.1 LLVM 3.1 Release Notes Clang 3.1 Release Notes あと一番気になっていた L…

C++Now! の資料をいくつか読んで

着々と C++Now! の資料が github で公開されているのでチラホラと読んでいます。 まだ全然読めていないんですが、気になったものをいくつか上げてみたいと思います。 基本的にコードしか読んでいないので間違っているかも知れませんがきっと気のせいです。 …

Boost.Xpressive で対応した文字で一括置換

少し前にコメントで教えていただいたので覚書。 [ソース] #include <boost/xpressive/xpressive.hpp> #include <boost/xpressive/regex_actions.hpp> #include <map> int main(){ namespace x = boost::xpressive; using x::_; std::map<std::string, std::string> m = { { "(", "[ " }, { ")", " ]" }, }; x::local<std::string const*> pstr; x::sr…</std::string></std::string,></map></boost/xpressive/regex_actions.hpp></boost/xpressive/xpressive.hpp>

Vim 上で Visual Studio 11 Beta を使ってコンパイルする

そういえば、やってなかったと思い設定しました。 基本的にはこれと同じように正しく PATH を設定するだけですね。 " 使用する msvc を設定 let $VSINSTALLDIR="C:/Program Files/Microsoft Visual Studio 11.0" let $VCINSTALLDIR=$VSINSTALLDIR."/VC" let …

(」・ω・)」リポジトリ!(/・ω・)/つくった!

vim

以前つくったこれを github に上げました。 そういえば、quickrun 関係でリポジトリ作るのは初めてかもしれない。 [プラグイン] quickrun-hook-u-nya- - github :NeoBundle "git://github.com/osyo-manga/quickrun-hook-u-nya-.git" [vimrc] " quickrun_conf…

C++Now! 2012 の資料

C++

下記の github に上がっています。 件の Metaparse の資料なども上がっているので、気になっている方は目を通してみるとよろしいかと思います。 cppnow_presentations_2012 - github

C++11 でコンパイル時に外部のファイルを読み込む

C++

まぁ #include を使用するのですが。 外部ファイルを文字列として読み込む必要があるので、外部ファイルに少し手を加える必要があります。 C++11 であれば raw string literal が使用できるので多少マシになりますね。 [ソース] #include <iostream> #include <string> int mai</string></iostream>…

metaparse の meta_hs を使って C++ で Haskell を書く

と、いうことで C++なうで注目を浴び、巷で話題沸騰中の metaparse で Haskell を書いてみました。 まぁ Haskell はあんまり書けないんですけどね! [metaparse] metaparse.pdf - github meta_hs - github [ソース] #define BOOST_MPL_LIMIT_STRING_SIZE 50 …

Boost.Xpressive で HTML タグの中身とタグ名を取得する

こんな感じで簡単に取得出来るみたい。 [ソース] #define _SCL_SECURE_NO_WARNINGS #include <iostream> #include <boost/xpressive/xpressive.hpp> #include <boost/xpressive/xpressive_static.hpp> int main(){ namespace x = boost::xpressive; using x::s1; using x::_w; using x::_; // タグで囲まれた文字列を取得 x::mark_tag in_tag(</boost/xpressive/xpressive_static.hpp></boost/xpressive/xpressive.hpp></iostream>…

LLVM/Clang 3.1 で追加される予定の C++11 の機能

一応、まだリリース前なのですが、これでほぼ間違いないでしょう。 LLVM/Clang 3.1 では新しく下記の C++11 の機能が実装されました。 [Language Feature] Initializer lists Lambda expressions Declared type of an expression - Incomplete return types …

Boost.Xpressive のセマンティックアクションで整数を受け取る

as を使用します。 [ソース] #include <boost/xpressive/xpressive.hpp> #include <boost/xpressive/regex_actions.hpp> int main(){ namespace x = boost::xpressive; using x::_; int n = 0; x::sregex regex = ("(" >> (x::s1 = -*_) >> ")")[ x::ref(n) = x::as<int>(x::s1) ]; std::string const source = "(1234)"; if( x::rege…</int></boost/xpressive/regex_actions.hpp></boost/xpressive/xpressive.hpp>

Boost.Xpressive でセマンティックアクション

こんなことが出来るみたい。 [ソース] #include <boost/xpressive/xpressive.hpp> #include <boost/xpressive/regex_actions.hpp> #include <string> int main(){ namespace x = boost::xpressive; using x::_; std::string result; x::sregex regex = "(" >> ((x::s1 = -*_)[x::ref(result) = x::s1]) >> ")"; std::string const source</string></boost/xpressive/regex_actions.hpp></boost/xpressive/xpressive.hpp>…

Boost で文字列の置換

boost::algorithm::replace_all_copy あたりを使うのが楽そう。 [ソース] #include <boost/algorithm/string.hpp> #include <iostream> int main(){ std::string source = "homuhomuhomu"; // 結果をコピーして返す auto result1 = boost::algorithm::replace_all_copy(source, "homu", "mado"); st</iostream></boost/algorithm/string.hpp>…

Vim で自動的にヘッダーを include する

面白いプラグインがあったので紹介。 vim-cpp-auto-include : Automatically insert or delete `#include`s for C++ code - vim.org vim-cpp-auto-include - github github に gif 動画が上がっているので、それを見てもらえれば何となく分かると思うのです…

Boost.Filesystem でディレクトリ内の全てのファイルを走査する

Boost.Filesystem の directory_iterator ではディレクトリ直下のファイルしか走査しませんが、recursive_directory_iterator を使用すれば全てのファイルを走査します。 [ソース] #include <iostream> #include <boost/filesystem.hpp> #include <boost/range/algorithm/for_each.hpp> int main(){ namespace f = boost::filesyst</boost/range/algorithm/for_each.hpp></boost/filesystem.hpp></iostream>…

unite-neobundle でアカウント名で絞込み

vim

unite-neobundle を使用している時にアカウント名(主に "Shougo" で)絞込みを行いたい事がよくあるんですが、実装してもらったのでご紹介。 こんな感じでアカウント名で絞込みを行うことが出来るようになりました。

(」・ω・)」quick!(/・ω・)/run!

vim

かわいい。 [quickrun-hook] "unite-hook-u-nya- {{{ let s:hook = { \ "name" : "u_nya_", \ "kind" : "hook", \ "index_counter" : 0, \ "config" : { \ "enable" : 0 \} \} function! s:hook.on_ready(session, context) let self.index_counter = -2 end…

quickrun.vim 0.6.0 でアニメーション

vim

id:thinca さんに無理やり脅して実装してもらいました。 これで quickrun.vim でもアニメーションが出来るようになりました!! [quickrun-hook] "unite-hook-banban {{{ let s:hook = { \ "name" : "banban", \ "kind" : "hook", \ "index_counter" : 0, \ …

quickrun.vim 0.6.0

vim

quickrun.vim 0.6.0 リリース予告 - 永遠に未完成 と、いうことで近々 quickrun.vim 0.6.0 がリリース予定ということなので先取りして遊んでみました。 また、quickrun.vim 0.6.0 に移行するにあたっていくつか破壊的な変更が行われているので、上記のサイト…

真のプログラマを目指す人が使うべきたった一つのエディタ

vim

世界中にエディタと呼ばれるものはたくさんあるので、自分の手で自分にあったエディタを見つけて(創りあげて)下さい。 例え Vim を使っている人が世界中に何十億人いても、あなたが使っている Vim は世界に一つだけなのですから。

AtCoder #002 の A を解いてみた

参加はしていなかったんですが、終わったあとに問題を見かけたので解いてみました。 [ソース] #include <cstddef> #include <boost/preprocessor/repetition/enum.hpp> // // static print // template<std::size_t Index, typename String> constexpr char at_c(String const& str){ return Index >= str.length() ? char('\0') : str[Index]; } te</std::size_t></boost/preprocessor/repetition/enum.hpp></cstddef>…

Boost.Xpressive で () の中身を取り出す

mark_tag を使用して、マッチした位置の文字列を取得することが出来ます。 [ソース] #define _SCL_SECURE_NO_WARNINGS #include <iostream> #include <boost/xpressive/xpressive.hpp> int main(){ namespace x = boost::xpressive; x::mark_tag name(1); x::sregex regex = "(" >> (name = -*x::_) >></boost/xpressive/xpressive.hpp></iostream>…