1 #ifndef CARMA_UTIL_STLCONTAINERUTILS_H
2 #define CARMA_UTIL_STLCONTAINERUTILS_H
22 template <
typename C >
31 template <
typename C >
35 template <
typename K,
typename V >
36 ::std::multimap< V, K > invertToMultimap( const ::std::map< K, V > & in );
39 template <
typename K,
typename V >
40 ::std::multimap< V, K > invertToMultimap( const ::std::multimap< K, V > & in );
45 template <
typename K,
typename V >
46 ::std::set< K >
keys( const ::std::map< K, V > & in );
50 template <
typename K,
typename V >
51 ::std::set< K >
keys( const ::std::multimap< K, V > & in );
56 template<
typename T >
57 typename T::first_type operator()(T keyValuePair )
const {
58 return keyValuePair.first;
67 template <
typename C >
74 typename C::const_iterator i = c.begin();
78 return (i == c.end());
82 template <
typename C >
89 typename C::const_iterator i = c.begin();
93 return (i == c.end());
97 template <
typename K,
typename V >
98 ::std::multimap< V, K >
99 carma::util::invertToMultimap( const ::std::map< K, V > & in )
101 ::std::multimap< V, K > out;
103 typename ::std::map< K, V >::const_iterator i = in.begin();
104 const typename ::std::map< K, V >::const_iterator iEnd = in.end();
106 for ( ; i != iEnd; ++i )
107 out.insert( ::std::make_pair( i->second, i->first ) );
113 template <
typename K,
typename V >
114 ::std::multimap< V, K >
115 carma::util::invertToMultimap( const ::std::multimap< K, V > & in )
117 ::std::multimap< V, K > out;
119 typename ::std::multimap< K, V >::const_iterator i = in.begin();
120 const typename ::std::multimap< K, V >::const_iterator iEnd = in.end();
122 for ( ; i != iEnd; ++i )
123 out.insert( ::std::make_pair( i->second, i->first ) );
128 template <
typename K,
typename V >
132 transform( in.begin(), in.end(),
133 inserter( out, out.begin() ), RetrieveKey()
138 template <
typename K,
typename V >
144 transform( in.begin(), in.end(),
145 inserter( out, out.begin() ), RetrieveKey()
bool sizeIsOneOrLess(const C &)
Constant time check that a container has no more than one element.
bool sizeIsExactlyOne(const C &)
Constant time check that a container has exactly one element.
Struct which operators on a container key-value pair to retrieve the key.
::std::set< K > keys(const ::std::map< K, V > &in)
Return the keys of a map as a set.