Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:13

0001 // name=std__unique ; gcc $name.cc -std=c++11 -lstdc++ -o /tmp/$name && /tmp/$name
0002 
0003 // C++ program to demonstrate the use of std::unique
0004 #include <algorithm>
0005 #include <iostream>
0006 #include <vector>
0007 
0008 using namespace std;
0009 
0010 int main()
0011 {
0012     vector<int> v = { 1, 1, 3, 3, 3, 10, 1, 3, 3, 7, 7, 8 };
0013 
0014     vector<int>::iterator ip;
0015 
0016     // Using std::unique
0017     ip = std::unique(v.begin(), v.begin() + 12);
0018     // Now v becomes {1 3 10 1 3 7 8 * * * * *}
0019     // * means undefined
0020 
0021     // Resizing the vector so as to remove the undefined
0022     // terms
0023     v.resize(std::distance(v.begin(), ip));
0024 
0025     // Displaying the vector after applying std::unique
0026     for (ip = v.begin(); ip != v.end(); ++ip) {
0027         cout << *ip << " ";
0028     }
0029 
0030     return 0;
0031 }