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
| struct Compare
{
typedef std::unique_ptr<NumericalConstant const> ptr_type;
// Pour le placement dans la collection
bool operator () (ptr_type const& x, ptr_type const& y) const
{
return (x->getIntValue() < y->getIntValue());
}
// Pour le test d'appartenance
bool operator () (ptr_type const& x, int y) const
{
return (x->getIntValue() < y);
}
bool operator () (int x, ptr_type const& y) const
{
return (x < y->getIntValue());
}
}; // struct Compare
class NumericalConstantList : private std::set<std::unique_ptr<NumericalConstant const>, Compare>
{
typedef std::set<std::unique_ptr<NumericalConstant const>, Compare> _base;
(...)
public:
const_iterator find(int value) const
{
const_iterator pos = begin();
while ((pos != end()) && key_comp()(*pos, value))
++pos;
if ((pos != end()) && !key_comp()(value, *pos))
return pos;
return end();
}
std::pair<const_iterator, bool> insert(value_type&& value)
{
const_iterator pos = begin();
while ((pos != end()) && key_comp()(*pos, value))
++pos;
if ((pos != end()) && !key_comp()(value, *pos))
return std::make_pair(pos, false);
return _base::insert(pos, std::move(value));
}
}; |