简体   繁体   中英

g++: 'class std::map<int, std::vector<std::vector<int> > >' has no member named 'insert_or_assign'

Coding for a problem on leetcode. I am using a std::map to link an int to a vector<vector<int>> . I checked the API on cppreference and am using the function std::map::insert_or_assign() to insert a key-value pair. However upon compiling the code with g++ on windows 10 powershell terminal (editor-VSCode), I get the following output in the terminal.

PS C:\Users\vishw\Desktop\vsCode\p15_leetcode> g++ p15.cpp -o p15.exe
p15.cpp: In member function 'bool Solution::present(std::vector<std::vector<int> >&, std::vector<int>&)':
p15.cpp:75:19: error: 'class std::map<int, std::vector<std::vector<int> > >' has no member named 'insert_or_assign'
             store.insert_or_assign(arg_nums[0], v);

Why do I get this error? C++ version issues? Compiler issues? Kindly help! PFA below my code

class Solution {
private:
    map<int, vector<vector<int>>> store;
public:
    vector<vector<int>> threeSum(vector<int>& arg_nums) {
        vector<vector<int>> vector_return;
        if (arg_nums.size() < 3) return vector_return;
        vector<int> holder;
        for (int index0 = 0; index0 < arg_nums.size() - 2; ++index0) {
            for (int index1 = index0 + 1; index1 < arg_nums.size() - 1; ++index1) {

                if (index1 != index0) {
                    for (int index2 = index1 + 1; index2 < arg_nums.size() - 0; ++index2) {

                        if ((index2 != index1)
                             && (index2 != index0)) {
                            
                            if (arg_nums[index2] + arg_nums[index1] + arg_nums[index0] == 0) {
                                holder = sort(arg_nums[index0], arg_nums[index1],
                                              arg_nums[index2]);
                                if (!present(vector_return, holder)) {
                                    vector_return.push_back(holder);
                                }
                            }
                        }
                    }
                }
            }
        }
        return vector_return;
    }

    vector<int> sort(int arg_num0, int arg_num1, int arg_num2) {
        vector<int> vector_return;
        if (arg_num0 > arg_num1) {
            vector_return.push_back(arg_num0);
            vector_return.insert(vector_return.begin(), arg_num1);
            if (arg_num2 > arg_num0) vector_return.push_back(arg_num2);
            else {
                if ((arg_num2 > arg_num1) && (arg_num2 <= arg_num0)) {
                    vector_return.insert(++vector_return.begin(), arg_num2);
                } else vector_return.insert(vector_return.begin(), arg_num2);
            }
        } else {
            vector_return.push_back(arg_num1);
            vector_return.insert(vector_return.begin(), arg_num0);
            if (arg_num2 > arg_num1) vector_return.push_back(arg_num2);
            else {
                if ((arg_num2 > arg_num0) && (arg_num2 <= arg_num1)) {
                    vector_return.insert(++vector_return.begin(), arg_num2);
                } else vector_return.insert(vector_return.begin(), arg_num2);
            }
        }
        return vector_return;
    }

    bool present(vector<vector<int>>& arg_gathered, vector<int>& arg_nums) {
        if (store.find(arg_nums[0]) == store.end()) {
            vector<vector<int>> v;
            v.push_back(arg_nums);
            store.insert_or_assign(arg_nums[0], v);
            return true;
        } else {
            map<int, vector<vector<int>>>::iterator iterator0 = store.find(arg_nums[0]);
            vector<vector<int>>::iterator iterator1 = (std::get<vector<vector<int>>>(*iterator0)).begin();
            while (iterator1 != std::get<vector<vector<int>>>(*iterator0).end()) {
                if (*iterator1 == arg_nums) return false;
                iterator1 = iterator1 + 1;
            }
            (std::get<vector<vector<int>>>(*iterator0)).push_back(arg_nums);
            return true;
        }
    }
};

This is a simple version issue, thank you acraig5075 for your help (comments below the question), code compiled successfully. Here is how you can specify the c++ version while compiling

g++ -std=c++17 your_program_name.cpp -o you_give_name.exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM