const std::map?

前端 未结 2 1731
故里飘歌
故里飘歌 2021-01-12 07:45
// BOOST Includes
#include              // Boost::Assign
#include      // Boost::Assign::List_Of
#include <         


        
相关标签:
2条回答
  • 2021-01-12 08:08

    I would try

    const map<x3_string_tuple, string> query_selector_map = map_list_of<x3_string_tuple, string>
    (x3_string_tuple("4556", "SELECT", "FILENAME"), "4556_SELECT_FILENAME");
    

    But, honestly, maybe it's easier just to have 3 separate lists of strings, and then one-by-one combine them into a tuple and add that to a map.

    0 讨论(0)
  • 2021-01-12 08:27

    I tried this, and it fails because the keys of the map need to be comparable (with std::less, thus there needs to be an operator< defined). boost::tuple's comparison operators are defined in the header boost/tuple/tuple_comparison.hpp.

    Having included that, this code works fine:

    #include <boost/assign/list_of.hpp>
    #include <boost/tuple/tuple.hpp>
    #include <boost/tuple/tuple_comparison.hpp>
    #include <map>
    #include <string>
    
    using std::string;
    typedef boost::tuple<string, string, string> tpl_t;
    
    int main() {
        using boost::assign::map_list_of;
        std::map<tpl_t, string> const m = 
            map_list_of(tpl_t("a","b","c"), "c")(tpl_t("x","y","c"), "z");
    }
    
    0 讨论(0)
提交回复
热议问题