[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: kdebase/kioslave/smtp
From:       Frerich Raabe <frerich.raabe () gmx ! de>
Date:       2003-04-25 1:52:59
[Download RAW message or body]

On Thursday 24 April 2003 22:18, Dirk Mueller wrote:
> --- kdebase/kioslave/smtp/capabilities.cc  #1.6:1.7
> @@ -133,5 +133,7 @@ namespace KioSMTP {
>      }
>      result.sort();
> -    result.erase( std::unique( result.begin(), result.end() ),
> result.end() ); +    QStringList::iterator it = result.begin();
> +    for (QStringList::iterator ot = it++; it != result.end(); ot = it++)
> +        if (*ot == *it) result.remove(ot);
>      return result;
>    }

Instead of sorting the whole list and then iterating once more over it, you 
might want to use this (but it requires an intermediate list, which should 
not be a problem though), which I have been using in a few projects now:

template <class Container>
Container qUnique( const Container &container )
{
    Container c;
    typename Container::ConstIterator it = container.begin();
    typename Container::ConstIterator end = container.end();
    for ( ; it != end; ++it )
        if ( c.find( *it ) == c.end() )
            c << *it;
    return c;
}

I don't know whether it's significantely better than sorting and then removing 
adjacent duplicates, but it sure is nicer for your eyes.

- Frerich

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic