user3665224
user3665224

Reputation: 1357

Is creating complex STL Containers efficient?

I am going through some codes that create complex stl containers as below.

map<string, list<pair<string, set<complexclassX*>>>>

or like

map<string, list<pair<complexclassX*, set<complexclassY*>>>>

Here, map, list set, pair are all used for one object. Is it a good practice or can it be better designed ?

Upvotes: 2

Views: 98

Answers (1)

Daniel
Daniel

Reputation: 31579

Specifically the contains you posted have no efficiency problem of being nested.
Containers that are moving elements like vector do. But with move constructors their cost is low, while not as low as pointers.
If you want to use containers like vector, wrapping the type with unique_ptr would have almost the same cost as pointers but you won't have to manage memory.

In any case, the container you posted looks complex. Splitting it to classes where each one contains one container will be more readable.

Upvotes: 2

Related Questions