userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
floating_point_types.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/storages/clickhouse/io/floating_point_types.hpp
4
/// @brief @copybrief storages::clickhouse::io::FloatingWithPrecision
5
6
#
include
<
concepts
>
7
8
#
include
<
fmt
/
format
.
h
>
9
10
USERVER_NAMESPACE_BEGIN
11
12
namespace
storages::
clickhouse
::
io
{
13
14
/// @brief Class that can be escaped for clickhouse queries instead of [double] and [float].
15
/// [double] and [float] are escaped as FloatingWithPrecision<double, 12> and
16
/// FloatingWithPrecision<float, 6> respectively. These constants were derived from the accuracity the numbers from
17
/// ranges [0.0-100000.0] (doubles) and [0.0-100.0] (floats) can be represented by these type. Clickhouse also supports
18
/// inf, -inf and nan, see clickhouse docs.
19
template
<
std
::floating_point FloatingPointT, std::uint32_t Precision = std::is_same_v<FloatingPointT,
float
> ? 6 : 12>
20
class
FloatingWithPrecision
{
21
public
:
22
template
<
typename
U>
23
FloatingWithPrecision(U value)
24
: value_(value)
25
{}
26
27
template
<
typename
U, std::uint32_t AnotherPrecision>
28
FloatingWithPrecision(
const
FloatingWithPrecision
<U, AnotherPrecision>& other)
29
: value_(other.value_)
30
{}
31
32
template
<
typename
U, std::uint32_t AnotherPrecision>
33
FloatingWithPrecision(
FloatingWithPrecision
<U, AnotherPrecision>&& other)
34
: value_(other.value_)
35
{}
36
37
template
<
typename
U, std::uint32_t AnotherPrecision>
38
FloatingWithPrecision
& operator=(
const
FloatingWithPrecision
<U, AnotherPrecision>& other) {
39
value_ = other.value_;
40
return
*
this
;
41
}
42
43
template
<
typename
U, std::uint32_t AnotherPrecision>
44
FloatingWithPrecision
& operator=(
FloatingWithPrecision
<U, AnotherPrecision>&& other) {
45
if
(
this
== &other) {
46
return
*
this
;
47
}
48
value_ = other.value_;
49
return
*
this
;
50
}
51
52
std::string ToString() {
return
fmt
::format(
"{:.{}f}"
, value_, Precision); }
53
54
private
:
55
FloatingPointT value_;
56
57
template
<
std
::floating_point U, std::uint32_t AnotherPrecision>
58
friend
class
FloatingWithPrecision
;
59
};
60
61
}
// namespace storages::clickhouse::io
62
63
USERVER_NAMESPACE_END
userver
storages
clickhouse
io
floating_point_types.hpp
Generated on
for userver by
Doxygen
1.17.0