Line data Source code
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 : 24 : namespace jami { 25 : namespace map_utils { 26 : 27 : ///< Return the N-th type of a tuple type used as the Container compliant value type 28 : template<typename C, std::size_t N> 29 : using type_element = typename std::remove_cv<typename std::tuple_element<N, typename C::value_type>::type>::type; 30 : 31 : ///< Extract in a std::vector object each N-th values of tuples contained in a Container compliant 32 : ///< object \a container. 33 : template<std::size_t N, typename C> 34 : inline std::vector<type_element<C, N>> 35 2 : extractElements(const C& container) 36 : { 37 2 : std::vector<type_element<C, N>> result; 38 2 : if (container.size() > 0) { 39 2 : result.resize(container.size()); 40 2 : auto iter = std::begin(container); 41 17 : std::generate(std::begin(result), std::end(result), [&] { return std::get<N>(*iter++); }); 42 : } 43 2 : return result; 44 0 : } 45 : 46 : template<typename M> 47 : inline auto 48 1 : extractKeys(const M& map) -> decltype(extractElements<0>(map)) 49 : { 50 1 : return extractElements<0>(map); 51 : } 52 : 53 : template<typename M> 54 : inline auto 55 1 : extractValues(const M& map) -> decltype(extractElements<1>(map)) 56 : { 57 1 : return extractElements<1>(map); 58 : } 59 : 60 : } // namespace map_utils 61 : } // namespace jami