Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a vector of bitsets?

Tags:

c++

vector

bitset

I am trying to create a vector of bitsets in C++. For this, I have tried the attempt as shown in the code snippet below:

vector<bitset<8>> bvc;
    while (true) {
        bitset<8> bstemp( (long) xtemp );
        if (bstemp.count == y1) {
            bvc.push_back(bstemp);
        }
        if ( xtemp == 0) {
            break;
        }
        xtemp = (xtemp-1) & ntemp;
    }

When I try to compile the program, I get the error that reads that bvc was not declared in the scope. It further tells that the template argument 1 and 2 are invalid. (the 1st line). Also, in the line containing bvc.push_back(bstemp), I am getting an error that reads invalid use of member function.

like image 732
uyetch Avatar asked Jan 21 '12 10:01

uyetch


2 Answers

I have a feeling that you're using pre C++11.

Change this:

vector<bitset<8>> bvc;

to this:

vector<bitset<8> > bvc;

Otherwise, the >> is parsed as the right-shift operator. This was "fixed" in C++11.

like image 186
Mysticial Avatar answered Sep 20 '22 16:09

Mysticial


Change vector<bitset<8>> bvc to vector<bitset<8> > bvc. Note the space. >> is an operator.

Yes, pretty nasty syntax issue.

like image 22
littleadv Avatar answered Sep 20 '22 16:09

littleadv