2014-02-05から1日間の記事一覧

auto使うとラムダ書きやすい

C++

これでいいんだっていう。 #include <iostream> #include <functional> int main() { auto lambda = [](int x, int y) -> int { return x + y; }; auto f = std::bind(lambda, std::placeholders::_1, 10); std::cout << f(1) << std::endl; return 0; } 実行結果 11</functional></iostream>

Xを越える最初のコンテナの要素へのイテレーターを返す

C++

毎回関数オブジェクト使ってたんだけどlower_boundってのがあるんだなって。 lower_boundは"以上(>=)"なんだけど、"より大きい(>)"をやるには同様にupper_boundってのがあるのか。 #include <iostream> #include <vector> #include <algorithm> int main() { //適当なデータ std::vector<double> x</double></algorithm></vector></iostream>…