C++11 から begin() と end() と言う面白い関数が出来た ― 2020年04月20日 12時07分32秒
基本的にはコンテナ型の様に使うのだが、配列の様に純粋なコンテナ型では無いものにも使える。
整数型の配列を cout で出力できる。
#include <iterator>
#include <iostream>
#include <algorithm>
int main()
{
int numbers[] = { 1, 2, 3, 4, -2, 5, 0, -1 };
std::for_each( numbers, std::end( numbers ),
[]( int i ) { std::cout << i << std::endl; } );
}
% c++ -std=c++11 end.cpp
% ./a.out
1
2
3
4
-2
5
0
-1
最近のコメント