| 1 |
#include <iostream> |
| 2 |
#include <string> |
| 3 |
#include <vector> |
| 4 |
#include <list> |
| 5 |
#include <queue> |
| 6 |
#include <algorithm> |
| 7 |
#include <iterator> |
| 8 |
|
| 9 |
#include "placementalloc.h" |
| 10 |
#include "plainalloc.h" |
| 11 |
#include "newalloc.h" |
| 12 |
|
| 13 |
#include "storage.h" |
| 14 |
|
| 15 |
using namespace std; |
| 16 |
|
| 17 |
int main(int argc, char **argv) |
| 18 |
{ |
| 19 |
switch (argv[1][0]) |
| 20 |
{ |
| 21 |
default: |
| 22 |
cout << "Provide argument to read from stdin:\n" |
| 23 |
"n: read strings, using NewAlloc with a vector\n" |
| 24 |
"p: read strings, using PlacementAlloc with a deque\n" |
| 25 |
"s: read ints, using a simple PlainAlloc with a list\n"; |
| 26 |
break; |
| 27 |
|
| 28 |
case 'n': |
| 29 |
{ |
| 30 |
Storage<string, NewAlloc, std::vector> storage; |
| 31 |
|
| 32 |
copy(istream_iterator<string>(cin), istream_iterator<string>(), |
| 33 |
back_inserter(storage)); |
| 34 |
|
| 35 |
cout << "Element index 1 is " << storage[1] << '\n'; |
| 36 |
storage[1] = "hello"; |
| 37 |
|
| 38 |
copy(storage.begin(), storage.end(), |
| 39 |
ostream_iterator<NewAlloc<string> >(cout, "\n")); |
| 40 |
} |
| 41 |
break; |
| 42 |
|
| 43 |
case 'p': |
| 44 |
{ |
| 45 |
Storage<string, PlacementAlloc, deque> storage; |
| 46 |
|
| 47 |
copy(istream_iterator<string>(cin), istream_iterator<string>(), |
| 48 |
back_inserter(storage)); |
| 49 |
|
| 50 |
copy(storage.begin(), storage.end(), |
| 51 |
ostream_iterator<PlacementAlloc<string> >(cout, "\n")); |
| 52 |
} |
| 53 |
break; |
| 54 |
|
| 55 |
case 's': |
| 56 |
{ |
| 57 |
Storage<int, PlainAlloc, list> storage; |
| 58 |
|
| 59 |
copy(istream_iterator<int>(cin), istream_iterator<int>(), |
| 60 |
back_inserter(storage)); |
| 61 |
|
| 62 |
copy(storage.begin(), storage.end(), |
| 63 |
ostream_iterator<PlainAlloc<int> >(cout, "\n")); |
| 64 |
} |
| 65 |
break; |
| 66 |
} |
| 67 |
} |