|
Boost Users : |
Subject: Re: [Boost-users] [forEach] Working with custom operator []
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2011-05-09 08:26:10
Nathan Ridge wrote:
>> From: avishay.ben.shabtai_at_[hidden]
>>
>> Hi
>> i have a container class that defines 2 overloaded [] operators:
>> T& operator[](const chat *);
>> T& operator[](unsigned int);
>>
>> when i am using BOOST_FOREACH(T val,container)
>>
>> i get compilation errors but working directly with iterators is working
>> ok, any idea?
>
>
> BOOST_FOREACH uses the begin() and end() member functions to get
> iterators pointing to the beginning and end of the range,
> then advances the begin iterator using ++ until it reaches the end.
> Along the way it dereferences the iterator to get the the element
> that is assigned to "val". It has nothing to do with operator[].
>
> If you want your container to work with BOOST_FOREACH, you need
> to make sure it has begin() and end() member functions which
> return iterators with the appropriate capabilities (increment,
> dereference, equality comparison).
Or specialized boost::begin/boost::end perhaps?
Jeff
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net