定义boost(dynamic_bitset)的(一/二)维数组(defining (one/two) dimensional array of boost::dynamic_bitset)

有没有办法在boost中有一个dynamic_bitset数组? 我希望能够同时拥有1-D和2-D阵列 - 谢谢!

Is there a way to have an array of dynamic_bitset in boost? I would like to be able to have both 1-D and 2-D arrays -- Thanks!

最满意答案

如果你可以使用一个可能更好的std :: vector而且你可以同时使用它们,这里有一个例子( 见实时 ):

#include <iostream> #include <vector> #include <boost/dynamic_bitset.hpp> int main() { std::vector<boost::dynamic_bitset<> > v(10, boost::dynamic_bitset<>(3)); std::cout << v[0] << std::endl ; v[0][2] = 1 ; std::cout << v[0] << std::endl ; std::vector< std::vector<boost::dynamic_bitset<> > > vv(3, std::vector<boost::dynamic_bitset<> >( 3, boost::dynamic_bitset<>(3)) ); std::cout << vv[0][0] << std::endl ; vv[0][0][1] = 1 ; std::cout << vv[0][0] << std::endl ; }

这个先前的线程也是一个很好的读取, 在C ++中创建boost dynamic_bitset的向量 。

If you can use a std::vector that would probably be better and yes you can do both, here is an example (see it live):

#include <iostream> #include <vector> #include <boost/dynamic_bitset.hpp> int main() { std::vector<boost::dynamic_bitset<> > v(10, boost::dynamic_bitset<>(3)); std::cout << v[0] << std::endl ; v[0][2] = 1 ; std::cout << v[0] << std::endl ; std::vector< std::vector<boost::dynamic_bitset<> > > vv(3, std::vector<boost::dynamic_bitset<> >( 3, boost::dynamic_bitset<>(3)) ); std::cout << vv[0][0] << std::endl ; vv[0][0][1] = 1 ; std::cout << vv[0][0] << std::endl ; }

This previous thread is a good read too, Creating vector of boost dynamic_bitset in C++.

更多推荐