Main MRPT website > C++ reference for MRPT 1.9.9
printf_vector.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 #include <mrpt/math/eigen_frwds.h>
12 #include <string>
13 #include <vector>
14 #include <cstdio>
15 
16 namespace mrpt
17 {
18 namespace containers
19 {
20 /** \addtogroup
21  * @{ */
22 
23 /** Generates a string for a vector in the format [A,B,C,...] to std::cout, and
24  * the fmt string for <b>each</b> vector element. */
25 template <typename T>
26 std::string sprintf_vector(const char* fmt, const std::vector<T>& V)
27 {
28  std::string ret = "[";
29  const size_t N = V.size();
30  for (size_t i = 0; i < N; i++)
31  {
32  ret += format(fmt, V[i]);
33  if (i != (N - 1)) ret += ",";
34  }
35  ret += "]";
36  return ret;
37 }
38 /// @overload
39 template <typename Derived>
41 {
42  std::string ret = "[";
43  const size_t N = V.size();
44  for (size_t i = 0; i < N; i++)
45  {
46  ret += format(fmt, V[i]);
47  if (i != (N - 1)) ret += ",";
48  }
49  ret += "]";
50  return ret;
51 }
52 
53 /** Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string
54  * for <b>each</b> vector element. */
55 template <typename T>
56 void printf_vector(const char* fmt, const std::vector<T>& V)
57 {
58  ::fputs(sprintf_vector(fmt, V).c_str(), stdout);
59 }
60 
61 /** @} */ // end of grouping
62 } // namespace containers
63 } // namespace mrpt
void printf_vector(const char *fmt, const std::vector< T > &V)
Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element...
Definition: printf_vector.h:56
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
GLsizei const GLchar ** string
Definition: glext.h:4101
std::string sprintf_vector(const char *fmt, const std::vector< T > &V)
Generates a string for a vector in the format [A,B,C,...] to std::cout, and the fmt string for each v...
Definition: printf_vector.h:26
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019