[xsde-users] find() in sequences

Boris Kolpackov boris at codesynthesis.com
Wed Oct 7 04:47:43 EDT 2009


Hi Duncan,

Duncan.Perrett at elekta.com <Duncan.Perrett at elekta.com> writes:

> However, I have since gone on to just do this ...
> 
>         for (NodeType::TxMessage_const_iterator j = 
> i->TxMessage().begin(); j != i->TxMessage().end(); ++j) // for each 
> TxMessage of the Node
>         {
>                 if (j->Name() == "ADC1_data_dia")
>                 {
>                         msgTxMsgNum = j;
>                         msgNodeNum = i;
>                         cout << "match for msg ADC1_data_carr" <<
>                         " in Node " << i->Name() << " msg no. " << 
> numCANMsgs++ << endl;
>                 }
>  
>                 numCANMsgs++;
>         }
> 
> 
> Would installing the iterator support and using find_if() with a predicate 
> be worth doing?  Would it be faster/smaller etc?

It is not going to be faster since find_if() does essentially the same.
I also don't think it will be smaller in terms of object code size. It
definitely looks more elegant if you can use the bind technique but with
a custom predicate it becomes much less appealing unless you have a lot
of places where you call find_if() with the same predicate. So I would 
say use the loop approach if you only need to do it once.

Boris



More information about the xsde-users mailing list