Main MRPT website > C++ reference for MRPT 1.4.0
list_searchable.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#ifndef list_searchable_H
10#define list_searchable_H
11
12#include <list>
13#include <algorithm>
14
15namespace mrpt
16{
17 namespace utils
18 {
19 using std::for_each;
20 using std::string;
21
22 /** This class implements a STL container with features of both, a std::set and a std::list.
23 * \note Defined in #include <mrpt/utils/list_searchable.h>
24 * \ingroup stlext_grp
25 */
26 template <class T>
27 class list_searchable : public std::list<T>
28 {
29 public:
30 void insert( const T &o ) { std::list<T>::push_back(o); }
31
32 typename std::list<T>::iterator find( const T& i ) {
33 return std::find(std::list<T>::begin(),std::list<T>::end(),i);
34 }
35
36 typename std::list<T>::const_iterator find( const T& i ) const {
37 return std::find(std::list<T>::begin(),std::list<T>::end(),i);
38 }
39
40 /** Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain pointer "ptr". */
41 template <typename PTR>
42 typename std::list<T>::iterator find_ptr_to( const PTR ptr )
43 {
44 for (typename std::list<T>::iterator it=std::list<T>::begin();it!=std::list<T>::end();it++)
45 if (it->pointer()==ptr)
46 return it;
47 return std::list<T>::end();
48 }
49
50 /** Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain pointer "ptr". */
51 template <typename PTR>
52 typename std::list<T>::const_iterator find_ptr_to( const PTR ptr ) const
53 {
54 for (typename std::list<T>::const_iterator it=std::list<T>::begin();it!=std::list<T>::end();it++)
55 if (it->pointer()==ptr)
56 return it;
57 return std::list<T>::end();
58 }
59
60 };
61
62 } // End of namespace
63} // End of namespace
64#endif
This class implements a STL container with features of both, a std::set and a std::list.
std::list< T >::iterator find(const T &i)
std::list< T >::const_iterator find_ptr_to(const PTR ptr) const
Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain ...
std::list< T >::iterator find_ptr_to(const PTR ptr)
Finds an element in a list of smart pointers, having "->pointer()", such as it matches a given plain ...
std::list< T >::const_iterator find(const T &i) const
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Fri Jan 20 00:13:14 UTC 2023