MRPT  2.0.4
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-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 
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>
36 std::string to_string(T v)
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 std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
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.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string to_string(const char *s)
Definition: format.h:51
#define MRPT_printf_format_check(_FMT_, _VARARGS_)
Definition: common.h:142



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020