@@ -27,6 +27,38 @@ namespace classdesc_access
2727 void operator ()(classdesc::xml_pack_t & t,const classdesc::string& d, const T& a)
2828 {t.pack_notag (d,a);}
2929 };
30+
31+ #if defined(__cplusplus) && __cplusplus>=201703L
32+
33+ template <class ... A>
34+ struct access_xml_pack <std::tuple<A...>>
35+ {
36+ template <class T >
37+ void xml_pack_tuple_element (classdesc::xml_pack_t & o, const cd::string& d, T& a)
38+ {
39+ if constexpr (std::tuple_size<T>::value>0 )
40+ {
41+ // element name is given by the type name
42+ std::string eName=classdesc::typeName<typename std::tuple_element<0 ,T>::type>();
43+ eName=eName.substr (0 ,eName.find (' <' )); // trim off any template args
44+ // strip leading namespace and qualifiers
45+ const char *e=eName.c_str ()+eName.length ();
46+ while (e!=eName.c_str () && *(e-1 )!=' ' && *(e-1 )!=' :' ) e--;
47+ ::xml_pack (o,e,std::get<0 >(a));
48+ auto tail=classdesc::tupleTail (a);
49+ xml_pack_tuple_element (o,d,tail);
50+ }
51+ }
52+
53+ template <class U >
54+ void operator ()(classdesc::xml_pack_t & o, const cd::string& d, U& a)
55+ {
56+ classdesc::xml_pack_t ::Tag tag (o,d);
57+ xml_pack_tuple_element (o, d, a);
58+ }
59+ };
60+ #endif
61+
3062#endif
3163
3264#ifdef CLASSDESC_XML_UNPACK_BASE_H
@@ -45,6 +77,37 @@ namespace classdesc_access
4577 t.unpack (d,tmp);
4678 }
4779 };
80+
81+ #if defined(__cplusplus) && __cplusplus>=201703L
82+ template <class ... A>
83+ struct access_xml_unpack <std::tuple<A...>>
84+ {
85+ template <class T >
86+ void xml_unpack_tuple_element (classdesc::xml_unpack_t & o, const cd::string& d, T& a, int i)
87+ {
88+ if constexpr (std::tuple_size<T>::value>0 )
89+ {
90+ ::xml_unpack (o,classdesc::idx(d,i),std::get<0>(a));
91+ auto tail=classdesc::tupleTail (a);
92+ xml_unpack_tuple_element (o,d,tail,i+1 );
93+ a=std::tuple_cat (std::make_tuple (std::get<0 >(a)), tail);
94+ }
95+ }
96+
97+ template <class U >
98+ void operator ()(classdesc::xml_unpack_t & o, const cd::string& d, U& a)
99+ {
100+ // element name is given by the type name
101+ std::string eName=classdesc::typeName<typename std::tuple_element<0 ,std::tuple<A...>>::type>();
102+ eName=eName.substr (0 ,eName.find (' <' )); // trim off any template args
103+ // strip leading namespace and qualifiers
104+ const char *e=eName.c_str ()+eName.length ();
105+ while (e!=eName.c_str () && *(e-1 )!=' ' && *(e-1 )!=' :' ) e--;
106+ xml_unpack_tuple_element (o,d+" ." +e,a,0 );
107+ }
108+ };
109+ #endif
110+
48111#endif
49112}
50113
0 commit comments