如何找到的boost ::来,dynamic_bitset&LT一个第一和最后一个出场;&GT; [英] How to find first and last appearance of one in boost::dynamic_bitset<>
本文介绍了如何找到的boost ::来,dynamic_bitset&LT一个第一和最后一个出场;&GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要的的boost ::来,dynamic_bitset&LT的1第一和最后一个出场的指标;> ,第一个是容易找到类似的 SIZE_TYPE find_first()const的。如何最终能找到,我需要遍历或创建以相反的顺序新的或有技巧,找到更简单的方法?
I need indexes of first and last appearance of 1 in boost::dynamic_bitset<>, first is easy to find like size_type find_first() const. How to find last, do I need to iterate or create new in reverse order or there is trick to find on easier way ?
推荐答案
我们可以使用一些伎俩像
We can use some trick like
#include <iostream>
#include <boost/dynamic_bitset.hpp>
int main()
{
typedef boost::dynamic_bitset<>::size_type size_type;
const size_type npos = boost::dynamic_bitset<>::npos;
boost::dynamic_bitset<> bitset(10, 50);
size_type first_idx = bitset.find_first();
size_type current_idx = first_idx;
if (first_idx != npos)
{
do {
current_idx = bitset.find_next(current_idx);
} while (bitset.find_next(current_idx) != boost::dynamic_bitset<>::npos);
std::cout << bitset << " first: " << first_idx << " last: " << current_idx << std::endl;
}
}
这篇关于如何找到的boost ::来,dynamic_bitset&LT一个第一和最后一个出场;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文