Overview
Features
Download
Documentation
Community
Add-Ons & Services
The POCO C++ Libraries Blog

NamedTuple and DynamicAny

Filed under: Uncategorized by alex at 14:40

Since we are doing 1.4 overhaul, I’m not sure what (if anything) to do about following:

DynamicAny NamedTuple::operator[] (const std::string& name)

It would be nice to be able to do this on a NamedTuple:

NamedTuple nt("name", 1);
nt["name"] = 2;

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:

nt.set<0>(2);

In order for the ‘nt["name"] = 2;‘ syntax to work as expected, the return value should be reference. And that’s where the downside comes into play – to return DynamicAny reference instead of copy, one has to have a member container of DynamicAny’s inside NamedTuple, which, in turn, means duplicating all the values, so I’m not sure whether the syntactic sugar is really worth it.

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.

Any thoughts on the above dilemma and proposal? I’ll volunteer to implement the changes if any are voted in.

Update: I would rather write programs that help me write programs than write programs, but it was a dumb title for this blog post.

No Comments »

No comments yet.

RSS RSS feed for comments on this post. TrackBack URI

Leave a comment