Boost logo

Boost :

From: Felipe Magno de Almeida (felipe.almeida_at_[hidden])
Date: 2005-03-17 17:37:54


sorry, it's just wrong.

Felipe Magno de Almeida wrote:
> Ive modified the ptr_map_adapter in the operator[]
> to be:
> const_reference operator[]( const key_type& key ) const
> {
> //return lookup( key );
> iterator i = find( key );
> if( i != end() )
> return *i;
> else {
> i = const_cast<ptr_map_adapter_base*>(this)
> ->insert(begin(), key,
> CloneAllocator::allocate_clone(value_type()));
> return *i;
> }
> }
> and the non-const just dont have the const_cast, but this way I think
> value_type is default-constructed and then copy-constructed isnt? well,
> this isnt very efficient, but to my needs it is already better.
>
> Thorsten Ottosen wrote:
>
>> Hi Felipe,
>>
>> "Felipe Magno de Almeida" <felipe.almeida_at_[hidden]> wrote in
>> message news:4239C1B1.3050507_at_ic.unicamp.br...
>> | Hi.
>> |
>> | I dont see why ptr_map throws in operator[], I think it should have the
>> | same behavior of std::map and return a default constructed object in
>> | case it doesnt find the key.
>> | Anyway, it is just a opinion
>>
>> Hm..yeah...I guess you can use
>>
>> map.at( "foo" );
>>
>> if you want the exception to be thrown. I think you're right
>> it should call insert a heap-allocated object.
>>
>> I will change this for the post-review. In the meantime, you can make
>> a new function in ptr_map_adapter using lookup()
>> as a template to get the behavior you need.
>> .
>> | Im using ptr_map in production code and
>>
>> I'm glad to hear that.
>>
>> -Thorsten
>>
>>
>> _______________________________________________
>> Unsubscribe & other changes:
>> http://lists.boost.org/mailman/listinfo.cgi/boost
>>
>

-- 
    Felipe Magno de Almeida
    UIN: 2113442
     email: felipe.almeida at ic unicamp br, felipe.m.almeida at gmail 
com, felipe at synergy com
I am a C, modern C++, MFC, ODBC, Windows Services, MAPI developer
from synergy, and Computer Science student from State
University of Campinas(UNICAMP).
To know more about:
Unicamp: http://www.ic.unicamp.br
Synergy: http://www.synergy.com.br
current work: http://www.mintercept.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk