1#pragma once
2
3#include <sstream>
4#include <string>
5#include <cassert>
6#include <cstdlib>
7#include <exception>
8
9// Polyfill needed by Qt when building for Android with GCC
10#if defined(__ANDROID__) && defined(__GLIBCXX__)
11
12namespace std {
13
14template <typename T>
15std::string to_string(T value)
16{
17 std::ostringstream oss;
18 oss << value;
19
20 return oss.str();
21}
22
23inline int stoi(const std::string &str)
24{
25 return atoi(str.c_str());
26}
27
28inline float stof(const std::string &str) {
29 return static_cast<float>(atof(str.c_str()));
30}
31
32} // namespace std
33
34#endif
35
36namespace mbgl {
37namespace util {
38
39template <class T>
40inline std::string toString(T t) {
41 return std::to_string(t);
42}
43
44inline std::string toString(int8_t num) {
45 return std::to_string(val: int(num));
46}
47
48inline std::string toString(uint8_t num) {
49 return std::to_string(val: unsigned(num));
50}
51
52std::string toString(float);
53std::string toString(double);
54std::string toString(long double);
55
56inline std::string toString(std::exception_ptr error) {
57 assert(error);
58
59 if (!error) {
60 return "(null)";
61 }
62
63 try {
64 std::rethrow_exception(error);
65 } catch (const std::exception& ex) {
66 return ex.what();
67 } catch (...) {
68 return "Unknown exception type";
69 }
70}
71
72inline float stof(const std::string& str) {
73 return std::stof(str: str);
74}
75
76} // namespace util
77} // namespace mbgl
78

source code of qtlocation/src/3rdparty/mapbox-gl-native/include/mbgl/util/string.hpp