const std::map?

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


        
2条回答
  •  庸人自扰
    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 
    #include 
    #include 
    #include 
    #include 
    
    using std::string;
    typedef boost::tuple tpl_t;
    
    int main() {
        using boost::assign::map_list_of;
        std::map const m = 
            map_list_of(tpl_t("a","b","c"), "c")(tpl_t("x","y","c"), "z");
    }
    

提交回复
热议问题