@@ -554,6 +554,8 @@ concept container_but_not_string =
554554
555555---
556556
557+ # Serialize 'array-like' Containers
558+
557559```cpp
558560template <class T>
559561 requires(container_but_not_string<T>)
@@ -575,8 +577,16 @@ constexpr void atom(string_builder &b, const T &t) {
575577✅ Works with ` vector ` , ` array ` , ` deque ` , custom containers...
576578
577579
580+
578581---
579582
583+ # For Deserialization
584+
585+ * Many ways to add values to a container
586+ * ` push_back ` , ` append ` , ` emplace_back `
587+
588+
589+
580590``` cpp
581591template <typename T>
582592concept appendable_containers =
@@ -588,6 +598,42 @@ concept appendable_containers =
588598
589599---
590600
601+ # Write a Helper Function
602+
603+ ``` cpp
604+ template <appendable_containers T, typename ... Args>
605+ constexpr decltype (auto) emplace_one(T &vec, Args &&...args) {
606+ if constexpr (details::supports_emplace_back<T >) {
607+ return vec.emplace_back(std::forward<Args >(args)...);
608+ } else if constexpr (details::supports_emplace<T >) {
609+ return vec.emplace(std::forward<Args >(args)...);
610+ } else if constexpr (details::supports_push_back<T >) {
611+ return vec.push_back(std::forward<Args >(args)...);
612+ } else if constexpr (details::supports_push<T >) {
613+ return vec.push(std::forward<Args >(args)...);
614+ } else if constexpr (details::supports_add<T >) {
615+ return vec.add(std::forward<Args >(args)...);
616+ } else if constexpr (details::supports_append<T >) {
617+ return vec.append(std::forward<Args >(args)...);
618+ } else if constexpr (details::supports_insert<T >) {
619+ return vec.insert(std::forward<Args >(args)...);
620+ // ....
621+ ```
622+
623+
624+ ---
625+
626+
627+ # Derialize 'array-like' Containers
628+ ```cpp
629+ auto arr = json.get_array()
630+ for (auto v : arr) {
631+ concepts::emplace_one(out, v.get<value_type>());
632+ }
633+ ```
634+
635+ ---
636+
591637# Concepts + Reflection = Automatic Support
592638
593639When you write:
@@ -726,6 +772,22 @@ if (!needs_escape)
726772
727773We've observed a 6% slow-down when compiling simdjson with static reflection enabled. (clang p2996 experimental branch).
728774
775+
776+ ---
777+
778+ ## Learning Curve
779+
780+ ```
781+ error: invalid use of incomplete type 'std::reflect::member_info<
782+ std::reflect::get_public_data_members_t<Person>[0]>'
783+ in instantiation of function template specialization
784+ 'get_member_name<Person, 0>' requested here
785+ note: in instantiation of function template specialization
786+ 'serialize_impl<Person>' requested here
787+ note: while substituting template arguments for class template
788+ ```
789+
790+
729791---
730792
731793![ bg right] ( images/racecar.png )
@@ -741,7 +803,7 @@ We've observed a 6% slow-down when compiling simdjson with static reflection ena
741803
7428044 ) ** SIMD** : String operations benefit
743805
744- 5 ) ** Many optimization helps **
806+ 5 ) ** Many optimizationns may help **
745807
746808---
747809
0 commit comments