print.hpp
1.39 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/url
//
#ifndef BOOST_URL_DETAIL_PRINT_HPP
#define BOOST_URL_DETAIL_PRINT_HPP
#ifndef BOOST_URL_SOURCE
#error
#endif
#include <cstdint>
#include <type_traits>
namespace boost {
namespace urls {
namespace detail {
// std::uint64_t
// 18446744073709551615
// 1 2
template<class T>
struct printed
: std::false_type
{
};
// 16-bit unsigned
template<>
class printed<std::uint16_t>
: std::false_type
{
char n_;
char buf_[5];
public:
printed(std::uint16_t n)
{
char* it =
buf_ + sizeof(buf_);
if(n == 0)
{
*--it = '0';
n_ = 1;
}
else
{
while(n > 0)
{
*--it = '0' + (n % 10);
n /= 10;
}
n_ = static_cast<char>(
sizeof(buf_) - (
it - buf_));
}
}
string_view
string() const noexcept
{
return string_view(buf_ +
sizeof(buf_) - n_, n_);
}
};
template<class T>
printed<T>
make_printed(T t)
{
return printed<T>(t);
}
} // detail
} // urls
} // boost
#endif