why not std::not1 ?

D

dragon9

//main.cpp
...
class IsFileAttributes{
public:
IsFileAttributes(const DWORD aim):aim_(aim){}
bool operator() (const fs::path arg){
using namespace wukexin;
string fname=arg.native_file_string();
DWORD attrib=GetFileAttributes(fname.c_str() );
std::cout<<fname<<"\n";
//std::cout<<"file="<<attrib<<"\tfiltrate="<<aim_<<"\n";
//std::cout<<"file="<<fileAttribToStr(attrib)<<"\tfiltrate="<<fileAttribToStr(aim_)<<"\n";
std::cout.setf(ios::boolalpha);
std::cout<<static_cast<bool>(aim_ & attrib)<<"\t"<<fname<<"\n";
return ( aim_ & attrib );
}
//private:
DWORD aim_;
};
...
if(vm.count("attribute") ){
const vector said:
DWORD attrib(0);
for(vector<string>::const_iterator
itr=attribs.begin();itr!=attribs.end();++itr){
attrib |= wukexin::stringToAttrib(*itr);
}
filtrate(fileList,IsFileAttributes(attrib) );
}
...
//help.h
//
template<class C, class P> void filtrate(C& c, P pred)
{
c.erase(std::remove_if(c.begin(), c.end(), std::not1(pred) ), c.end());
}
//vc 2003 error message
main.cpp
d:\backup\program\VC2003\include\functional(201) : error C2039:
¡°argument_type¡± : ²»ÊÇ¡°IsFileAttributes¡±µÄ³ÉÔ±
main.cpp(31) : ²Î¼û¡°IsFileAttributes¡±µÄÉùÃ÷
d:\backup\program\boost_1_34_1\../wukexin\help\help.h(18) : ²Î¼û¶ÔÕýÔÚ±àÒëµÄÀàÄ£°åʵÀý»¯¡°std::unary_negate<_Fn1>¡±µÄÒýÓÃ
with
[
_Fn1=IsFileAttributes
]
main.cpp(171) : ²Î¼û¶ÔÕýÔÚ±àÒëµÄº¯ÊýÄ£°åʵÀý»¯¡°void
filtrate<Container,IsFileAttributes>(C &,P)¡±µÄÒýÓÃ
with
[
C=Container,
P=IsFileAttributes
]
d:\backup\program\VC2003\include\functional(201) : error C2146: Óï·¨´íÎó :
ȱÉÙ¡°,¡±(ÔÚ±êʶ·û¡°argument_type¡±µÄÇ°Ãæ)
d:\backup\program\VC2003\include\functional(201) : error C2065:
¡°argument_type¡± : δÉùÃ÷µÄ±êʶ·û
d:\backup\program\VC2003\include\functional(201) : error C2976:
¡°std::unary_function¡± : Ä£°å²ÎÊýÌ«ÉÙ
d:\backup\program\VC2003\include\functional(20) : ²Î¼û¡°std::unary_function¡±µÄÉùÃ÷
d:\backup\program\VC2003\include\functional(209) : error C2039:
¡°argument_type¡± : ²»ÊÇ¡°IsFileAttributes¡±µÄ³ÉÔ±
main.cpp(31) : ²Î¼û¡°IsFileAttributes¡±µÄÉùÃ÷
d:\backup\program\boost_1_34_1\../wukexin\help\help.h(18) : error C2664:
¡°std::remove_if¡± : ²»Äܽ«²ÎÊý 3 ´Ó¡°std::unary_negate<_Fn1>¡±×ª»»Îª¡°std::unary_negate<_Fn1>¡±


with
[
_Fn1=IsFileAttributes
]
and
[
_Fn1=IsFileAttributes
]
ûÓпÉÓÃÓÚ class¡°std::unary_negate<_Fn1>¡±µÄ¸´Öƹ¹Ô캯Êý£¬»ò¹¹Ô캯ÊýÊÔͼִÐе½·Ç __gc ÒýÓõķǷ¨×ª»»
with
[
_Fn1=IsFileAttributes
]
 
T

Triple-DES

//main.cpp
..
class IsFileAttributes{
public:
IsFileAttributes(const DWORD aim):aim_(aim){}
bool operator() (const fs::path arg){
using namespace wukexin;
string fname=arg.native_file_string();
DWORD attrib=GetFileAttributes(fname.c_str() );
std::cout<<fname<<"\n";
//std::cout<<"file="<<attrib<<"\tfiltrate="<<aim_<<"\n";
//std::cout<<"file="<<fileAttribToStr(attrib)<<"\tfiltrate="<<fileAttribToS­tr(aim_)<<"\n";
std::cout.setf(ios::boolalpha);
std::cout<<static_cast<bool>(aim_ & attrib)<<"\t"<<fname<<"\n";
return ( aim_ & attrib );}

//private:
DWORD aim_;};

..
if(vm.count("attribute") ){
const vector<string>& attribs = vm["attribute"].as< vector<string>
 >();
DWORD attrib(0);
for(vector<string>::const_iterator
itr=attribs.begin();itr!=attribs.end();++itr){
attrib |= wukexin::stringToAttrib(*itr);}

filtrate(fileList,IsFileAttributes(attrib) );}

..
//help.h
//
template<class C, class P> void filtrate(C& c, P pred)
{
c.erase(std::remove_if(c.begin(), c.end(), std::not1(pred) ), c.end());}
It would be easier if you made a simpler example, but try to make your
predicate inherit from std::unary_function<bool, fs::path>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top