?? howtos.sgml
字號:
<!-- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| section -->
<section id="howtos">
<title>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>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -