Bonjour, comme déjà décrit dans l'autre topic, j'ai un problème pour avoir le min_element d'une map selon un foncteur/prédicat personnalisé.
Mon premier problème étant les paramètres de l'opérateur() du foncteur.

Voici un code exemplaire:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
class Foo
{
public:
	std::string at_attr;
	std::string elem;
	int num;
 
	Foo() :
		at_attr(""),
		elem(""),
		num(0)
	{
	}
 
	Foo(std::string at, std::string e, int i) :
		at_attr(at),
		elem(e),
		num(i)
	{
	}
 
	Foo(Foo& f) :
		at_attr(f.at_attr),
		elem(f.elem),
		num(f.num)
	{
	}
 
	Foo& operator=(Foo& f)
	{
		this->at_attr = f.at_attr;
		this->elem = f.elem;
		this->num = f.num;
		return *this;
	}
};
 
typedef boost::shared_ptr<Foo> FooPtr;
 
typedef std::map<std::string, FooPtr> MsFoo;
 
struct Foo_smaller
{
	bool operator()(const FooPtr& a, const FooPtr& b)
	{
		return a->num < b->num;
	}
};
 
int main(int argc, char** argv)
{
	MsFoo foomap;
	FooPtr p1(new Foo("agv", "bla", 5));
	FooPtr p2(new Foo("ffgfg", "fdfd", 98));
	FooPtr p3(new Foo("poer", "dhh", 457));
	foomap["agv"] = p1;
	foomap["fhvbd"] = p2;
	foomap["puer"] = p3;
 
	MsFoo::iterator it3 = std::min_element(foomap.begin(), foomap.end(), Foo_smaller());
	std::cout << "min_element of foomap: " << it3->first << " => " 
		<< "at_attr_ " << it3->second->at_attr 
		<< "elem_ " << it3->second->elem
		<< "num_ " <<it3->second->num
		<< std::endl;
 
	return 0;
}
l'erreur de compilation obtenue est la suivante:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
error C2664: 'bool Foo_smaller::operator ()(const FooPtr &,const FooPtr &)': Conversion of parameter 1 from 'std::pair<_Ty1,_Ty2>' into 'const FooPtr &' impossible with
[
            _Ty1=const std::string,
            _Ty2=FooPtr
]
Si quelqu'un à un soupcon d'idée, je suis preneur.