can the boost multi-array be easily extended to std::map's?

I'm working on an application (a data analysis system built in C++) for which it would be helpful to have nested (multidimensional) containers other than ordinary arrays. I have defined a generic 'data' class which I like to store in std::vector<data *>'s. For a very simple example, a 'data' might be a double representing a student's score on an exam, or in more complex settings it might be some sort of spatial map, or a multidimensional set of records for a medical patient. I am interested in structures where 'data' is nested across multiple levels. For example, test scores are nested within students, students nested within teachers, nested within school districts, etc. For a single layer of nesting a std::map<std::string, std::vector<data *> > seems to be an ideal way to store such data, largely because text strings can be used to identify subjects: dat["johnny"] // returns a std::vector of pointers to johnny's test scores. This is often the way that data are stored in files to be analyzed. I'm looking for some sort of C++ container that is more convenient for multiply nested data than std::map<std::string, std::map<std::string .... , std::vector<data *> > > ... >, but which will allow me to write expressions like: dat["LAUSD"]["Central High"]["Ms. Jones' Class"]["Johnny"] // same vector as above. Can something like the Boost multi-array package be extended to handle this?

On Mon, 23 Aug 2004 08:42:09 -0700, Steven L. Scott <sls@usc.edu> wrote:
I'm working on an application (a data analysis system built in C++) for which it would be helpful to have nested (multidimensional) containers other than ordinary arrays.
I've been toying with using boost::variant for something like this - an arbitrarily nested data structure that could be used like the hashes in Perl/Python etc. Unfortunately, because boost::variant doesn't know about the std::map operators, you can't use code like thedata["first"]["second"] but you can write something like this (data_t is used just to gain the syntactic sugar of std::map::operator[]) #include <map> #include <string> #include <boost/variant.hpp> typedef boost::make_recursive_variant< int, double, std::string, std::map<std::string, boost::recursive_variant_> >::type atom_t; typedef std::map<std::string, atom_t> data_t; int main () { data_t scores, student_scores; student_scores["Midterm"] = 90.0; student_scores["Final"] = 88.0; scores["johnny"] = student_scores; } I'd love to get some feedback on this approach, especially if anyone has a solution for implementing data["foo"]["bar"] etc. -- Caleb Epstein caleb.epstein@gmail.com
participants (2)
-
Caleb Epstein
-
Steven L. Scott