0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-30 15:58:20 +02:00

ircd::json: Array list protocol for stringifying tuple.

This commit is contained in:
Jason Volk 2018-02-28 02:23:32 -08:00
parent 7a7c1fb542
commit ff94fdd3a6

View file

@ -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)