-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversal_converter.h
More file actions
45 lines (37 loc) · 1.19 KB
/
universal_converter.h
File metadata and controls
45 lines (37 loc) · 1.19 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
#ifndef __universal_converter_h__
#define __universal_converter_h__
#include "fstring.h"
class universal_converter
{
public:
universal_converter() = default;
constexpr operator std::string_view() const noexcept { return std::string_view(m_value); }
template<typename TValue>
universal_converter& operator=(const TValue in_value)
{
if constexpr (std::is_same<TValue, bool>())
{
m_value += in_value ? "true" : "false";
}
else if constexpr (std::is_same<TValue, char>())
{
m_value += in_value;
}
else if constexpr (std::is_floating_point_v<TValue>) {
m_value.printf(in_value);
}
else if constexpr (std::is_integral_v<TValue> && std::is_signed_v<TValue>) {
m_value.printf(in_value);
}
else if constexpr (std::is_integral_v<TValue> && std::is_unsigned_v<TValue>) {
m_value.printf(in_value);
}
else if constexpr (std::is_convertible_v<TValue, std::string_view>){
m_value += in_value;
}
return *this;
}
protected:
fstr::fstr63 m_value;
};
#endif // __universal_converter_h__