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::containers
17 {
18 /** \addtogroup
19  * @{ */
20 
21 /** Generates a string for a vector in the format [A,B,C,...] to std::cout, and
22  * the fmt string for <b>each</b> vector element. */
23 template <typename T>
24 std::string sprintf_vector(const char* fmt, const std::vector<T>& V)
25 {
26  std::string ret = "[";
27  const size_t N = V.size();
28  for (size_t i = 0; i < N; i++)
29  {
30  ret += format(fmt, V[i]);
31  if (i != (N - 1)) ret += ",";
32  }
33  ret += "]";
34  return ret;
35 }
36 /// @overload
37 template <typename Derived>
39 {
40  std::string ret = "[";
41  const size_t N = V.size();
42  for (size_t i = 0; i < N; i++)
43  {
44  ret += format(fmt, V[i]);
45  if (i != (N - 1)) ret += ",";
46  }
47  ret += "]";
48  return ret;
49 }
50 
51 /** Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string
52  * for <b>each</b> vector element. */
53 template <typename T>
54 void printf_vector(const char* fmt, const std::vector<T>& V)
55 {
56  ::fputs(sprintf_vector(fmt, V).c_str(), stdout);
57 }
58 
59 /** @} */ // end of grouping
60 }
61 
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:54
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:24
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16



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