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