Re: Perl style hash
Sam wrote:
So? This calls for an overloaded Anything::operator=():
class Anything {
public:
// ..
Anything &operator=(double);
Anything &operator=(int);
Anything &operator=(std::string);
};
Okee-dokee.
And even if you could, you still wouldn't have the perl-style
behavior that I described. If you tried:
x["root"]["branch"]["leaf"] = 5;
the compiler would not know how to resolve the second (and third) set
of braces.
Of course it would. It's merely a matter of implementing operator[]()
accordingly.
I like the simplicity of this approach. The way I'm doing it now, I'll
have to add an iterator class to my wrapper, etc, which stinks. Your way,
I'd just be using std::map directly.
But I still don't quite see how the second and third sets of [] would work.
The first one, x["root"], is going to return an Antyhing&. So, class
Anything would have to also have a [] operator. How would the returned
Anything object access "x", which would be of type std::map?