Search code examples
c++boostboost-dynamic-bitset

defining (one/two) dimensional array of boost::dynamic_bitset


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!


Solution

  • 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++.