Test non-default compare template argument in std::map
This commit is contained in:
parent
967776189e
commit
dcbccc6f6f
3 changed files with 47 additions and 0 deletions
|
|
@ -117,4 +117,25 @@ namespace std {
|
|||
}
|
||||
}
|
||||
|
||||
%ignore LengthCompare::operator();
|
||||
%inline %{
|
||||
struct LengthCompare {
|
||||
bool operator() (std::string s1, std::string s2) const {
|
||||
return s1.size() < s2.size();
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
// A map sorted by string lengths
|
||||
%template(StringLengthNumberMap) std::map< std::string, int, LengthCompare >;
|
||||
|
||||
%inline %{
|
||||
std::map< std::string, int, LengthCompare > MyMap;
|
||||
void populate(std::map< std::string, int, LengthCompare >&m) {
|
||||
m["aa"] = 2;
|
||||
m["xxxx"] = 4;
|
||||
m["a"] = 1;
|
||||
m["aaaaa"] = 5;
|
||||
m["zzz"] = 3;
|
||||
}
|
||||
%}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue