MRPT  1.9.9
copy_container_typecasting.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-2019, 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 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  auto i = src.begin();
34  auto last = src.end();
35  auto 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 } // namespace mrpt::containers
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:7397



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019