MRPT  1.9.9
format.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 
10 #pragma once
11 
12 #include <mrpt/core/common.h>
13 #include <string>
14 
15 /** This is the global namespace for all Mobile Robot Programming Toolkit (MRPT)
16  * libraries. */
17 namespace mrpt
18 {
19 /** A std::string version of C sprintf.
20  * You can call this to obtain a std::string using printf-like syntax.
21  * \ingroup mrpt_core_grp
22  */
23 std::string format_impl(const char* fmt, ...) MRPT_printf_format_check(1, 2);
24 
25 template <typename... ARGS>
26 std::string format(std::string_view fmt, ARGS&&... args)
27 {
28  return format_impl(fmt.data(), std::forward<ARGS>(args)...);
29 }
30 
31 /** Just like std::to_string(), but with an overloaded version
32  * for std::string arguments.
33  * \ingroup mrpt_core_grp
34  */
35 template <typename T>
37 {
38  return std::to_string(v);
39 }
40 template <>
41 inline std::string to_string<>(std::string v)
42 {
43  return v;
44 }
45 template <>
46 inline std::string to_string<>(bool v)
47 {
48  return v ? "true" : "false";
49 }
50 template <>
51 inline std::string to_string<>(const char* s)
52 {
53  return std::string(s);
54 }
55 } // namespace mrpt
std::string to_string(T v)
Just like std::to_string(), but with an overloaded version for std::string arguments.
Definition: format.h:36
std::string format_impl(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
STL namespace.
GLdouble s
Definition: glext.h:3682
GLsizei const GLchar ** string
Definition: glext.h:4116
const GLdouble * v
Definition: glext.h:3684
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLenum GLsizei GLenum format
Definition: glext.h:3535
std::string to_string(const char *s)
Definition: format.h:51
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
Definition: common.h:158



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 9b18308f3 Mon Nov 18 23:39:25 2019 +0100 at lun nov 18 23:45:12 CET 2019