Well.. By each string (name) I only need one bool and vector <string> .. so I should use pair for this? Names (string) should also be unique, thats why I wanted to go for map (would be easier)..
Edit: Why did my post go to the top?
Printable View
Well.. By each string (name) I only need one bool and vector <string> .. so I should use pair for this? Names (string) should also be unique, thats why I wanted to go for map (would be easier)..
Edit: Why did my post go to the top?
I would make a class. Whether you include the name in the class or not depends on whether the name is a logical part of whatever data you are trying to represent. If you include it in the class, then you can make a set of your class objects, and create an operator< for the class that compares only the name. Or if the name is not part of the class or if you might be changing names as you go, then use a map of string to class objects.
As you said, if the list is big, it might be better to use a smart pointer. You can encapsulate that in the class itself so that when the class is copied the list is not.
>> Why did my post go to the top?
They fixed the time on the forum which apparently through off some post times.
Hello..
I need to store data in a map/class that way (and I wonder what would be better to use):
I need a list of 3 things:
string name;
bool is_static;
vector <string> list_;
So I could use:
orCode:map <string, map <bool, vector <string> > >
The list 'may' be huge, and thats why I think it would be smarter to pass it to the function as a smart pointer..Code:class some_class {
public:
string name;
bool is_static;
vector <string> list_;
}
What do you think would be best choice/approach to do?
If you are going to pass a large object to a function, it is usually far better to pass it by reference. It makes it easier on the stack heap, and takes less memory to complete the job.
Is name unique?
Despite being unique, do you want the list to be keyed on it?
Edit:
On a side note, map <bool, vector <string> is a no-no, unless really that is what you want. To have a map that can only take 2 entries. One for false and one for true. The alternative here would be:
map <string, pair <bool, vector <string> > >, or a multimap.