#include <list>
#include <functional>
#include <algorithm>
#include <iostream>
using namespace std;
typedef struct astruct {
astruct(int _a, int _b) : a(_a), b(_b){}
int a;
int b;
}astruct;template <class T>
class in_adver : public binary_function<T, int, bool>
{
public:
bool operator()(T it, int id)
{
return (it->a == id);
}
};typedef list<astruct> LIST;
int main(int argc, char* argv[])
{
LIST l;
for (int i = 0; i < 50; i++)
l.push_back(astruct(i, -i));
list<int> l2;
for (i = 0; i < 10; i++)
l2.push_back(i * 5);
list<int>::iterator it = l2.begin();
for ( ; it != l2.end(); ++it)
remove_if(l.begin(), l.end(),
binder2nd<in_adver<LIST::iterator> >(
in_adver<LIST::iterator>(), *it));
LIST::iterator it2 = l.begin();
for ( ; it2 != l.end(); ++it2)
cout << "(" << it2->a << "," << it2->b << ")" << endl; return 0;
}
#include <functional>
#include <algorithm>
#include <iostream>
using namespace std;
typedef struct astruct {
astruct(int _a, int _b) : a(_a), b(_b){}
int a;
int b;
}astruct;template <class T>
class in_adver : public binary_function<T, int, bool>
{
public:
bool operator()(T it, int id)
{
return (it->a == id);
}
};typedef list<astruct> LIST;
int main(int argc, char* argv[])
{
LIST l;
for (int i = 0; i < 50; i++)
l.push_back(astruct(i, -i));
list<int> l2;
for (i = 0; i < 10; i++)
l2.push_back(i * 5);
list<int>::iterator it = l2.begin();
for ( ; it != l2.end(); ++it)
remove_if(l.begin(), l.end(),
binder2nd<in_adver<LIST::iterator> >(
in_adver<LIST::iterator>(), *it));
LIST::iterator it2 = l.begin();
for ( ; it2 != l.end(); ++it2)
cout << "(" << it2->a << "," << it2->b << ")" << endl; return 0;
}
解决方案 »
- 如何 响应 CTabCtrl Item 的双击消息
- ado中m_recordset->Open失败(拜托看一下)
- 哪位大侠能讲一下VS2003下编写ATL Project与VS6.0下的区别?100分!
- VC中怎样读取和设置系统BIOS的参数
- ==========opentuxedo(开缝的燕尾服)=======请进========CArray又有新问题了
- 低级问题:控制台程序下有kbhit函数来结束循环,窗口程序MFC或API有哪个?
- 关于窗口的消息问题……
- 如何改变CRichEditView中选中文字的字体?????
- BITMAPV5HEADER' : undeclared identifier 为啥呢?
- 如何模拟Alt+N消息?
- 关于ADO的问题,请大家帮忙,参予有分,在线等待
- 请教关于多列排序的算法。(高手请进)谢谢
c:\program files\microsoft visual studio\vc98\include\algorithm(50) : error C2664: '()' : cannot convert parameter 1 from 'struct astruct' to 'const class std::list<struct astruct,class std::allocator<struct astruct> >::iterator &'
Reason: cannot convert from 'struct astruct' to 'const class std::list<struct astruct,class std::allocator<struct astruct> >::iterator'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\program files\microsoft visual studio\vc98\include\algorithm(299) : see reference to function template instantiation 'class std::list<struct astruct,class std::allocator<struct astruct> >::iterator __cdecl std::find_if(class std::list<str
uct astruct,class std::allocator<struct astruct> >::iterator,class std::list<struct astruct,class std::allocator<struct astruct> >::iterator,class std::binder2nd<class in_adver<class std::list<struct astruct,class std::allocator<struct astruct> >::i
terator> >)' being compiled
c:\program files\microsoft visual studio\vc98\include\algorithm(50) : error C2064: term does not evaluate to a function
c:\program files\microsoft visual studio\vc98\include\algorithm(299) : see reference to function template instantiation 'class std::list<struct astruct,class std::allocator<struct astruct> >::iterator __cdecl std::find_if(class std::list<str
uct astruct,class std::allocator<struct astruct> >::iterator,class std::list<struct astruct,class std::allocator<struct astruct> >::iterator,class std::binder2nd<class in_adver<class std::list<struct astruct,class std::allocator<struct astruct> >::i
terator> >)' being compiled
c:\program files\microsoft visual studio\vc98\include\algorithm(316) : error C2664: '()' : cannot convert parameter 1 from 'struct astruct' to 'const class std::list<struct astruct,class std::allocator<struct astruct> >::iterator &'
Reason: cannot convert from 'struct astruct' to 'const class std::list<struct astruct,class std::allocator<struct astruct> >::iterator'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\program files\microsoft visual studio\vc98\include\algorithm(304) : see reference to function template instantiation 'class std::list<struct astruct,class std::allocator<struct astruct> >::iterator __cdecl std::remove_copy_if(class std::l
ist<struct astruct,class std::allocator<struct astruct> >::iterator,class std::list<struct astruct,class std::allocator<struct astruct> >::iterator,class std::list<struct astruct,class std::allocator<struct astruct> >::iterator,class std::binder2nd<
class in_adver<class std::list<struct astruct,class std::allocator<struct astruct> >::iterator> >)' being compiled
c:\program files\microsoft visual studio\vc98\include\algorithm(316) : error C2064: term does not evaluate to a function
c:\program files\microsoft visual studio\vc98\include\algorithm(304) : see reference to function template instantiation 'class std::list<struct astruct,class std::allocator<struct astruct> >::iterator __cdecl std::remove_copy_if(class std::l
ist<struct astruct,class std::allocator<struct astruct> >::iterator,class std::list<struct astruct,class std::allocator<struct astruct> >::iterator,class std::list<struct astruct,class std::allocator<struct astruct> >::iterator,class std::binder2nd<
class in_adver<class std::list<struct astruct,class std::allocator<struct astruct> >::iterator> >)' being compiled
Error executing cl.exe.taa.exe - 4 error(s), 0 warning(s)
// compile with: /EHsc
#include <vector>
#include <functional>
#include <algorithm>
#include <iostream>using namespace std;// Creation of a user-defined function object
// that inherits from the unary_function base class
class greaterthan15: unary_function<int, bool>
{
public:
result_type operator( ) ( argument_type i )
{
return ( result_type ) ( i > 15 );
}
};int main( )
{
vector <int> v1;
vector <int>::iterator Iter;
int i;
for ( i = 0 ; i <= 5 ; i++ )
{
v1.push_back( 5 * i );
} cout << "The vector v1 = ( " ;
for ( Iter = v1.begin( ) ; Iter != v1.end( ) ; Iter++ )
cout << *Iter << " ";
cout << ")" << endl; // Count the number of integers > 10 in the vector
int result1a;
result1a = count_if( v1.begin( ), v1.end( ), bind2nd( greater<int>( ), 10 ) );
cout << "The number of elements in v1 greater than 10 is: "
<< result1a << "." << endl; // Compare counting the number of integers > 15 in the vector
// with a user-defined function object
int result1b;
result1b = count_if( v1.begin( ), v1.end( ), greaterthan15( ) );
cout << "The number of elements in v1 greater than 15 is: "
<< result1b << "." << endl; // Count the number of integers < 10 in the vector
int result2;
result2 = count_if( v1.begin( ), v1.end( ), bind1st( greater<int>( ), 10 ) );
cout << "The number of elements in v1 less than 10 is: "
<< result2 << "." << endl;
}