Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 插入到多重映射c++;_C++_Class_Dictionary_Tree_Multimap - Fatal编程技术网

C++ 插入到多重映射c++;

C++ 插入到多重映射c++;,c++,class,dictionary,tree,multimap,C++,Class,Dictionary,Tree,Multimap,我已经得到了一个mutlimap typedef std::multimap<std::string, size_t, StringLenCmp> wordDictType; 或 但我不知道StringLenCmp是什么。是这个班, class StringLenCmp { public: StringLenCmp() = default; // sort by length first, and then alphabetically bool op

我已经得到了一个mutlimap

typedef std::multimap<std::string, size_t, StringLenCmp> wordDictType;

但我不知道StringLenCmp是什么。是这个班,

class StringLenCmp {

public:

    StringLenCmp() = default;

    // sort by length first, and then alphabetically
    bool operator()(const std::string& a, const std::string& b) const {
        return (a.size() < b.size()) || (a.size() == b.size() && a < b);
    }

private:
    // no data
};
class-StringLenCmp{
公众:
StringLenCmp()=默认值;
//先按长度排序,然后按字母顺序排序
布尔运算符()(常数std::string&a,常数std::string&b)常数{
返回(a.size()
但问题是,我不知道这一切意味着什么

有人能帮我破译这一切吗

如您所知,
std::multimap
定义为

template < class Key,                                     // multimap::key_type
           class T,                                       // multimap::mapped_type
           class Compare = less<Key>,                     // multimap::key_compare
           class Alloc = allocator<pair<const Key,T> >    // multimap::allocator_type
           > class multimap;
template类多重映射;

参数
class Compare
是默认情况下根据键值按升序(
less
)排序的部分,但您可以定义对地图中的元素进行自定义排序,而
class StringLenCmp
正是这样做的。每个元素在插入期间都会被检查和排序。

它是比较函数的一个函子,用于“排序”多重映射


或者只是一个包含运算符重载的类,这样它就可以确定这两个元素中的任何一个是否较大、较小或相等。

第三个参数用于对映射进行排序或排序。
class StringLenCmp {

public:

    StringLenCmp() = default;

    // sort by length first, and then alphabetically
    bool operator()(const std::string& a, const std::string& b) const {
        return (a.size() < b.size()) || (a.size() == b.size() && a < b);
    }

private:
    // no data
};
template < class Key,                                     // multimap::key_type
           class T,                                       // multimap::mapped_type
           class Compare = less<Key>,                     // multimap::key_compare
           class Alloc = allocator<pair<const Key,T> >    // multimap::allocator_type
           > class multimap;