-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilityFunctions.h
More file actions
67 lines (57 loc) · 1.67 KB
/
Copy pathUtilityFunctions.h
File metadata and controls
67 lines (57 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef BaseLib_Templates_UtilityFunctions_h_Included
#define BaseLib_Templates_UtilityFunctions_h_Included
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <limits>
#include"BaseLib/Export.h"
namespace BaseLib
{
template<typename T>
DLL_STATE inline std::string Stringify(T const& x)
{
std::ostringstream out;
out << x;
return out.str();
}
template<>
DLL_STATE inline std::string Stringify<bool>(bool const& x)
{
std::ostringstream out;
out << std::boolalpha << x;
return out.str();
}
template<>
DLL_STATE inline std::string Stringify<double>(double const& x)
{
const int sigdigits = std::numeric_limits<double>::digits10;
// or perhaps std::numeric_limits<double>::max_digits10 if that is available on your compiler
std::ostringstream out;
out << std::setprecision(sigdigits) << x;
return out.str();
}
template<>
DLL_STATE inline std::string Stringify<float>(float const& x)
{
const int sigdigits = std::numeric_limits<float>::digits10;
// or perhaps std::numeric_limits<float>::max_digits10 if that is available on your compiler
std::ostringstream out;
out << std::setprecision(sigdigits) << x;
return out.str();
}
template<>
DLL_STATE inline std::string Stringify<long double>(const long double& x)
{
const int sigdigits = std::numeric_limits<long double>::digits10;
// or perhaps std::numeric_limits<long_double>::max_digits10 if that is available on your compiler
std::ostringstream out;
out << std::setprecision(sigdigits) << x;
return out.str();
}
//template<>
//DLL_STATE inline std::string Stringify<wchar_t>(const wchar_t &buf)
//{
//}
} // namespace BaseLib
#endif // BaseLib_Templates_UtilityFunctions_h_Included