Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
unique.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for copy, unique_copy
30#include <iostream> // for cout, endl
31#include <iterator> // for insert_iterator, ostream_iterator
32#include <vector> // for vector
33
34int main ()
35{
36 // for convenience
37 typedef std::vector<int, std::allocator<int> > Vector;
38 typedef std::insert_iterator<Vector> Iter;
39 typedef std::ostream_iterator<Vector::value_type, char,
40 std::char_traits<char> > OSIter;
41
42 // Initialize two vectors.
43 const int a1 [] = {
44 4, 5, 5, 9, -1, -1, -1, 3, 7, 5,
45 5, 5, 6, 7, 7, 7, 4, 2, 1, 1
46 };
47
48 Vector v (a1, a1 + sizeof a1 / sizeof *a1);
50
51 // Create an insert_iterator for results.
52 Iter ins (result, result.begin ());
53
54 // Demonstrate includes.
55 std::cout << "The vector: " << std::endl << " ";
56
57 std::copy (v.begin (), v.end (), OSIter (std::cout, " "));
58
59 // Find the unique elements.
60 std::unique_copy(v.begin(), v.end(), ins);
61
62 // Display the results.
63 std::cout << "\n\nHas the following unique elements:\n ";
64
65 std::copy (result.begin (), result.end (), OSIter (std::cout, " "));
66 std::cout << std::endl;
67
68 return 0;
69}
#define v
Definition 17.names.cpp:138
#define a1
Definition 17.names.cpp:225
volatile int result
std::vector< UserClass, std::allocator< UserClass > > Vector
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition alg7.cpp:64
int main()
Definition unique.cpp:34