如何用比较功能制作一套? [英] how can i make a set with comparison function ?
问题描述
如何制作具有比较功能的套装?
所有我知道我可以用这样的比较功能制作地图
struct strCmp {
bool operator()(const char * s1,const char * s2)const {
return strcmp(s1,s2)< 0;
}
};
map< const char *,int,strCmpages;
>
我怎么能用比较函数制作整数集?
struct Cmp
{
bool运算符()(const int * s1,const int * s2)const {
返回s1< = s2? true:false;
}
};
set< int,Cmp s;
how can i make a set with comparison function ?
all i know that i can make a map with comparison function like this
struct strCmp {
bool operator()( const char* s1, const char* s2 ) const {
return strcmp( s1, s2 ) < 0;
}
};
map<const char*, int, strCmpages;
while how can i make set of integers with comparison function ?
struct Cmp
{
bool operator()( const int* s1, const int* s2 ) const {
return s1<=s2 ? true : false ;
}
};
set < int , Cmp s;
推荐答案
PicO写道:
PicO wrote:
how我可以用比较功能制作一套吗?
所有我知道我可以用这样的比较功能制作地图
how can i make a set with comparison function ?
all i know that i can make a map with comparison function like this
与std :: set相同。
-
Ian Collins。
Same with std::set.
--
Ian Collins.
Ian Collins写道:
Ian Collins wrote:
PicO写道:
PicO wrote:
>我如何使用比较函数创建一个集合?
所有我知道我可以用这样的比较函数制作地图
>how can i make a set with comparison function ?
all i know that i can make a map with comparison function like this
与std :: set相同。
Same with std::set.
但是,一旦元素出现在集合中,就无法修改用于比较的字段
。
However, once an element is in the set, you cannot modify the fields
that you use for the comparison.
8月9日上午12:25,red floyd< no.s ... @ here.dudewrote:
On Aug 9, 12:25 am, red floyd <no.s...@here.dudewrote:
I一个柯林斯写道:
Ian Collins wrote:
PicO写道:
PicO wrote:
如何用比较函数创建一个集合?
how can i make a set with comparison function ?
我知道我可以制作一个像这样的比较函数的地图
all i know that i can make a map with comparison function like this
与std :: set相同。
Same with std::set.
但是,一旦元素出现在集合中,就无法修改用于比较的字段
。
However, once an element is in the set, you cannot modify the fields
that you use for the comparison.
i不想修改集合中已有的元素..我想得到
通过比较设置排序元素或对象功能如我所愿(如地图
以上例子)..
i don''t want to modify an element already in the set .. i want to get
set sort element or object by compare function as i want ( like in map
in example above ) ..
这篇关于如何用比较功能制作一套?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!