Re: Can associative arrays be implemented by operator overloading?
On Nov 19, 11:40 pm, Ian Collins <ian-n...@hotmail.com> wrote:
Ramon F Herrera wrote:
I am looking for a good excuse to pick up C++. I have been a satisfied
C programmer for years, a language that provides me all the facilities
that I need, with ONE exception.
I keep on finding programming problems that can be nicely solved by
the use of relational arrays. I wish I could count on the simplicity
of expression afforded by Java:
array.put(key, data);
or -even better- by Perl:
pictureOf{"ramon"} = myimage.gif; // or something to that effect
My question is two-fold:
(1) Which relational array implementation should I use?
Heterogeneous or homogeneous? For the latter, std::map probably gives
you what you want, for the former, look at boost.
Hadn't thought about it, but my stuff is pretty homogeneous.
(2) Let's say I found a perfect implementation that suits my needs. Is
there a way to overload the bracket operators to make them behave like
in Perl? Please don't tell me that the only interesting/elegant case
of operator overloading is in complex arithmetic!
Given:
std::map<std::string,int> myMap;
myMap["ramon"] = 42.
I am sold! Let the C++ cramming begin...
Thanks++! (*)
-Ramon
(*) don't want to imply that the question is closed, as I am very
interesting on the whole topic.