Re: std::vector<Bool_t> in PyROOT

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Wed, 30 Jun 2010 14:53:54 +0200


Hi Akira,

it should work now in the trunk. Thanks for your report!

Cheers, Axel.

OKUMURA, Akira wrote on 06/29/2010 05:21 PM:
> Hello Wim and Axel,
>
> Kevin kindly told me that vector<bool> is a special template in the C++ standard and thus it is different from other vectors such as vector<int>... I did not know this in fact.
>

>> I don't have a solution for you, but perhaps it will help out. 
>> std::vector<bool> is NOT a directly indexable container ... in fact, the
>> standard specifies std::vector<bool> as a specialization with different
>> semantics that the base std::vector<T> template.  It can't be directly
>> indexed or iterated; it requires proxy objects.
>>
>> See, for instance, http://www.gotw.ca/gotw/050.htm and
>> http://www.gotw.ca/publications/N1211.pdf

>
>
> However, at least GCC4 on Mac can handle vector<bool> as a user (who is lacking this knowledge) expected. This test code compiles and runs as expected. So I was wondering if CINT also could handle vector<bool> as GCC does, although I can avoid this "feature" using vector<int> or similar.
>
> int main()
> {
> std::vector<bool> v(100);
>
> for(int i = 0; i < 100; i++){
> v[i] = i%2 == 0 ? true : false;
> std::cout << v[i] << std::endl;
> } // i
>
> return 0;
> }
>
>
> Regards,
>
> --
> OKUMURA, Akira oxon@{astro.isas.jaxa.jp,stanford.edu}
> Institute of Space and Astronautical Science (ISAS/JAXA)
> Now at KIPAC/SLAC/Stanford
> Varian Physics #306
> 382 Via Pueblo Mall, MC 406 Stanford, CA94305
> TEL 650-736-0971/FAX 650-724-5065
> Skype : okumura.akira
>
> On 2010/06/28, at 21:41, WLavrijsen_at_lbl.gov wrote:
>
>> Tim,
>>
>>> It doesn't, well __getitem__() is missing:
>>
>> hmm, something with the dictionary than. I'm afraid we'll have to wait
>> until Axel wakes up, as the problem is there in CINT also:
>>
>> [pc3-wlav] ~/rootdev/root % root -b -l
>> root [0] #include <vector> root [1] std::vector<bool> v; root [2] v.push_back(false); root [3] v.push_back(true); root [4] std::cout << v.size() << std::endl;
>> 2
>> root [5] std::cout << v[0] << std::endl; Error: Can't call vector<bool,allocator<bool> >::operator[]((int)0) in current scope (tmpfile):1:
>> Possible candidates are...
>> (in vector<bool,allocator<bool> >)
>> *** Interpreter error recovered ***
>> root [6]
>>
>>> How do you get a dictionary to be loaded and why do the others get
>>> loaded automagically?
>>
>> Long story. In short: some std::vector instantiations are "shipped" with
>> CINT, others are auto-generated, yet others are found through the ROOTMAP
>> or LDPATH search paths if e.g. setup within an experiment runtime.
>>
>> Best regards,
>>           Wim
>> -- 
>> WLavrijsen_at_lbl.gov    --    +1 (510) 486 6411    --    www.lavrijsen.net

>
>
Received on Wed Jun 30 2010 - 14:54:00 CEST

This archive was generated by hypermail 2.2.0 : Wed Jun 30 2010 - 17:50:01 CEST