Boost logo

Boost :

Subject: Re: [boost] [ boost ] [ Trie ]
From: Edward Diener (eldiener_at_[hidden])
Date: 2015-02-23 09:35:14


On 2/23/2015 8:55 AM, Cosmin Boaca wrote:
> Hello,
>
> I have encountered some problems when I have tried to remove the 2 template
> parameters. I have tried to do it this way :
>
> in trie_iterator class i have modified the following typedefs
>
> typedef trie_iterator<Key, Value> iterator
> typedef trie_iterator<Key, Value> iter_type;
> tpyedef trie_iterator<Key, const Value> const_iterator;
> typedef std::pair<std::vector<key_type>, Value&> reference;
> typedef std::pair<std::vector<key_type>, Value&>* pointer;
>
> And in trie class
> typedef detail::trie_iterator<Key, Value> iterator
>
> I thought this was the only thing I need to modify in order to solve the
> task but it doesn't work. Actually, the following code doesn't work and I
> can't figure out why :
>
> boost::tries::trie<char, int> t;
> boost::tries::trie<char, int>::const_iterator ci = t.end();
>
> It raises compile time error that says it cannot convert from iterator to
> const_iterator. Basically it seems that it's called the end method that
> returns iterator instead of the const one and I can't figure out why.

Overloaded functionality in C++ is based on the types of the parameters
being used in the call and not the type of the return value. if you have:

boost::tries::trie<char, int> const t;
boost::tries::trie<char, int>::const_iterator ci = t.end();

I will bet it works. Also the equivalent

boost::tries::trie<char, int> t;
boost::tries::trie<char, int>::const_iterator ci =
(const_cast<boost::tries::trie<char, int> const>(t)).end();

should also work.

> If i
> change from end to cend then it works.


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