{"id":89,"date":"2007-06-18T14:40:49","date_gmt":"2007-06-18T12:40:49","guid":{"rendered":"http:\/\/appinf.com\/poco\/blog\/?p=89"},"modified":"2007-06-18T14:40:49","modified_gmt":"2007-06-18T12:40:49","slug":"id-rather-write-programs-that-help-me-write-programs-than-write-programs","status":"publish","type":"post","link":"https:\/\/pocoproject.org\/blog\/?p=89","title":{"rendered":"NamedTuple and DynamicAny"},"content":{"rendered":"<p>Since we are doing 1.4 overhaul, I&#8217;m not sure what (if anything) to do about following:<\/p>\n<p>DynamicAny NamedTuple::operator[] (const std::string&amp; name)<\/p>\n<p>It would be nice to be able to do this on a NamedTuple:<\/p>\n<p><code>NamedTuple nt(\"name\", 1);<br \/>\nnt[\"name\"] = 2;<\/code><\/p>\n<p>The way it is done right now is deceptive because it does not modify the tuple itself but the copy of DynamicAny returned by NamedTuple::operator [](). The proper way to modify the NamedTuple value is:<br \/>\n<code><br \/>\nnt.set&lt;0&gt;(2);<\/code><\/p>\n<p>In order for the &#8216;<code>nt[\"name\"] = 2;<\/code>&#8216; syntax to work as expected, the return value should be reference. And that&#8217;s where the downside comes into play &#8211; to return DynamicAny reference instead of copy, one has to have a member container of DynamicAny&#8217;s inside NamedTuple, which, in turn, means duplicating all the values, so I&#8217;m not sure whether the syntactic sugar is really worth it.<\/p>\n<p>Another option (I did not try this, so there may be some obstacles to it) is to enable DynamicAny to act as a wrapper (hold SharedPtr instead of its own copy of the value). I mean this in addition, not as a replacement, to existing implementation.<\/p>\n<p>Any thoughts on the above dilemma and proposal? I&#8217;ll volunteer to implement the changes if any are voted in.<\/p>\n<p>Update: I would rather write programs that help me write programs than write programs, but it was a dumb title for this blog post.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since we are doing 1.4 overhaul, I&#8217;m not sure what (if anything) to do about following: DynamicAny NamedTuple::operator[] (const std::string&amp; name) It would be nice to be able to do this on a NamedTuple: NamedTuple nt(&#8220;name&#8221;, 1); nt[&#8220;name&#8221;] = 2; The way it is done right now is deceptive because it does not modify the [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":0,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/89\/revisions"}],"wp:attachment":[{"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pocoproject.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}