repr
0.1
Reconstructable string representations and more
Loading...
Searching...
No Matches
fundamental.h
Go to the documentation of this file.
1
#pragma once
2
#include <
string
>
3
#include <
cmath
>
4
#include <
librepr/macro/format.h
>
5
6
namespace
librepr
{
7
8
// Boolean type
9
inline
std::string
repr
(
bool
obj
) {
10
return
obj
?
"true"
:
"false"
;
11
}
12
13
// Integer types
14
inline
std::string
repr
(
signed
short
obj
) {
15
return
REPR_FORMAT
(
"{}"
,
obj
);
16
}
17
18
inline
std::string
repr
(
unsigned
short
obj
) {
19
return
REPR_FORMAT
(
"{}"
,
obj
);
20
}
21
inline
std::string
repr
(
signed
int
obj
) {
22
return
REPR_FORMAT
(
"{}"
,
obj
);
23
}
24
inline
std::string
repr
(
unsigned
int
obj
) {
25
return
REPR_FORMAT
(
"{}U"
,
obj
);
26
}
27
inline
std::string
repr
(
signed
long
obj
) {
28
return
REPR_FORMAT
(
"{}L"
,
obj
);
29
}
30
inline
std::string
repr
(
unsigned
long
obj
) {
31
return
REPR_FORMAT
(
"{}UL"
,
obj
);
32
}
33
inline
std::string
repr
(
signed
long
long
obj
) {
34
return
REPR_FORMAT
(
"{}LL"
,
obj
);
35
}
36
inline
std::string
repr
(
unsigned
long
long
obj
) {
37
return
REPR_FORMAT
(
"{}ULL"
,
obj
);
38
}
39
40
// Floating-point types
41
inline
std::string
repr
(
float
obj
) {
42
auto
is_integer
=
rintf
(
obj
) ==
obj
;
43
return
REPR_FORMAT
(
"{}{}F"
,
obj
,
is_integer
?
".0"
:
""
);
44
}
45
46
inline
std::string
repr
(
double
obj
) {
47
auto
is_integer
= rint(
obj
) ==
obj
;
48
return
REPR_FORMAT
(
"{}{}"
,
obj
,
is_integer
?
".0"
:
""
);
49
}
50
51
inline
std::string
repr
(
long
double
obj
) {
52
auto
is_integer
=
rintl
(
obj
) ==
obj
;
53
return
REPR_FORMAT
(
"{}{}L"
,
obj
,
is_integer
?
".0"
:
""
);
54
}
55
56
// Character types
57
inline
std::string
repr
(
char
obj
) {
58
return
REPR_FORMAT
(
"'{:c}'"
,
obj
);
59
}
60
61
}
// namespace librepr
REPR_FORMAT
#define REPR_FORMAT(...)
std::string
cmath
format.h
librepr
Definition
ctvi/ctvi.h:9
librepr::code_for
std::string code_for()
Definition
repr:39
repr
constexpr ::librepr::ReprWrapper repr
Definition
repr:59
string
include
librepr
repr
fundamental.h
Generated by
1.9.8, using the excellent
Doxygen Awesome
Theme