| 1 |
#include <iostream> |
| 2 |
#include <algorithm> |
| 3 |
#include <vector> |
| 4 |
#include <string> |
| 5 |
#include <iterator> |
| 6 |
|
| 7 |
using namespace std; |
| 8 |
|
| 9 |
size_t fstNonEmpty(vector<string> const &vs) |
| 10 |
{ |
| 11 |
return |
| 12 |
find_if(vs.begin(), vs.end(), |
| 13 |
[&](string const &str) |
| 14 |
{ |
| 15 |
return str != ""; |
| 16 |
} |
| 17 |
) - vs.begin(); |
| 18 |
} |
| 19 |
|
| 20 |
int main() |
| 21 |
{ |
| 22 |
vector<string> vs; |
| 23 |
|
| 24 |
copy(istream_iterator<string>(cin), istream_iterator<string>(), |
| 25 |
back_inserter(vs)); |
| 26 |
|
| 27 |
cout << "vs contains " << vs.size() << " words\n" |
| 28 |
"first non-empty word at index " << fstNonEmpty(vs) << "\n" |
| 29 |
"moving the first half into vector v2\n"; |
| 30 |
|
| 31 |
vector<string> v2{ make_move_iterator(vs.begin()), |
| 32 |
make_move_iterator(vs.begin() + vs.size() / 2) }; |
| 33 |
|
| 34 |
cout << "vs contains " << vs.size() << " words\n" |
| 35 |
"first non-empty word at index " << fstNonEmpty(vs) << "\n" |
| 36 |
"v2 contains " << v2.size() << " words\n"; |
| 37 |
} |