How-to's</> <!-- ||||||||||||||||||||||||||||| subsection --> <section id="howtos.search"> <title>How to find something in a sequence?</> <para> If you just want to make an enquiry if a sequence contains a type with certain properties, you can do it like that: </> <programlisting> <![CDATA[ typedef mpl::list5<> types; typedef mpl::contains<types,int>::type res; // res::value == true ]]> </> <para> A predicate version of <literal>contains</> algorithm is spelled <literal>any</>: </> <programlisting> <![CDATA[ // find if any type in 'types' is derived from 'my' typedef mpl::any<types, mpl::is_convertible<_1,my> >::type res; ]]> </> <para> Now, if you really want to find type in a sequence - that is, to obtain an iterator on its position, when the should-be-known-from-STL <literal>find</> and <literal>find_if</> algorithms are most probably exactly what you need: </> <programlisting> <![CDATA[ // find if any type in 'types' is derived from 'my' typedef mpl::find<types, int >::type iterator; typedef mpl::find_if<types, mpl::is_convertible<_1,my> >::type iterator; ]]> </> <para> Unless, of course, the sequence is sorted. If it is, then the other known names come into the play - <literal>lower_bound</>, <literal>upper_bound</>, or <literal>binary_search</>: </> <programlisting> <![CDATA[ // find if any type in 'types' is derived from 'my' typedef mpl::lower_bound<types, mpl::int_c<5>, mpl::less<_1,_2> >::type iterator; typedef mpl::upper_bound<types, mpl::int_c<5>, mpl::less<_1,_2> >::type iterator; typedef mpl::binary_search<types, mpl::int_c<5>, mpl::less<_1,_2> >::type iterator; ]]> </> </section> </section>