lundi 6 mai 2019

cpp wrong number of template arguments

I have writtne the function below which iterates through a map whose primary key is a pair and secondary pair is a string. The goal is to get all primary+secondary key pairs whose value matches a given value. I wanted to store the result in a vector of pairs of pairs as shown below:

vector<pair<string, pair<int, int> > > get_splits_direction_with(map<pair<int, int>, map<string, double>> nodes_expanded_direction, double minimum)
    {
        vector<string> directions = {"forward", "backward"}; 
        vector<pair<string, pair<int, int>>> result;
        for (auto it = nodes_expanded_direction.begin(); it != nodes_expanded_direction.end(); ++it)
        {
            for (string direction : directions)
            {
                if (it->second[direction] == minimum)
                {
                    pair<string, pair<int, int>> p(direction, it->first);
                    result.push_back(p);
                }
            }

        }
        return result;
    }

When I call the function with:

vector<pair<string direction, pair<int, int> > > min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction);

the following error output is produced:

vector > > min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction);

root@DESKTOP-1066SO9:/mnt/c/projects/a-star# make get_optimal_split_direction > direction.output In file included from get_optimal_split_direction.cpp:16:0: lib/my_lib/vector_ops.hpp: In function ‘std::vector > get_min_splits(bool, DB, std::__cxx11::string, std::__cxx11::string, int, int, std::__cxx11::string, std::__cxx11::string, std::__cxx11::string)’: lib/my_lib/vector_ops.hpp:348:48: error: wrong number of template arguments (1, should be 2) vector>> min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction); ^~ In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0, from /usr/include/c++/7/bits/char_traits.h:39, from /usr/include/c++/7/ios:40, from /usr/include/c++/7/ostream:38, from /usr/include/c++/7/iostream:39, from get_optimal_split_direction.cpp:4: /usr/include/c++/7/bits/stl_pair.h:198:12: note: provided for ‘template struct std::pair’ struct pair ^~~~ In file included from get_optimal_split_direction.cpp:16:0: lib/my_lib/vector_ops.hpp:348:50: error: template argument 1 is invalid vector>> min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction); ^ lib/my_lib/vector_ops.hpp:348:50: error: template argument 2 is invalid lib/my_lib/vector_ops.hpp:348:161: error: cannot convert ‘std::vector, std::pair > >’ to ‘int’ in initialization vector>> min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction); ^ make: * [get_optimal_split_direction] Error 1 root@DESKTOP-1066SO9:/mnt/c/projects/a-star# make get_optimal_split_direction > direction.output root@DESKTOP-1066SO9:/mnt/c/projects/a-star# make get_optimal_split_direction > direction.output root@DESKTOP-1066SO9:/mnt/c/projects/a-star# make get_optimal_split_direction > direction.output In file included from get_optimal_split_direction.cpp:16:0: lib/my_lib/vector_ops.hpp: In function ‘std::vector > get_min_splits(bool, DB, std::__cxx11::string, std::__cxx11::string, int, int, std::__cxx11::string, std::__cxx11::string, std::__cxx11::string)’: lib/my_lib/vector_ops.hpp:348:48: error: wrong number of template arguments (1, should be 2) vector>> min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction); ^~ In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0, from /usr/include/c++/7/bits/char_traits.h:39, from /usr/include/c++/7/ios:40, from /usr/include/c++/7/ostream:38, from /usr/include/c++/7/iostream:39, from get_optimal_split_direction.cpp:4: /usr/include/c++/7/bits/stl_pair.h:198:12: note: provided for ‘template struct std::pair’ struct pair ^~~~ In file included from get_optimal_split_direction.cpp:16:0: lib/my_lib/vector_ops.hpp:348:50: error: template argument 1 is invalid vector>> min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction); ^ lib/my_lib/vector_ops.hpp:348:50: error: template argument 2 is invalid lib/my_lib/vector_ops.hpp:348:161: error: cannot convert ‘std::vector, std::pair > >’ to ‘int’ in initialization vector>> min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction); ^ make: * [get_optimal_split_direction] Error 1 root@DESKTOP-1066SO9:/mnt/c/projects/a-star# make get_optimal_split_direction > direction.output In file included from get_optimal_split_direction.cpp:16:0: lib/my_lib/vector_ops.hpp: In function ‘std::vector > get_min_splits(bool, DB, std::__cxx11::string, std::__cxx11::string, int, int, std::__cxx11::string, std::__cxx11::string, std::__cxx11::string)’: lib/my_lib/vector_ops.hpp:348:50: error: wrong number of template arguments (1, should be 2) vector > > min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction); ^ In file included from /usr/include/c++/7/bits/stl_algobase.h:64:0, from /usr/include/c++/7/bits/char_traits.h:39, from /usr/include/c++/7/ios:40, from /usr/include/c++/7/ostream:38, from /usr/include/c++/7/iostream:39, from get_optimal_split_direction.cpp:4: /usr/include/c++/7/bits/stl_pair.h:198:12: note: provided for ‘template struct std::pair’ struct pair ^~~~ In file included from get_optimal_split_direction.cpp:16:0: lib/my_lib/vector_ops.hpp:348:52: error: template argument 1 is invalid vector > > min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction); ^ lib/my_lib/vector_ops.hpp:348:52: error: template argument 2 is invalid lib/my_lib/vector_ops.hpp:348:163: error: cannot convert ‘std::vector, std::pair > >’ to ‘int’ in initialization vector > > min_splits_direction = get_splits_direction_with(nodes_expanded_direction, min_split_nodes_expanded_direction); ^ make: *** [get_optimal_split_direction] Error 1

Aucun commentaire:

Enregistrer un commentaire