r...@zedat.fu-berlin.de (Stefan Ram) wrote in news:quiz-20150907203920
@
ram.dialup.fu-berlin.de:
> The following code is legal, but it still has an unnecessary
> run-time inefficiency in it, that can be cured by a (small)
> change in the source code:
>
> /* assume necessary #includes */
>
>::std::unordered_map< ::std::string, int >map;
> /* here some values might be put into the map */
>
> for( const ::std::pair< ::std::string, int > & pair : map )
> /* assume a statement here that might use the pair */
The correct way is to use auto and let it figure out the needed type:
for( const auto& pair : map )
According to the docs the type would be std::pair<const std::string,int>,
but why should I waste my time on it and hope to get it right every time?
This example is just an example of fragile code.
Cheers
Paavo