Oprava metody PorovnejCislo.
#include <iostream>
#include <list>
#include <algorithm>
// tady si nastav jednu z variant 1 az 4
#define VARIANTA 2
#if VARIANTA==3 || VARIANTA==4
#include <boost/lambda/lambda.hpp>
#include <boost/bind.hpp>
#endif
struct struktura
{
struktura(unsigned cislo, int data)
: cislo(cislo),
data(data)
{
}
#if VARIANTA==1
operator unsigned() const
{
return cislo;
}
#endif
#if VARIANTA==2
bool PorovnejCislo(
unsigned c
) const
{
return cislo == c;
}
#endif
#if VARIANTA==4
unsigned GetCislo() const { return cislo; }
#endif
unsigned int cislo;
int data;
};
typedef
std::list<struktura> L;
int main()
{
L l;
l.push_back(struktura(4, 1));
l.push_back(struktura(5, 2));
l.push_back(struktura(1, 3));
l.push_back(struktura(12, 4));
l.push_back(struktura(100, 5));
l.push_back(struktura(3, 6));
#if VARIANTA==1
L::const_iterator it = std::find_if(
l.begin(), // Odkud
l.end(), // Pokud
std::bind2nd(std::equal_to<unsigned>(), 12U) // Vyuziti moznosti pretypovani struktury na unsigned
);
#elif VARIANTA==2
L::const_iterator it = std::find_if(
l.begin(), // Odkud
l.end(), // Pokud
std::bind2nd(std::mem_fun_ref(&struktura::PorovnejCislo), 12U)
);
#elif VARIANTA==3
L::const_iterator it = std::find_if(
l.begin(), // Odkud
l.end(), // Pokud
boost::bind(&struktura::cislo, _1) == 12U
);
#elif VARIANTA==4
L::const_iterator it = std::find_if(
l.begin(), // Odkud
l.end(), // Pokud
boost::bind(&struktura::GetCislo, _1) == 12U
);
#endif
if (it == l.end())
std::cout << "Nenalezeno\n";
else
std::cout << "Nalezeno " << it->cislo << ", " << it->data << '\n';
}