Ring Daemon 16.0.0
Loading...
Searching...
No Matches
map_utils.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <vector>
20#include <iterator>
21#include <algorithm>
22#include <tuple>
23
24namespace jami {
25namespace map_utils {
26
28template<typename C, std::size_t N>
30 typename std::remove_cv<typename std::tuple_element<N, typename C::value_type>::type>::type;
31
34template<std::size_t N, typename C>
35inline std::vector<type_element<C, N>>
37{
38 std::vector<type_element<C, N>> result;
39 if (container.size() > 0) {
40 result.resize(container.size());
41 auto iter = std::begin(container);
42 std::generate(std::begin(result), std::end(result), [&] { return std::get<N>(*iter++); });
43 }
44 return result;
45}
46
47template<typename M>
48inline auto
49extractKeys(const M& map) -> decltype(extractElements<0>(map))
50{
51 return extractElements<0>(map);
52}
53
54template<typename M>
55inline auto
56extractValues(const M& map) -> decltype(extractElements<1>(map))
57{
58 return extractElements<1>(map);
59}
60
61} // namespace map_utils
62} // namespace jami
typename std::remove_cv< typename std::tuple_element< N, typename C::value_type >::type >::type type_element
Extract in a std::vector object each N-th values of tuples contained in a Container compliant object ...
Definition map_utils.h:33
auto extractValues(const M &map) -> decltype(extractElements< 1 >(map))
Definition map_utils.h:56
std::vector< type_element< C, N > > extractElements(const C &container)
Definition map_utils.h:36
auto extractKeys(const M &map) -> decltype(extractElements< 0 >(map))
Definition map_utils.h:49
void emitSignal(Args... args)
Definition ring_signal.h:64