开发者

bitset to dynamic bitset

开发者 https://www.devze.com 2022-12-28 07:47 出处:网络
I have a function where i use bitset.Now i 开发者_Python百科need to convert it to a dynamic bitset..

I have a function where i use bitset.Now i 开发者_Python百科need to convert it to a dynamic bitset.. but i don't know how. Can somebody help me ?

set<string> generateCandidates(set<string> ck,unsigned int k){
 set<string> nk ;
 for (set<string>::const_iterator p = ck.begin( );p != ck.end( ); ++p){
     for (set<string>::const_iterator q = ck.begin( );q != ck.end( ); ++q){
         bitset<4> bs1(*p);
         bitset<4> bs2(*q);
         bs1|= bs2 ;
         if(bs1.count() == k){
             nk.insert(bs1.to_string<char,char_traits<char>,allocator<char> >());
         }
     }
 }
 return nk;
}


The difference isn't that big:

boost::dynamic_bitset<> bs1(*p);
boost::dynamic_bitset<> bs2(*q);
bs1 |= bs2;
if(bs1.count() == k){
    std::string str;
    boost::to_string(bs1, str);
    nk.insert(str);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消