Vector<bool> object does not support item assignment

I cannot seem to be able to assign items in vector objects in PyROOT. The following simple example shows this:

from ROOT import *

The last command returns error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'vector<bool,allocator<bool> >' object does not support item assignment

I found a thread from 2010 ( reporting the exact same error, with the same problem occurring in CINT. However that was fixed and I don’t see a problem with CINT.

I have this problem with ROOT/Python versions 5.34.08/2.7.5 (from Gentoo Linux) and 5.30.02/2.6.5 (from ATLAS software thing).

I think it’s related to the fact that vector is a “special” kind of std::vector which has different interfaces. It packs the boolean values for smaller storage, but when you access elements, it doesn’t happen directly. I don’t know much more than this, but here is some reading:

Apparently the solution is “don’t use vector”. For most applications, using a vector shouldn’t be wasting so much memory that it’s a problem.



yes, what Jean-François said …

To get around that, I’ve added a setitem for std::vector in the pythonizations, so it now works, but it’s not particularly efficient.