stl questions: how can I compare 2 stl list?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

stl questions: how can I compare 2 stl list?

yinglcs2@yahoo.com
is there a better way to compare 2 stl list? I write a
function like
this below, but I wonder if there is a better way to
achieve that with boost(e.g.
less code)?

bool isSame(const list<int>& srcList,  const
list<int>& destList ) {
        if (srcList.size() != destList.size()) {
                return false;
        }

        int size = srcList.size();
        for (int i = 0; i < size; i++) {
                if (srcList[i] != destList[i]) {
                        return false;
                }
        }

        return true;

}

Thank you.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: stl questions: how can I compare 2 stl list?

Olaf van der Spek-2
On 4/16/06, [hidden email] <[hidden email]> wrote:
> is there a better way to compare 2 stl list? I write a

Yes.
What about just srcList == dstList?

BTW, does your function actually compile?
I thought std::list doesn't provide operator[]?

> function like
> this below, but I wonder if there is a better way to
> achieve that with boost(e.g.
> less code)?
>
> bool isSame(const list<int>& srcList,  const
> list<int>& destList ) {
>        if (srcList.size() != destList.size()) {
>                return false;
>        }
>
>        int size = srcList.size();
>        for (int i = 0; i < size; i++) {
>                if (srcList[i] != destList[i]) {
>                        return false;
>                }
>        }
>
>        return true;
>
> }
>
> Thank you.
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: stl questions: how can I compare 2 stl list?

cablepuff
In reply to this post by yinglcs2@yahoo.com
Yes... there is a way... operator== is already implemented into stl. ....std::list has a way to compare to two list... base on same size..same elments.... (pg 168 of standard c++ library by Nicolai M. Josuttiss).

On 4/16/06, [hidden email] <[hidden email]> wrote:
is there a better way to compare 2 stl list? I write a
function like
this below, but I wonder if there is a better way to
achieve that with boost(e.g.
less code)?

bool isSame(const list<int>& srcList,  const
list<int>& destList ) {
        if (srcList.size() != destList.size()) {
                return false;
        }

        int size = srcList.size();
        for (int i = 0; i < size; i++) {
                if (srcList[i] != destList[i]) {
                        return false;
                }
        }

        return true;

}

Thank you.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users