arangodb / velocypack

A fast and compact format for serialization and storage
Other
420 stars 40 forks source link

Unpack Tuple #85

Closed maierlars closed 3 years ago

maierlars commented 3 years ago

This adds a new function unpackTuple<T_1, T_2, ..., T_n> to Slice and ArrayIterator. It can be used to unpack values from an array given their types. Given a type a Extractor<T> is used to extract the type from a slice. Thus we can easily add more types and even user code can provide specializations for their types to extract them.

unpackTuple extracts the first n elements from a Slice and reads n elements from an ArrayIterator.

auto t = s.unpackTuple<std::string, int, bool, Slice>();
static_assert(std::is_same_v<decltype(t), std::tuple<std::string, int, bool, Slice>>);

Supported types are:

As by-product it also adds extract<T> to slice.

coveralls commented 3 years ago

Coverage Status

Coverage decreased (-0.02%) to 96.409% when pulling 6ad6cf2c77ce6fcd41f65a93d0168fcd0007a499 on feature/unpack-tuple into 390fc4c8dfec7c70704b22b0eafafc5d1f08b44a on main.