Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it normal practice or very bad to nest maps?

Is it normal practice or very bad to nest maps several levels?

        // name property     // name singal         // interval of Ranges      // values

typedef std::map<std::string, std::map<std::string, std::map<RangeSignalValue, std::string > > > sgHashSignals;
like image 890
G-71 Avatar asked Dec 05 '25 16:12

G-71


2 Answers

I've certainly done this. However, I'd break down the definition into digestible chunks:

typedef std::map<RangeSignalValue, std::string> RangeIntervalMap; 
typedef std::map<std::string, RangeIntervalMap> NameSignalMap;
typedef std::map<std::string, NameSignalMap>    NamePropertyMap;
like image 163
sbi Avatar answered Dec 08 '25 05:12

sbi


If it makes sense in the context you're working in then I don't see any problems, other than it might be hard to read. Might it be possible to use typedef to make some of these nested maps easier to understand?

like image 36
FrustratedWithFormsDesigner Avatar answered Dec 08 '25 05:12

FrustratedWithFormsDesigner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!