xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
basics
join.h
1
#pragma once
2
3
#include <
cstddef
>
4
#include <
string
>
5
#include <
string_view
>
6
#include <
utility
>
7
8
namespace
xrpl
{
9
10
template
<
class
Stream,
class
Iter>
11
Stream&
12
join
(Stream& s, Iter iter, Iter end,
std::string_view
delimiter)
13
{
14
if
(iter == end)
15
return
s;
16
s << *iter;
17
for
(++iter; iter != end; ++iter)
18
s << delimiter << *iter;
19
return
s;
20
}
21
22
template
<
class
Collection>
23
class
CollectionAndDelimiter
24
{
25
public
:
26
Collection
const
&
collection
;
27
std::string
const
delimiter
;
28
29
explicit
CollectionAndDelimiter
(Collection
const
& c,
std::string
delim)
30
:
collection
(c),
delimiter
(
std
::move(delim))
31
{
32
}
33
34
template
<
class
Stream>
35
friend
Stream&
36
operator<<
(Stream& s,
CollectionAndDelimiter
const
& cd)
37
{
38
return
join
(s,
std::begin
(cd.
collection
),
std::end
(cd.
collection
), cd.
delimiter
);
39
}
40
};
41
42
template
<
class
Collection, std::
size_t
N>
43
class
CollectionAndDelimiter
<Collection[N]>
44
{
45
public
:
46
Collection
const
*
collection
;
47
std::string
const
delimiter
;
48
49
explicit
CollectionAndDelimiter
(Collection
const
c[N],
std::string
delim)
50
:
collection
(c),
delimiter
(
std
::move(delim))
51
{
52
}
53
54
template
<
class
Stream>
55
friend
Stream&
56
operator<<
(Stream& s,
CollectionAndDelimiter
const
& cd)
57
{
58
return
join
(s, cd.
collection
, cd.
collection
+ N, cd.
delimiter
);
59
}
60
};
61
62
// Specialization for const char* strings
63
template
<std::
size_t
N>
64
class
CollectionAndDelimiter
<char[N]>
65
{
66
public
:
67
char
const
*
collection
;
68
std::string
const
delimiter
;
69
70
explicit
CollectionAndDelimiter
(
char
const
c[N],
std::string
delim)
71
:
collection
(c),
delimiter
(
std
::move(delim))
72
{
73
}
74
75
template
<
class
Stream>
76
friend
Stream&
77
operator<<
(Stream& s,
CollectionAndDelimiter
const
& cd)
78
{
79
auto
end = cd.
collection
+ N;
80
if
(N > 0 && *(end - 1) ==
'\0'
)
81
--end;
82
return
join
(s, cd.
collection
, end, cd.
delimiter
);
83
}
84
};
85
86
}
// namespace xrpl
std::string
std::string_view
std::begin
T begin(T... args)
xrpl::CollectionAndDelimiter< Collection[N]>::CollectionAndDelimiter
CollectionAndDelimiter(Collection const c[N], std::string delim)
Definition
join.h:49
xrpl::CollectionAndDelimiter< Collection[N]>::delimiter
std::string const delimiter
Definition
join.h:47
xrpl::CollectionAndDelimiter< Collection[N]>::collection
Collection const * collection
Definition
join.h:46
xrpl::CollectionAndDelimiter< char[N]>::delimiter
std::string const delimiter
Definition
join.h:68
xrpl::CollectionAndDelimiter< char[N]>::collection
char const * collection
Definition
join.h:67
xrpl::CollectionAndDelimiter< char[N]>::CollectionAndDelimiter
CollectionAndDelimiter(char const c[N], std::string delim)
Definition
join.h:70
xrpl::CollectionAndDelimiter::operator<<
friend Stream & operator<<(Stream &s, CollectionAndDelimiter const &cd)
Definition
join.h:36
xrpl::CollectionAndDelimiter::collection
Collection const & collection
Definition
join.h:26
xrpl::CollectionAndDelimiter::delimiter
std::string const delimiter
Definition
join.h:27
xrpl::CollectionAndDelimiter::CollectionAndDelimiter
CollectionAndDelimiter(Collection const &c, std::string delim)
Definition
join.h:29
cstddef
std::end
T end(T... args)
std
STL namespace.
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::join
Stream & join(Stream &s, Iter iter, Iter end, std::string_view delimiter)
Definition
join.h:12
string
string_view
utility
Generated by
1.17.0