/src/libreoffice/include/o3tl/vector_utils.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | */ |
10 | | |
11 | | #pragma once |
12 | | |
13 | | #include <algorithm> |
14 | | #include <unordered_set> |
15 | | #include <vector> |
16 | | |
17 | | namespace o3tl |
18 | | { |
19 | | // removes duplicated elements in a vector |
20 | | template <typename T> void remove_duplicates(std::vector<T>& rVector) |
21 | 0 | { |
22 | 0 | std::unordered_set<T> aSet; |
23 | 0 | auto aEnd = std::copy_if(rVector.begin(), rVector.end(), rVector.begin(), |
24 | 0 | [&aSet](T const& rElement) { return aSet.insert(rElement).second; }); |
25 | 0 | rVector.erase(aEnd, rVector.end()); |
26 | 0 | } |
27 | | } |
28 | | |
29 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |