summaryrefslogtreecommitdiff
path: root/redfish-core/include/utils/stl_utils.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'redfish-core/include/utils/stl_utils.hpp')
-rw-r--r--redfish-core/include/utils/stl_utils.hpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/redfish-core/include/utils/stl_utils.hpp b/redfish-core/include/utils/stl_utils.hpp
new file mode 100644
index 0000000000..04d02cbada
--- /dev/null
+++ b/redfish-core/include/utils/stl_utils.hpp
@@ -0,0 +1,39 @@
+#pragma once
+
+#include <algorithm>
+#include <string>
+
+namespace redfish
+{
+
+namespace stl_utils
+{
+
+template <typename ForwardIterator>
+ForwardIterator firstDuplicate(ForwardIterator first, ForwardIterator last)
+{
+ auto newLast = first;
+
+ for (auto current = first; current != last; ++current)
+ {
+ if (std::find(first, newLast, *current) == newLast)
+ {
+ if (newLast != current)
+ {
+ *newLast = *current;
+ }
+ ++newLast;
+ }
+ }
+
+ return newLast;
+}
+
+template <typename T>
+void removeDuplicate(T& t)
+{
+ t.erase(firstDuplicate(t.begin(), t.end()), t.end());
+}
+
+} // namespace stl_utils
+} // namespace redfish