mirror of
https://github.com/matrix-construct/construct
synced 2024-10-01 05:08:59 +02:00
ircd::json: Array list protocol for stringifying tuple.
This commit is contained in:
parent
7a7c1fb542
commit
ff94fdd3a6
1 changed files with 34 additions and 0 deletions
|
@ -1129,6 +1129,19 @@ serialized(const tuple<T...> &t)
|
|||
return std::accumulate(begin(sizes), e, size_t(overhead));
|
||||
}
|
||||
|
||||
template<class... T>
|
||||
size_t
|
||||
serialized(const tuple<T...> *const &b,
|
||||
const tuple<T...> *const &e)
|
||||
{
|
||||
size_t ret(1 + (b == e));
|
||||
return std::accumulate(b, e, ret, []
|
||||
(size_t ret, const tuple<T...> &t)
|
||||
{
|
||||
return ret += serialized(t) + 1;
|
||||
});
|
||||
}
|
||||
|
||||
template<class... T>
|
||||
string_view
|
||||
stringify(mutable_buffer &buf,
|
||||
|
@ -1154,6 +1167,27 @@ stringify(mutable_buffer &buf,
|
|||
return stringify(buf, begin(members), e);
|
||||
}
|
||||
|
||||
template<class... T>
|
||||
string_view
|
||||
stringify(mutable_buffer &buf,
|
||||
const tuple<T...> *b,
|
||||
const tuple<T...> *e)
|
||||
{
|
||||
const auto start(begin(buf));
|
||||
consume(buf, copy(buf, "["_sv));
|
||||
if(b != e)
|
||||
{
|
||||
stringify(buf, *b);
|
||||
for(++b; b != e; ++b)
|
||||
{
|
||||
consume(buf, copy(buf, ","_sv));
|
||||
stringify(buf, *b);
|
||||
}
|
||||
}
|
||||
consume(buf, copy(buf, "]"_sv));
|
||||
return { start, begin(buf) };
|
||||
}
|
||||
|
||||
template<class... T>
|
||||
std::ostream &
|
||||
operator<<(std::ostream &s, const tuple<T...> &t)
|
||||
|
|
Loading…
Reference in a new issue