MRPT  1.9.9
printf_vector.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 <mrpt/core/format.h>
12 #include <cstdio>
13 #include <string>
14 #include <vector>
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 VEC>
24 std::string sprintf_vector(const char* fmt, const VEC& 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 
37 /** Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string
38  * for <b>each</b> vector element. */
39 template <typename T>
40 void printf_vector(const char* fmt, const std::vector<T>& V)
41 {
42  ::fputs(sprintf_vector(fmt, V).c_str(), stdout);
43 }
44 
45 /** @} */ // end of grouping
46 } // namespace mrpt::containers
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
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:40
std::string sprintf_vector(const char *fmt, const VEC &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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020