How to create an empty std::map object? [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I tried this:
std::map<int,int> m;
and it works -- m becomes an empty map. But this approach may not work if the compiler choose to not initialize m to an empty map by default. Better solution?

Any better solution?
Taking your question literally, no. There is no better solution.
This will create a default constructed, and therefore empty std::map<int,int>.
std::map<int,int> m;

Related

Calling keys in C++ for their values [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hi I need to type a code which calls the key and its values such as "Tokyo 10 23 32". I can't use arrays or vectors how can I store my data? Thanks.
Use std::map or std::unordered_map. std::map uses a Red-Black tree, and std::unordered_map uses a Hash Table.

Move constructor with vector of pointers [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
How should i do the move constructor for a vector with pointers?
for example :
I have this in class A as a field - vector<A*> AList;
In the function (A &&otherA) ( which is the move constructor) ,
should i write like this :
AList(std::move(other.AList)) or in an other way?
Yes, you can do it like that.
Or, if you don't need the move assignment operator to do anything else, just leave it out and the compiler will do this for you.
This goes for moving any member vector.

storing contents in vectors in C++ language [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How do you store contents in a vector and then sort them without creating a class?
Doing a class project and it requires to not use a class. The books are not helping.
This page has a good example, assuming you can put all of the elements in the vector at once. If you need to put them in one at a time, use std::vector::push_back.
Something like std::vector<std::string> v; v.push_back("hello"); std::sort(v.begin(), v.end());. Get better books.

data type of a and b in map<int,int> a,b [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to learn c++. I was struck at map in c++. Can someone qualitatively explain me what is a map and where is it more often used?
You are wrong about the internals of std::map - it uses a data structure with O(log n) insertion, query and delete times. IIRC, it's a red-black tree. To answer your question, the objects stored are of type map<int,int>::value_type which is std::pair<const int, int>. Here's the ref.

How to sort a pair of keys and values using boost? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Is there some function in boost library which can sort key-value pairs?
e.g. keys being an array of double variables, and values are some index (integer) of the array.
What you probably want is a std::map<My_Double_Array, size_t> along with your own My_Double_Array class that wraps your array of double variables and provides a operator <() for sorting. Or simply std::map<std::vector<double>, size_t> might be all you need.