diff --git a/src/manager.cpp b/src/manager.cpp index 5bca738dd..ccf881419 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -2858,9 +2858,7 @@ Manager::getConferenceDetails( std::vector Manager::getConferenceList() const { - std::vector v; - map_utils::vectorFromMapKeys(pimpl_->conferenceMap_, v); - return v; + return map_utils::extractKeys(pimpl_->conferenceMap_); } std::vector diff --git a/src/map_utils.h b/src/map_utils.h index d4046a280..acc126ccd 100644 --- a/src/map_utils.h +++ b/src/map_utils.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2013-2017 Savoir-faire Linux Inc. + * Copyright (C) 2017 Savoir-faire Linux Inc. * - * Author: Tristan Matthews + * Author: Guillaume Roguez * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,37 +18,41 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef MAP_UTILS_H_ -#define MAP_UTILS_H_ +#pragma once #include -#include +#include +#include +#include namespace ring { namespace map_utils { -template -void vectorFromMapKeys(const M &m, V &v) +///< Return the N-th type of a tuple type used as the Container compliant value type +template +using type_element = typename std::remove_cv::type>::type; + +///< Extract in a std::vector object each N-th values of tuples contained in a Container compliant object \a container. +template +inline std::vector> +extractElements(const C& container) { - for (typename M::const_iterator it = m.begin(); it != m.end(); ++it) - v.push_back(it->first); + std::vector> result; + if (container.size() > 0) { + result.resize(container.size()); + auto iter = std::begin(container); + std::generate(std::begin(result), std::end(result), [&]{ return std::get(*iter++); }); + } + return result; } -template -void vectorFromMapValues(const M &m, V &v) -{ - for (typename M::const_iterator it = m.begin(); it != m.end(); ++it) - v.push_back(it->second); -} +template +inline auto +extractKeys(const M& map) -> decltype(extractElements<0>(map)) +{ return extractElements<0>(map); } -template -typename M::const_iterator -findByValue(const M &m, V &v) { - for (typename M::const_iterator it = m.begin(); it != m.end(); ++it) - if (it->second == v) - return it; - return m.cend(); -} +template +inline auto +extractValues(const M& map) -> decltype(extractElements<1>(map)) +{ return extractElements<1>(map); } }} // namespace ring::map_utils - -#endif // MAP_UTILS_H_