MRPT  1.9.9
copy_container_typecasting.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-2018, 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 namespace mrpt::containers
12 {
13 /** \addtogroup containers_grp
14  * @{ */
15 
16 /** Copy all the elements in a container (vector, deque, list) into a different
17  * one performing the appropriate typecasting.
18  * The target container is automatically resized to the appropriate size, and
19  * previous contents are lost.
20  * This can be used to assign std::vector's of different types:
21  * \code
22  * std::vector<int> vi(10);
23  * std::vector<float> vf;
24  * vf = vi; // Compiler error
25  * mrpt::containers::copy_container_typecasting(v1,vf); // Ok
26  * \endcode
27  */
28 template <typename src_container, typename dst_container>
30  const src_container& src, dst_container& trg)
31 {
32  trg.resize(src.size());
33  typename src_container::const_iterator i = src.begin();
34  typename src_container::const_iterator last = src.end();
35  typename dst_container::iterator target = trg.begin();
36  for (; i != last; ++i, ++target)
37  *target = static_cast<typename dst_container::value_type>(*i);
38 }
39 /** @} */ // end of grouping
40 }
41 
Scalar * iterator
Definition: eigen_plugins.h:26
void copy_container_typecasting(const src_container &src, dst_container &trg)
Copy all the elements in a container (vector, deque, list) into a different one performing the approp...
GLuint src
Definition: glext.h:7278
const Scalar * const_iterator
Definition: eigen_plugins.h:27



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020