-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_range.inl
72 lines (56 loc) · 1.14 KB
/
print_range.inl
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
/**
* @file print_range.inl
* @author Xuhua Huang
* @brief
* @version 0.1
* @date 2023-03-30
*
* @copyright ueg (c) 2023
*
*/
#ifndef PRINT_RANGE_INL
#define PRINT_RANGE_INL
#ifndef _IOSTREAM_
#include <iostream>
#endif
#ifndef _RANGES_
#include <ranges>
#endif
namespace util
{
namespace range
{
auto print_range(const std::ranges::range auto& range, bool newline = false) -> void;
namespace detail
{
auto print(const std::ranges::range auto& value) -> void
{
print_range(value, false);
}
auto print(const auto& value) -> void
{
std::cout << value;
}
} // namespace detail
auto print_range(const std::ranges::range auto& range, bool newline) -> void
{
const auto begin = std::ranges::cbegin(range);
const auto end = std::ranges::cend(range);
std::cout << '[';
for (auto&& i : std::ranges::subrange(begin, end - 1))
{
// std::cout << i << ",";
detail::print(i);
std::cout << ',';
}
// std::cout << *(end - 1) << ']';
detail::print(*(end - 1));
std::cout << ']';
if (newline)
{
std::cout << '\n';
}
}
} // namespace range
} // namespace util
#endif