[C++-sig] export std::set
Roman Yakovenko
roman.yakovenko at gmail.com
Thu May 4 18:53:18 CEST 2006
On 5/4/06, François Duranleau <duranlef at iro.umontreal.ca> wrote:
> On Wed, 3 May 2006, Andreas Beyer wrote:
>
> > Here is the complete code:
>
> If I may make a few suggestions:
>
> > // element access
> > bool contains(const KeyType key)
> > { return count(key)>0; }
> > // we must define add() for it gets explicit argument types
> > void add(const KeyType key)
> > { insert(key); }
> > void remove(const KeyType key)
> > // improve error handling here
> > { if (!contains(key)) throw "element not in set"; erase(key); }
>
> Why not put the key parameter as a const reference instead of copying?
>
> Also, for remove, it would probably be best to write it like this:
>
> void remove( const KeyType& key )
> {
> typename source_type::iterator i = this->find( key ) ;
> if ( i == this->end() )
> {
> throw "element not in set" ;
> }
> this->erase( i ) ;
> }
>
> This way you look up for the key only once, not twice.
>
> Also, everywhere in py_set<>, you need to either make all calls to some
> base class's (with template arguments dependent on the current class)
> method qualified (e.g. with this-> as above) or "import" them with 'using'
> declarations, or else this code is not standard and won't compile on some
> compilers (the one I use, g++-4.0, for instance).
Thanks, I will take this into account
> --
> François Duranleau
> LIGUM, Université de Montréal
>
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list