{"id":306762,"date":"2020-07-10T15:01:06","date_gmt":"2020-07-10T15:01:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=306762"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=306762","title":{"rendered":"\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 json \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 c++ \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e (\u0440\u0430\u0431\u043e\u0442\u0430 \u043d\u0430\u0434 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438)"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/510438\/\">\n<p><a href=\"https:\/\/habr.com\/ru\/post\/506506\/\">\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/a> \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0441++ \u0438 json \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439 \u0431\u043b\u0438\u043d \u2014 \u043a\u043e\u043c\u043e\u043c. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u2014 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439, \u0438 \u0437\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u0442\u043e\u0440\u0430\u044f. \u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 (\u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c) \u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u0434\u044b\u0440\u043e\u043a \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0431\u043b\u0438\u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0438 \u043a\u043e\u0435-\u0447\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"chto-bylo-ploho\">\u0427\u0442\u043e \u0431\u044b\u043b\u043e \u043f\u043b\u043e\u0445\u043e<\/h1>\n<p>  <\/p>\n<ul>\n<li>\u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441++ (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435). \u0412\u0441\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0441 \u043d\u0443\u043b\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c<\/li>\n<li>Json \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443<\/li>\n<li>Json \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/li>\n<li>\u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c stl \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b<\/li>\n<li>\u043c\u0430\u043a\u0440\u043e\u0441\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b (\u043c\u043e\u0436\u043d\u043e \u0438 \u0431\u0435\u0437 \u043d\u0438\u0445, \u043d\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043f\u043e\u043b\u0435\u0439 \u0436\u0435\u0441\u0442\u043a\u043e \u0441\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u0430 \u0441 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u044d\u0442\u0438\u0445 \u043f\u043e\u043b\u0435\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0435\u0437 \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043d\u0435\u0447\u0438\u0442\u0430\u0435\u043c\u043e)<\/li>\n<li>\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u0442.\u0435. \u043d\u0435\u043b\u044c\u0437\u044f \u0437\u0430\u0434\u0430\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/li>\n<\/ul>\n<p>  <\/p>\n<h1 id=\"kak-stalo-teper\">\u041a\u0430\u043a \u0441\u0442\u0430\u043b\u043e \u0442\u0435\u043f\u0435\u0440\u044c<\/h1>\n<p>  <\/p>\n<p>\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438, \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u0430 \u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435. \u0414\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">reg(V T::* ptr, std::string const &amp; name, Options&lt;U&gt;&amp;&amp; ... options);<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>ptr<\/code> \u2014 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043f\u043e\u043b\u0435<\/li>\n<li><code>name<\/code> \u2014 \u0438\u043c\u044f \u043f\u043e\u043b\u044f<\/li>\n<li><code>options<\/code> \u2014 \u043e\u043f\u0446\u0438\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u043e\u0432 \u043f\u043e\u043b\u0435\u0439 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b:<\/p>\n<p>  <\/p>\n<ul>\n<li>bool<\/li>\n<li>char, unsigned char, short, unsigned short, int unsigned int, long, long long<\/li>\n<li>float, double<\/li>\n<li>std::string<\/li>\n<li>std::list<\/li>\n<li>std::vector<\/li>\n<li>std::map (\u043a\u043b\u044e\u0447\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e std::string)<\/li>\n<li>std::unordered_map (\u043a\u043b\u044e\u0447\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e std::string)<\/li>\n<li>std::multimap (\u043a\u043b\u044e\u0447\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e std::string)<\/li>\n<li>std::unordered_multimap (\u043a\u043b\u044e\u0447\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e std::string)<\/li>\n<li>\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441++<\/li>\n<li>\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">struct Friend {  std::string name;  std::list&lt;int&gt; counters; };  struct MiB {  std::list&lt;Friend&gt; friends;  std::vector&lt;std::list&lt;std::string&gt;&gt; groups;  std::map&lt;std::string, std::vector&lt;std::string&gt;&gt; books; };  struct_mapping::reg(&amp;Friend::name, &quot;name&quot;); struct_mapping::reg(&amp;Friend::counters, &quot;counters&quot;);  struct_mapping::reg(&amp;MiB::friends, &quot;friends&quot;); struct_mapping::reg(&amp;MiB::groups, &quot;groups&quot;); struct_mapping::reg(&amp;MiB::books, &quot;books&quot;);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u043a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">map_json_to_struct(T &amp; result_struct, std::basic_istream&lt;char&gt; &amp; json_data);<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>result_struct<\/code> \u2014 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443<\/li>\n<li><code>json_data<\/code> \u2014 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0432\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0442\u043e\u043a json \u0434\u0430\u043d\u043d\u044b\u0445<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u043f\u043e\u043b\u0435\u0439 \u0442\u0438\u043f\u0430\u043c \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0434\u043b\u044f \u0447\u0438\u0441\u0435\u043b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u044b\u0445\u043e\u0434 \u0438\u0437 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0442\u0438\u043f\u0430 \u043f\u043e\u043b\u044f. \u041f\u0440\u0438 \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0442\u0438\u043f\u043e\u0432 \u0438\u043b\u0438 \u0432\u044b\u0445\u043e\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &lt;iostream&gt; #include &lt;sstream&gt;  #include &quot;struct_mapping\/struct_mapping.h&quot;  struct Planet {  bool giant;  long long surface_area;  double mass;  std::string satellite; };  int main() {  struct_mapping::reg(&amp;Planet::giant, &quot;giant&quot;);  struct_mapping::reg(&amp;Planet::surface_area, &quot;surface_area&quot;);  struct_mapping::reg(&amp;Planet::mass, &quot;mass&quot;);  struct_mapping::reg(&amp;Planet::satellite, &quot;satellite&quot;);   Planet earth;   std::istringstream json_data(R&quot;json(   {    &quot;giant&quot;: false,    &quot;surface_area&quot;: 510072000000000,    &quot;mass&quot;: 5.97237e24,    &quot;satellite&quot;: &quot;Moon&quot;   }  )json&quot;);   struct_mapping::map_json_to_struct(earth, json_data);   std::cout &lt;&lt; &quot;earth&quot; &lt;&lt; std::endl;  std::cout &lt;&lt; &quot; giant        : &quot; &lt;&lt; std::boolalpha &lt;&lt; earth.giant &lt;&lt; std::endl;  std::cout &lt;&lt; &quot; surface_area : &quot; &lt;&lt; earth.surface_area &lt;&lt; std::endl;  std::cout &lt;&lt; &quot; mass         : &quot; &lt;&lt; earth.mass &lt;&lt; std::endl;  std::cout &lt;&lt; &quot; satellite    : &quot; &lt;&lt; earth.satellite &lt;&lt; std::endl; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">earth  giant        : false  surface_area : 510072000000000  mass         : 5.97237e+24  satellite    : Moon<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"ispolzovanie-perechisleniy\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439<\/h2>\n<p>  <\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432 json \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">MemberString::set(From function_from_string_, To function_to_string_);<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>function_from_string_<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f<\/li>\n<li><code>function_to_string_<\/code> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432 \u0441\u0442\u0440\u043e\u043a\u0443<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">enum class Color {  red,  blue,  green, };  struct_mapping::MemberString&lt;Color&gt;::set(  [] (const std::string &amp; value) {   if (value == &quot;red&quot;) return Color::red;   if (value == &quot;green&quot;) return Color::green;   if (value == &quot;blue&quot;) return Color::blue;    throw struct_mapping::StructMappingException(&quot;bad convert '&quot;+value+&quot;' to Color&quot;);  },  [] (Color value) {   switch (value) {   case Color::red: return &quot;red&quot;;   case Color::green: return &quot;green&quot;;   default: return &quot;blue&quot;;   }  });<\/code><\/pre>\n<p>  <\/p>\n<p>\u0432 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u0438\u043f\u0430\u043c<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &lt;iostream&gt; #include &lt;list&gt; #include &lt;map&gt; #include &lt;sstream&gt; #include &lt;string&gt;  #include &quot;struct_mapping\/struct_mapping.h&quot;  namespace sm = struct_mapping;  enum class Color {  red,  blue,  green, };  Color color_from_string(const std::string &amp; value) {  if (value == &quot;red&quot;) return Color::red;  if (value == &quot;blue&quot;) return Color::blue;   return Color::green; }  std::string color_to_string(Color color) {  switch (color) {  case Color::red: return &quot;red&quot;;  case Color::green: return &quot;green&quot;;  default: return &quot;blue&quot;;  } }  struct Palette {  Color main_color;  Color background_color;  std::list&lt;Color&gt; special_colors;  std::map&lt;std::string, Color&gt; colors;   friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, const Palette &amp; o) {   os &lt;&lt; &quot;main_color       : &quot; &lt;&lt; color_to_string(o.main_color) &lt;&lt; std::endl;   os &lt;&lt; &quot;background_color : &quot; &lt;&lt; color_to_string(o.background_color) &lt;&lt; std::endl;   os &lt;&lt; &quot;special_colors   : &quot;;   for (auto color : o.special_colors)    os &lt;&lt; color_to_string(color) &lt;&lt; &quot;, &quot;;   os &lt;&lt; std::endl &lt;&lt; &quot;colors           : &quot;;   for (auto [name, color] : o.colors)    os &lt;&lt; &quot;[&quot; &lt;&lt; name &lt;&lt; &quot;, &quot; &lt;&lt; color_to_string(color) &lt;&lt; &quot;], &quot;;   os &lt;&lt; std::endl;    return os;  } };  int main() {  sm::MemberString&lt;Color&gt;::set(color_from_string, color_to_string);   sm::reg(&amp;Palette::main_color, &quot;main_color&quot;, sm::Required{});  sm::reg(&amp;Palette::background_color, &quot;background_color&quot;, sm::Default{Color::blue});  sm::reg(&amp;Palette::special_colors, &quot;special_colors&quot;);  sm::reg(&amp;Palette::colors, &quot;colors&quot;);   Palette palette;   std::istringstream json_data(R&quot;json(  {   &quot;main_color&quot;: &quot;green&quot;,   &quot;special_colors&quot;: [&quot;green&quot;, &quot;green&quot;, &quot;red&quot;],   &quot;colors&quot;: {    &quot;dark&quot;: &quot;green&quot;,    &quot;light&quot;: &quot;red&quot;,    &quot;neutral&quot;: &quot;blue&quot;   }  }  )json&quot;);   sm::map_json_to_struct(palette, json_data);   std::cout &lt;&lt; palette &lt;&lt; std::endl; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">main_color       : green background_color : blue special_colors   : green, green, red,  colors           : [dark, green], [light, red], [neutral, blue],<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"opcii-otobrazheniya\">\u041e\u043f\u0446\u0438\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u041f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044f \u043e\u043f\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044f<\/p>\n<p>  <\/p>\n<ul>\n<li>Bounds<\/li>\n<li>Default<\/li>\n<li>NotEmpty<\/li>\n<li>Required<\/li>\n<\/ul>\n<p>  <\/p>\n<h3 id=\"bounds\">Bounds<\/h3>\n<p>  <\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c (\u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430) \u0434\u043e\u043b\u0436\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u0430 \u0434\u043b\u044f \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0438 \u0442\u0438\u043f\u043e\u0432 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439. \u041e\u043f\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u2014 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430. \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0432\u044b\u0445\u043e\u0434\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">Bounds{\u043d\u0438\u0436\u043d\u044f\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430, \u0432\u0435\u0440\u0445\u043d\u044f\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430}<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043e\u043f\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">reg(&amp;Stage::engine_count, &quot;engine_count&quot;, Bounds{1, 31});<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"default\">Default<\/h3>\n<p>  <\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u043f\u043e\u043b\u044f. \u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u0430 \u0434\u043b\u044f bool, \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0442\u0438\u043f\u043e\u0432 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439, \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0441++ \u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. \u041e\u043f\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0434\u0438\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e.<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">Default{\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e}<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043e\u043f\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">reg(&amp;Stage::engine_count, &quot;engine_count&quot;, Default{3});<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"notempty\">NotEmpty<\/h3>\n<p>  <\/p>\n<p>\u041e\u0442\u043c\u0435\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u044f \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u043f\u0443\u0441\u0442\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u0430 \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a \u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432. \u041e\u043f\u0446\u0438\u044f \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u043b\u0438 \u043f\u0443\u0441\u0442\u043e\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043e\u043f\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">reg(&amp;Spacecraft::name, &quot;name&quot;, NotEmpty{}));<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"required\">Required<\/h3>\n<p>  <\/p>\n<p>\u041e\u0442\u043c\u0435\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u0430 \u0434\u043b\u044f bool, \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432, \u0442\u0438\u043f\u043e\u0432 \u0441 \u043f\u043b\u0430\u0432\u0430\u044e\u0449\u0435\u0439 \u0442\u043e\u0447\u043a\u043e\u0439, \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0441++ \u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. \u041e\u043f\u0446\u0438\u044f \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432. \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u044f \u043d\u0435 \u0431\u044b\u043b\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043e\u043f\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">reg(&amp;Spacecraft::name, &quot;name&quot;, Required{}));<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"primer-ispolzovaniya-opciy\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u043f\u0446\u0438\u0439<\/h3>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &lt;iostream&gt; #include &lt;list&gt; #include &lt;map&gt; #include &lt;sstream&gt; #include &lt;string&gt;  #include &quot;struct_mapping\/struct_mapping.h&quot;  namespace sm = struct_mapping;  struct Stage {  unsigned short engine_count;  std::string fuel;  long length;   friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, const Stage &amp; o) {   os &lt;&lt; &quot;  engine_count : &quot; &lt;&lt; o.engine_count &lt;&lt; std::endl;   os &lt;&lt; &quot;  fuel         : &quot; &lt;&lt; o.fuel &lt;&lt; std::endl;   os &lt;&lt; &quot;  length       : &quot; &lt;&lt; o.length &lt;&lt; std::endl;    return os;  } };  struct Spacecraft {  bool in_development;  std::string name;  int mass;  std::map&lt;std::string, Stage&gt; stages;  std::list&lt;std::string&gt; crew;   friend std::ostream &amp; operator&lt;&lt;(std::ostream &amp; os, const Spacecraft &amp; o) {   os &lt;&lt; &quot;in_development : &quot; &lt;&lt; std::boolalpha &lt;&lt; o.in_development &lt;&lt; std::endl;   os &lt;&lt; &quot;name           : &quot; &lt;&lt; o.name &lt;&lt; std::endl;   os &lt;&lt; &quot;mass           : &quot; &lt;&lt; o.mass &lt;&lt; std::endl;   os &lt;&lt; &quot;stages: &quot; &lt;&lt; std::endl;   for (auto&amp; s : o.stages) os &lt;&lt; &quot; &quot; &lt;&lt; s.first &lt;&lt; std::endl &lt;&lt; s.second;   os &lt;&lt; &quot;crew: &quot; &lt;&lt; std::endl;   for (auto&amp; p : o.crew) os &lt;&lt; &quot; &quot; &lt;&lt; p &lt;&lt; std::endl;    return os;  } };  int main() {  sm::reg(&amp;Stage::engine_count, &quot;engine_count&quot;, sm::Default{6}, sm::Bounds{1, 31});  sm::reg(&amp;Stage::fuel, &quot;fuel&quot;, sm::Default{&quot;subcooled&quot;});  sm::reg(&amp;Stage::length, &quot;length&quot;, sm::Default{50});   sm::reg(&amp;Spacecraft::in_development, &quot;in_development&quot;, sm::Required{});  sm::reg(&amp;Spacecraft::name, &quot;name&quot;, sm::NotEmpty{});  sm::reg(&amp;Spacecraft::mass, &quot;mass&quot;,   sm::Default{5000000}, sm::Bounds{100000, 10000000});  sm::reg(&amp;Spacecraft::stages, &quot;stages&quot;, sm::NotEmpty{});  sm::reg(&amp;Spacecraft::crew, &quot;crew&quot;,   sm::Default{std::list&lt;std::string&gt;{&quot;Arthur&quot;, &quot;Ford&quot;, &quot;Marvin&quot;}});   Spacecraft starship;   std::istringstream json_data(R&quot;json(  {   &quot;in_development&quot;: false,   &quot;name&quot;: &quot;Vostok&quot;,   &quot;stages&quot;: {    &quot;first&quot;: {     &quot;engine_count&quot;: 31,     &quot;fuel&quot;: &quot;compressed gas&quot;,     &quot;length&quot;: 70    },    &quot;second&quot;: {}   }  }  )json&quot;);   sm::map_json_to_struct(starship, json_data);   std::cout &lt;&lt; starship &lt;&lt; std::endl; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">in_development : false name           : Vostok mass           : 5000000 stages:   first   engine_count : 31   fuel         : compressed gas   length       : 70  second   engine_count : 6   fuel         : subcooled   length       : 50 crew:   Arthur  Ford  Marvin<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"obratnoe-otobrazhenie-struktury-c-na-json\">\u041e\u0431\u0440\u0430\u0442\u043d\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b c++ \u043d\u0430 json<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043d\u0430 json \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044f<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">reg(V T::* ptr, std::string const &amp; name, Options&lt;U&gt;&amp;&amp; ... options);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">map_struct_to_json(T &amp; source_struct, std::basic_ostream&lt;char&gt; &amp; json_data, std::string indent);<\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li><code>source_struct<\/code> \u2014 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443<\/li>\n<li><code>json_data<\/code> \u2014 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u043e\u0442\u043e\u043a json \u0434\u0430\u043d\u043d\u044b\u0445<\/li>\n<li><code>indent<\/code> \u2014 \u043e\u0442\u0441\u0442\u0443\u043f (\u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u043d, \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043b\u0443\u0447\u0448\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c)<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &lt;iostream&gt; #include &lt;sstream&gt;  #include &quot;struct_mapping\/struct_mapping.h&quot;  struct OceanPart {  std::string name;  double average_depth;  std::vector&lt;int&gt; temperature; };  struct OceanColor {  std::string name; };  struct Ocean {  double water_volume;  long long surface_area;  bool liquid;  std::string name;   OceanColor color;   std::vector&lt;OceanPart&gt; parts; };  struct Planet {  bool giant;  long long surface_area;  double mass;  double volume;  long long orbital_period;  std::string name;  bool terrestrial;  std::string shape;   Ocean ocean; };  int main() {  struct_mapping::reg(&amp;OceanPart::name, &quot;name&quot;);  struct_mapping::reg(&amp;OceanPart::average_depth, &quot;average_depth&quot;);  struct_mapping::reg(&amp;OceanPart::temperature, &quot;temperature&quot;);   struct_mapping::reg(&amp;OceanColor::name, &quot;name&quot;);   struct_mapping::reg(&amp;Ocean::water_volume, &quot;water_volume&quot;);  struct_mapping::reg(&amp;Ocean::surface_area, &quot;surface_area&quot;);  struct_mapping::reg(&amp;Ocean::liquid, &quot;liquid&quot;);  struct_mapping::reg(&amp;Ocean::name, &quot;name&quot;);  struct_mapping::reg(&amp;Ocean::color, &quot;color&quot;);  struct_mapping::reg(&amp;Ocean::parts, &quot;parts&quot;);   struct_mapping::reg(&amp;Planet::giant, &quot;giant&quot;);  struct_mapping::reg(&amp;Planet::surface_area, &quot;surface_area&quot;);  struct_mapping::reg(&amp;Planet::mass, &quot;mass&quot;);  struct_mapping::reg(&amp;Planet::volume, &quot;volume&quot;);  struct_mapping::reg(&amp;Planet::orbital_period, &quot;orbital_period&quot;);  struct_mapping::reg(&amp;Planet::name, &quot;name&quot;);  struct_mapping::reg(&amp;Planet::terrestrial, &quot;terrestrial&quot;);  struct_mapping::reg(&amp;Planet::shape, &quot;shape&quot;);  struct_mapping::reg(&amp;Planet::ocean, &quot;ocean&quot;);   Planet earth;   earth.giant = false;  earth.terrestrial = true;  earth.surface_area = 510072000;  earth.orbital_period = 365 * 24 * 3600;  earth.mass = 5.97237e24;  earth.name = &quot;Terra&quot;;  earth.volume = 1.08321e12;  earth.shape = &quot;nearly spherical&quot;;   earth.ocean.water_volume = 1332000000;  earth.ocean.surface_area = 361132000;  earth.ocean.liquid = true;  earth.ocean.name = &quot;World Ocean&quot;;  earth.ocean.color.name = &quot;blue&quot;;   OceanPart pacific;  pacific.name = &quot;Pacific Ocean&quot;;  pacific.average_depth = 4.280111;  pacific.temperature = std::vector&lt;int&gt;{-3, 5, 12};   OceanPart atlantic;  atlantic.name = &quot;Atlantic Ocean&quot;;  atlantic.average_depth = 3.646;  atlantic.temperature = std::vector&lt;int&gt;{-3, 0};   earth.ocean.parts.push_back(pacific);  earth.ocean.parts.push_back(atlantic);   std::ostringstream json_data;  struct_mapping::map_struct_to_json(earth, json_data, &quot;  &quot;);   std::cout &lt;&lt; json_data.str() &lt;&lt; std::endl; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">{   &quot;giant&quot;: false,   &quot;surface_area&quot;: 510072000,   &quot;mass&quot;: 5.97237e+24,   &quot;volume&quot;: 1.08321e+12,   &quot;orbital_period&quot;: 31536000,   &quot;name&quot;: &quot;Terra&quot;,   &quot;terrestrial&quot;: true,   &quot;shape&quot;: &quot;nearly spherical&quot;,   &quot;ocean&quot;: {     &quot;water_volume&quot;: 1.332e+09,     &quot;surface_area&quot;: 361132000,     &quot;liquid&quot;: true,     &quot;name&quot;: &quot;World Ocean&quot;,     &quot;color&quot;: {       &quot;name&quot;: &quot;blue&quot;     },     &quot;parts&quot;: [       {         &quot;name&quot;: &quot;Pacific Ocean&quot;,         &quot;average_depth&quot;: 4.28011,         &quot;temperature&quot;: [           -3,           5,           12         ]       },       {         &quot;name&quot;: &quot;Atlantic Ocean&quot;,         &quot;average_depth&quot;: 3.646,         &quot;temperature&quot;: [           -3,           0         ]       }     ]   } }<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"v-itoge\">\u0412 \u0438\u0442\u043e\u0433\u0435<\/h1>\n<p>  <\/p>\n<ul>\n<li>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0441++ \u043c\u043e\u0436\u043d\u043e (\u0438 \u043d\u0443\u0436\u043d\u043e)<\/li>\n<li>Json \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043a\u0430\u043a \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 (\u0442\u0430\u043a\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c), \u0442\u0430\u043a \u0438 \u043d\u0430 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/li>\n<li>Json \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043d\u0430 std::vector \u0438 std::list. \u041e\u0431\u0449\u0438\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430\u043c \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<\/li>\n<li>json \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u043d\u0430 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u044b, \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043a\u043b\u044e\u0447 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u043e\u0439. \u041e\u0431\u0449\u0438\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430\u043c, \u043a\u0430\u043a \u0438 \u0441 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438, \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<\/li>\n<li>\u043c\u0430\u043a\u0440\u043e\u0441\u044b \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u0438 \u0443\u0436 \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c (\u043a\u0430\u043a \u0432\u0430\u0440\u0438\u0430\u043d\u0442) \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438, \u0441\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u043d\u043e\u0439 \u0441 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u043b\u0435\u0439. \u041d\u043e \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u0438\u043b\u0435\u043d\u0430.<\/li>\n<li>\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0446\u0438\u0439<\/li>\n<\/ul>\n<p>  <\/p>\n<p><a href=\"https:\/\/github.com\/bk192077\/struct_mapping\" rel=\"nofollow\">\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043d\u0430 GitHub<\/a><\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/510438\/\"> https:\/\/habr.com\/ru\/post\/510438\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/510438\/\">\n<p><a href=\"https:\/\/habr.com\/ru\/post\/506506\/\">\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442<\/a> \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0441++ \u0438 json \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439 \u0431\u043b\u0438\u043d \u2014 \u043a\u043e\u043c\u043e\u043c. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u2014 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439, \u0438 \u0437\u0430 \u043f\u0435\u0440\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u0442\u043e\u0440\u0430\u044f. \u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 (\u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c) \u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u0434\u044b\u0440\u043e\u043a \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0431\u043b\u0438\u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0438 \u043a\u043e\u0435-\u0447\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-306762","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/306762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=306762"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/306762\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=306762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=306762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=306762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}