Subj : Ping? To : andrew clarke From : Bo Simonsen Date : Wed Apr 29 2009 21:17:43 ac> BS> for(typename std::set::iterator it = cont.begin(); ac> BS> it != cont.end(); ac> BS> ++it) { ac> BS> // do something with *it ac> BS> } ac> ac>How does "typename" work here? I'm not familiar with recent C++ ac>developments... My error.. There should not be any typename there.. Typename should only be used in relation to template arguments. typename C::iterator for a template argument C works. ac> BS> We can simply write: ac> ac> BS> for(auto it=cont.begin(); it != cont.end(); ++it) { ac> ac> BS> } ac> ac>Hmm. I don't really know how that works, but I think I prefer this: The compiler will deduce the type of 'it' from the return type of cont.begin() .. It's that simple.. :) ac> typedef std::set intset_t; ac> intset_t cont; ac> ac> cont.insert(5); ac> cont.insert(7); ac> ac> intset_t::iterator it = cont.begin(); ac> ac> while (it != cont.end()) ac> { ac> // do something with *it ac> ++it; ac> } Yes that's the generic way of doing it.. However we should use std::for_each if we should be 100% generic. But then we are missing the lambda functions where we can specify functions in one line.. :) ac>Having said that, my personal preference is a bit academic - as these ac>days I spend most of my programming time writing code in Python :-) Heh, the STL/C++ is my academic preference.. I'm working at the cphstl.dk.. ac> cont = set() ac> cont.add(5) ac> cont.add(7) ac> ac> for it in cont: ac> print it ac> Yep that's nice.. You would probably use "dict" instead? I wonder if "dict" is also implemented as a balanced binary search tree in python. In the STL you get O(lg n) guarantee for almost all your operations on set/map. It's really a nice thing with the complexity guarantees. Bo --- DayDream/Linux 2.15a * Origin: The Night Express, Korsoer, geekworld.no-ip.org (2:236/100) .