OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
ContainerHelper.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// std header
9#include <map>
10#include <list>
11
12namespace ot {
13
19 template <typename K, typename V> std::list<K> listFromMapKeys(const std::map<K, V>& _map);
20
26 template <typename K, typename V> std::list<V> listFromMapValues(const std::map<K, V>& _map);
27
33 template <class K, class V> void removeFromMapByValue(std::map<K, V>& _map, const V& _value);
34
35 template <typename T> std::vector<T> vectorFromList(const std::list<T>& _list);
36 template <typename T> std::list<T> listFromVector(const std::vector<T>& _vector);
37}
38
39template <typename K, typename V>
40std::list<K> ot::listFromMapKeys(const std::map<K, V>& _map) {
41 std::list<K> result;
42
43 for (const auto& it : _map) {
44 result.push_back(it.first);
45 }
46
47 return std::move(result);
48}
49
50template <typename K, typename V>
51std::list<V> ot::listFromMapValues(const std::map<K, V>& _map) {
52 std::list<V> result;
53
54 for (const auto& it : _map) {
55 result.push_back(it.second);
56 }
57
58 return std::move(result);
59}
60
61template <class K, class V>
62void ot::removeFromMapByValue(std::map<K, V>& _map, const V& _value) {
63 for (auto it = _map.begin(); it != _map.end(); ) {
64 if (it->second == _value) {
65 it = _map.erase(it);
66 }
67 else {
68 it++;
69 }
70 }
71}
72
73template <typename T>
74std::vector<T> ot::vectorFromList(const std::list<T>& _list) {
75 std::vector<T> result;
76 result.reserve(_list.size());
77 for (const T& entry : _list) {
78 result.push_back(entry);
79 }
80 return result;
81}
82
83template <typename T>
84std::list<T> ot::listFromVector(const std::vector<T>& _vector) {
85 std::list<T> result;
86 for (const T& entry : _vector) {
87 result.push_back(entry);
88 }
89 return result;
90}
int result
Definition dllmain.cpp:82
Definition Connector.h:8
std::list< K > listFromMapKeys(const std::map< K, V > &_map)
Creates a list containing all the keys from the provided map.
Definition ContainerHelper.h:40
void removeFromMapByValue(std::map< K, V > &_map, const V &_value)
Removes the value from the provided map.
Definition ContainerHelper.h:62
std::vector< T > vectorFromList(const std::list< T > &_list)
Definition ContainerHelper.h:74
std::list< V > listFromMapValues(const std::map< K, V > &_map)
Creates a list containing all the values from the provided map.
Definition ContainerHelper.h:51
std::list< T > listFromVector(const std::vector< T > &_vector)
Definition ContainerHelper.h:84