Rokiのチラ裏

学生による学習のログ

2016-06-19から1日間の記事一覧

エイリアステンプレート

C++

なんだか忘れてしまっていたのか、知らなかったのか分からないが、便利なのでメモメモ。 template<class _Tp,class Allocator=std::allocator<_Tp>> std::vector<_Tp,Allocator> twice(std::vector<_Tp,Allocator> v) { for(typename std::vector<_Tp,Allocator>::iterator i=std::begin(v); i!=std::end(v); ++i)*i*=2; // なんだか視覚的にわかりにくい</_tp,allocator></_tp,allocator></_tp,allocator></class>…

初期化lambdaキャプチャー

C++

こんなものがあったのか。知らなかったのでメモ。 まず、初期化lambdaキャプチャーにより、以下のように書ける。 #include<functional> int main() { typedef std::function<int()> function_i; int data{}; function_i f=[i=data]{return i;},g=[data=data]{return data;}, h=[</int()></functional>…