D
Daniel Etzold
Hi,
I have something similar to this:
template< typename X, typename Y, typename T = std::map< X, Y > >
class A {
T _t;
};
T may be a sequence of pairs or an associative container, e.g.
T = std::map< X, Y > | std::list< std:air< X, Y > > | ...
Now I want to implement the operator[] which returns Y& for a
given X. For associative containers it should use
_t.find( x ).second, for sequences it should use something
similar to this
for( T::it = _t.begin(); it != _t.end(); ++it )
if( it->first == x ) return it->second;
If the sequence would be a random access iterator I could use
iterator tags to call an appropriate overloaded method. But how
can I differ lists of pairs from maps or sequences of pairs from
associative containers in general?
Regards,
Daniel
I have something similar to this:
template< typename X, typename Y, typename T = std::map< X, Y > >
class A {
T _t;
};
T may be a sequence of pairs or an associative container, e.g.
T = std::map< X, Y > | std::list< std:air< X, Y > > | ...
Now I want to implement the operator[] which returns Y& for a
given X. For associative containers it should use
_t.find( x ).second, for sequences it should use something
similar to this
for( T::it = _t.begin(); it != _t.end(); ++it )
if( it->first == x ) return it->second;
If the sequence would be a random access iterator I could use
iterator tags to call an appropriate overloaded method. But how
can I differ lists of pairs from maps or sequences of pairs from
associative containers in general?
Regards,
Daniel