1 #pragma once 2 3 #include <algorithm> 4 #include <vector> 5 6 namespace redfish 7 { 8 9 namespace stl_utils 10 { 11 12 template <typename ForwardIterator> 13 ForwardIterator firstDuplicate(ForwardIterator first, ForwardIterator last) 14 { 15 auto newLast = first; 16 17 for (auto current = first; current != last; ++current) 18 { 19 if (std::find(first, newLast, *current) == newLast) 20 { 21 if (newLast != current) 22 { 23 *newLast = *current; 24 } 25 ++newLast; 26 } 27 } 28 29 return newLast; 30 } 31 32 template <typename T> 33 void removeDuplicate(T& t) 34 { 35 t.erase(firstDuplicate(t.begin(), t.end()), t.end()); 36 } 37 38 } // namespace stl_utils 39 } // namespace redfish 40