Main MRPT website > C++ reference for MRPT 1.4.0
stl_containers_utils.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <list>
12 #include <map>
13 #include <set>
14 
15 namespace mrpt
16 {
17  namespace utils
18  {
19  /** \addtogroup stlext_grp
20  * @{ */
21 
22  /** Returns the index of the value "T" in the container "vect" (std::vector,std::deque,etc), or string::npos if not found.
23  */
24  template <class T,class CONTAINER>
25  size_t find_in_vector(const T &value, const CONTAINER &vect)
26  {
27  typename CONTAINER::const_iterator last = vect.end();
28  for (typename CONTAINER::const_iterator i=vect.begin();i!=last;++i)
29  if (*i==value) return std::distance(vect.begin(),i);
30  return std::string::npos;
31  }
32 
33  /** Calls the standard "erase" method of a STL container, but also returns an iterator to the next element in the container (or ::end if none) */
34  template <class T> inline typename std::list<T>::iterator erase_return_next(std::list<T> &cont, typename std::list<T>::iterator &it)
35  {
36  return cont.erase(it);
37  }
38  //! \overload
39  template <class K,class V> inline typename std::map<K,V>::iterator erase_return_next(std::map<K,V> &cont, typename std::map<K,V>::iterator &it)
40  {
41  typename std::map<K,V>::iterator itRet = it; ++itRet;
42  cont.erase(it);
43  return itRet;
44  }
45  //! \overload
46  template <class K,class V> inline typename std::multimap<K,V>::iterator erase_return_next(std::multimap<K,V> &cont, typename std::multimap<K,V>::iterator &it)
47  {
48  typename std::multimap<K,V>::iterator itRet = it; ++itRet;
49  cont.erase(it);
50  return itRet;
51  }
52  //! \overload
53  template <class T> inline typename std::set<T>::iterator erase_return_next(std::set<T> &cont, typename std::set<T>::iterator &it)
54  {
55  typename std::set<T>::iterator itRet = it; ++itRet;
56  cont.erase(it);
57  return itRet;
58  }
59 
60 
61  /** @} */ // end of grouping
62  }
63 }
64 
Scalar * iterator
Definition: eigen_plugins.h:23
const Scalar * const_iterator
Definition: eigen_plugins.h:24
std::list< T >::iterator erase_return_next(std::list< T > &cont, typename std::list< T >::iterator &it)
Calls the standard "erase" method of a STL container, but also returns an iterator to the next elemen...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
size_t find_in_vector(const T &value, const CONTAINER &vect)
Returns the index of the value "T" in the container "vect" (std::vector,std::deque,etc), or string::npos if not found.
double BASE_IMPEXP distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.



Page generated by Doxygen 1.8.13 for MRPT 1.4.0 SVN: at Wed Mar 15 00:43:31 UTC 2017