diff options
author | Noel Grandin <noel@peralex.com> | 2015-11-19 13:43:23 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-11-20 08:14:13 +0000 |
commit | fe3fd05966a668c1cdf53e8221b8614e9a07de65 (patch) | |
tree | 4c6c105b78d0cb9c45431c2fecd2583d6a2aa85c /include | |
parent | 1d5c39192e81f950289dbdd7991a0e8a67c0aabc (diff) |
add mapKeysToSequence/mapValuesToSequence methods to comphelper
and use them
Change-Id: If4dc9df63db37185228aeaaab2979498d61304ec
Reviewed-on: https://gerrit.libreoffice.org/20055
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/comphelper/sequence.hxx | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/comphelper/sequence.hxx b/include/comphelper/sequence.hxx index 47bf0c5af9c4..17d1b67c0d64 100644 --- a/include/comphelper/sequence.hxx +++ b/include/comphelper/sequence.hxx @@ -369,6 +369,31 @@ namespace comphelper return o_Output; } + /** Copy (keys or values) from a associate container into a Sequence + + @tpl M map container type eg. std::map/std::unordered_map + + @return the generated Sequence + */ + template < typename M > + inline css::uno::Sequence< typename M::key_type > mapKeysToSequence( M const& map ) + { + css::uno::Sequence< typename M::key_type > ret( static_cast<sal_Int32>(map.size()) ); + typename M::key_type* pArray = ret.getArray(); + for (const auto& i : map) + *pArray++ = i.first; + return ret; + } + + template < typename M > + inline css::uno::Sequence< typename M::mapped_type > mapValuesToSequence( M const& map ) + { + css::uno::Sequence< typename M::mapped_type > ret( static_cast<sal_Int32>(map.size()) ); + typename M::mapped_type* pArray = ret.getArray(); + for (const auto& i : map) + *pArray++ = i.second; + return ret; + } } // namespace comphelper |