On 12 November 2011 08:56, Theodore Papadopoulo wrote: >> >> Yes, the reason I'm delighted with auto is that there are cases >> where I do not want to know the type (or I want to write generic >> code that will work with different kinds of containers). For >> >> std::multimap<Foo,Bar> amap; >> >> when I write >> >> auto ipair = amap.equal_range(key); for (auto iter = ipair.first; >> iter != ipair.second; ++iter) do_something_with(iter->first, >> iter->second); >> >> I explicitly do not want to know the details of the ridiculously >> hairy type of ipair. If you want to know, it is >> >> std::pair<std::multimap<Foo,Bar>::iterator,std::multimap<Foo,Bar>::iterator> >> >> and that's with the defaulted template parameters omitted.
Actually in our case (as you know) we have SCARY iterators, so multimap::iterator is a typedef, and the actual type is std::_Rb_tree_iterator<std::pair<const Foo, Bar>> which is even less useful to know! > Sorry to jump in.... > But it is when you write > auto ipair = amap.equal_range(key); > that you may want to know that this type is a pair and that you can > write ipair.first and ipair.second. > > Of course equal_range is not the best example, but I can very well > imagine that with the generalization of auto use and with third party > libraries it might become very difficult/boring to track the actual > return type of a function (imagine a serie of functions all using auto > as return type).... I actually think equal_range is a better example than most of how the feature *could* be useful, because std::pair<Iter,Iter> supports so few operations: you can write ipair.first and ipair.second, and not much else apart from user-defined functions written to work with that type. In many case, e.g. if you have a single iterator, the number of operations you could do with it is enormous (all the member operators such as *, ++, --, -> etc. as well as passing it to an uncountable number of function templates) But if the feature is useful the information can be extracted from DWARF already, and no editors seem to be doing so, so I'm sceptical they would do it for a new format. A friend pointed me to http://wiki.dwarfstd.org/index.php?title=Libdwarf_And_Dwarfdump which would make it even easier.