MRPT  2.0.1
list_searchable.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <algorithm>
12 #include <list>
13 
14 namespace mrpt::containers
15 {
16 /** This class implements a STL container with features of both, a std::set and
17  * a std::list.
18  * \note Defined in #include <mrpt/containers/list_searchable.h>
19  * \ingroup mrpt_containers_grp
20  */
21 template <class T>
22 class list_searchable : public std::list<T>
23 {
24  public:
25  void insert(const T& o) { std::list<T>::push_back(o); }
26  typename std::list<T>::iterator find(const T& i)
27  {
29  }
30 
31  typename std::list<T>::const_iterator find(const T& i) const
32  {
34  }
35 
36  /** Finds an element in a list of smart pointers, having "->pointer()", such
37  * as it matches a given plain pointer "ptr". */
38  template <typename PTR>
39  typename std::list<T>::iterator find_ptr_to(const PTR ptr)
40  {
41  for (auto it = std::list<T>::begin(); it != std::list<T>::end(); it++)
42  if (it->get() == ptr) return it;
43  return std::list<T>::end();
44  }
45 
46  /** Finds an element in a list of smart pointers, having "->pointer()", such
47  * as it matches a given plain pointer "ptr". */
48  template <typename PTR>
49  typename std::list<T>::const_iterator find_ptr_to(const PTR ptr) const
50  {
51  for (typename std::list<T>::const_iterator it = std::list<T>::begin();
52  it != std::list<T>::end(); it++)
53  if (it->pointer() == ptr) return it;
54  return std::list<T>::end();
55  }
56 };
57 } // namespace mrpt::containers
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(const T &i)
std::list< T >::const_iterator find(const T &i) const
const_iterator find(const KEY &key) const
Definition: ts_hash_map.h:224
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 ...
This class implements a STL container with features of both, a std::set and a std::list.
const_iterator end() const
Definition: ts_hash_map.h:246
const_iterator begin() const
Definition: ts_hash_map.h:240



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020