LIMA
Libre Multilingual Analyzer — C++ API
Loading...
Searching...
No Matches
backport.h
Go to the documentation of this file.
1// Copyright 2002-2021 CEA LIST
2// SPDX-FileCopyrightText: 2022 CEA LIST <gael.de-chalendar@cea.fr>
3//
4// SPDX-License-Identifier: MIT
5
6#ifndef DEEPLIMA_INCLUDE_BACKPORT_H
7#define DEEPLIMA_INCLUDE_BACKPORT_H
8
9#include <unordered_map>
10
11namespace deeplima
12{
13namespace utils
14{
15namespace backport
16{
17
18// backport from C++ 20
19template<class K, class V, class H, class A, class P>
20typename std::unordered_map<K, V, H, A>::size_type erase_if(std::unordered_map<K, V, H, A>& c, P pred)
21{
22 auto old_size = c.size();
23 for (auto i = c.begin(), last = c.end(); i != last;) {
24 if (pred(*i)) {
25 i = c.erase(i);
26 } else {
27 ++i;
28 }
29 }
30 return old_size - c.size();
31}
32
33} // namespace backport
34} // namespace utils
35} // namespace deeplima
36
37#endif
std::unordered_map< K, V, H, A >::size_type erase_if(std::unordered_map< K, V, H, A > &c, P pred)
Definition backport.h:20