stl

map/unordered_map with non-movable, default constructible value type

三世轮回 提交于 2021-01-27 11:28:46
问题 Update : It appears, in 23.5.4.3 here that the m[1] version should be valid Update2 : m[1] is working with gcc4.9.1 specifically, std::mutex . Let's say I want to have a std::unordered_map<int, std::mutex> . Is this possible? I can't seem to add a mutex to the map without triggering an error on a deleted copy constructor at some level, either of the mutex or of the intern std::pair holding the mutex. m.emplace(1); m.emplace(1, {}); m[1]; all fail to compile. All I really want is for the mutex

map/unordered_map with non-movable, default constructible value type

点点圈 提交于 2021-01-27 11:27:50
问题 Update : It appears, in 23.5.4.3 here that the m[1] version should be valid Update2 : m[1] is working with gcc4.9.1 specifically, std::mutex . Let's say I want to have a std::unordered_map<int, std::mutex> . Is this possible? I can't seem to add a mutex to the map without triggering an error on a deleted copy constructor at some level, either of the mutex or of the intern std::pair holding the mutex. m.emplace(1); m.emplace(1, {}); m[1]; all fail to compile. All I really want is for the mutex

map/unordered_map with non-movable, default constructible value type

此生再无相见时 提交于 2021-01-27 11:27:01
问题 Update : It appears, in 23.5.4.3 here that the m[1] version should be valid Update2 : m[1] is working with gcc4.9.1 specifically, std::mutex . Let's say I want to have a std::unordered_map<int, std::mutex> . Is this possible? I can't seem to add a mutex to the map without triggering an error on a deleted copy constructor at some level, either of the mutex or of the intern std::pair holding the mutex. m.emplace(1); m.emplace(1, {}); m[1]; all fail to compile. All I really want is for the mutex

map/unordered_map with non-movable, default constructible value type

蹲街弑〆低调 提交于 2021-01-27 11:23:26
问题 Update : It appears, in 23.5.4.3 here that the m[1] version should be valid Update2 : m[1] is working with gcc4.9.1 specifically, std::mutex . Let's say I want to have a std::unordered_map<int, std::mutex> . Is this possible? I can't seem to add a mutex to the map without triggering an error on a deleted copy constructor at some level, either of the mutex or of the intern std::pair holding the mutex. m.emplace(1); m.emplace(1, {}); m[1]; all fail to compile. All I really want is for the mutex

Bewildering SegFault involving STL sort algorithm

六眼飞鱼酱① 提交于 2021-01-27 05:41:24
问题 I am trying to recreate the program in Column 15 of programming pearls using the STL. I am trying to create a suffix array using a string and a vector of indices. I record the list of words that I read in a string called input that acts as a list of words separated by ' ' that I read from stdin at the beginning of the program. Everything works as expected until I get to the sorting portion of the code. I'd like to use the STL's sort algorithm, but I am completely perplexed at a seg fault that

Practical use of vector::max_size

社会主义新天地 提交于 2021-01-27 04:28:49
问题 This question got me thinking about the max_size method in vector class. It is quite apparent that practically the number of elements contained in the vector will be much lesser than what max_size returns. So I was wondering where this will be useful? Any clues? 回答1: It really isn't very useful. The only theoretical usage would be to check that if you need a container larger than max_size() , you are in trouble. But you would probably realize that already when considering a port of your

Practical use of vector::max_size

谁说我不能喝 提交于 2021-01-27 04:28:38
问题 This question got me thinking about the max_size method in vector class. It is quite apparent that practically the number of elements contained in the vector will be much lesser than what max_size returns. So I was wondering where this will be useful? Any clues? 回答1: It really isn't very useful. The only theoretical usage would be to check that if you need a container larger than max_size() , you are in trouble. But you would probably realize that already when considering a port of your

Initializing an array of pair in C++

浪尽此生 提交于 2021-01-27 04:19:02
问题 I want to initialize an array of pair in the following way: pair<int, int> adjs[4] = {{current_node.first-1, current_node.second}, {current_node.first+1, current_node.second}, {current_node.first, current_node.second-1}, {current_node.first, current_node.second+1}}; However my compiler, Code::Blocks 12.1, keeps on throwing the error: brace-enclosed initializer used to initialize `std::pair<int, int>'| I used this method once before on an online compiler and it worked. So is it the problem

Initializing an array of pair in C++

雨燕双飞 提交于 2021-01-27 04:17:15
问题 I want to initialize an array of pair in the following way: pair<int, int> adjs[4] = {{current_node.first-1, current_node.second}, {current_node.first+1, current_node.second}, {current_node.first, current_node.second-1}, {current_node.first, current_node.second+1}}; However my compiler, Code::Blocks 12.1, keeps on throwing the error: brace-enclosed initializer used to initialize `std::pair<int, int>'| I used this method once before on an online compiler and it worked. So is it the problem

Modify key of std::map

别来无恙 提交于 2021-01-26 17:59:04
问题 Is there a way to modify the key of a std::map or ? This example shows how to do so with rebalancing the tree. But what if I provide some guarantees that the key won't need to be rebalanced? #include <vector> #include <iostream> #include <map> class Keymap { private: int key; // this key will be used for the indexing int total; public: Keymap(int key): key(key), total(0) {} bool operator<(const Keymap& rhs) const{ return key < rhs.key; } void inc() { total++; } }; std::map<Keymap, int> my