0

I have a set of bitsets pointers in an unordered_map

static unordered_map< size_t, bitset<BITSIZE>* > systemBits;

And my function

template<typename system>
     static bitset<BITSIZE> & getBitFor() {

    size_t hash = typeid(system).hash_code();

    bitset<BITSIZE> * bit = systemBits[hash];

    if(bit == NULL) {
        bit = new bitset<BITSIZE>(0);
        (*bit) << POS++; // tried *bit << POS++ as well;
        systemBits[hash] = bit;
    }

    return *bit;
}

Whereas POS is an int set to 1 at first.

All that I'm trying to do is shift the bitset with the amounts of position per new bitset.

 (*bit) << POS++;

However this doesn't seem to work. When I cout the returned bitset all its bits are set to 0. If I do to the following:

bit->flip();

or (*bit).flip();

The bitset returned does flip all the 0 to 1.

What gives? Why does the shift operator have no effect at all?

Sidar
  • 504
  • 1
  • 9
  • 28

1 Answers1

0

Because you're not assigning the result to anything . You'd have the same problem if you were trying to shift an int.

Also, you've initialized your bitset to zero, and zero shifted by any amount is always zero.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680