﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Robertxiao-文章分类-C++ Tech</title><link>http://www.cppblog.com/Robertxiao/category/17418.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 29 Jul 2011 10:15:08 GMT</lastBuildDate><pubDate>Fri, 29 Jul 2011 10:15:08 GMT</pubDate><ttl>60</ttl><item><title>c++0x 系列&lt;result_of&gt;</title><link>http://www.cppblog.com/Robertxiao/articles/152019.html</link><dc:creator>Robertxiao</dc:creator><author>Robertxiao</author><pubDate>Fri, 29 Jul 2011 02:24:00 GMT</pubDate><guid>http://www.cppblog.com/Robertxiao/articles/152019.html</guid><wfw:comment>http://www.cppblog.com/Robertxiao/comments/152019.html</wfw:comment><comments>http://www.cppblog.com/Robertxiao/articles/152019.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/Robertxiao/comments/commentRss/152019.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/Robertxiao/services/trackbacks/152019.html</trackback:ping><description><![CDATA[<div>result_of 用于推导可调用对象的返回类型。<br />大致定义：<br />template<span style="color: blue">&lt;</span><span style="color: maroon">class</span> Ty<span style="color: blue">&gt;</span><br />&nbsp;&nbsp;&nbsp; struct result_of {<br />&nbsp;&nbsp;&nbsp; typedef T0 type;<br />&nbsp;&nbsp;&nbsp; };<br />Ty: 可调用类型，<br />
<p><Sentence id=tgt4 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="37fbc0073d68dc59c91d8d43cce986d6">The template class defines its member <span class="code" xmlns="http://www.w3.org/1999/xhtml">type</span> as a synonym for the return type of a function call described by its template argument <span class="code" xmlns="http://www.w3.org/1999/xhtml">Ty</span>. </sentence><Sentence id=tgt5 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="6f66a3bdb155d2ed9c20b9aa1d6a5956">The template argument must be of the form <span class="code" xmlns="http://www.w3.org/1999/xhtml">Fty(T1, T2, ..., TN)</span>, where <span class="code" xmlns="http://www.w3.org/1999/xhtml">Fty</span> is a callable type. </sentence><Sentence id=tgt6 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="aab822cdf347ee77b7cd313cacdb3878">The template determines the return type according to the first of the following rules that applies:</p>
<ul><li>
<p><Sentence id=tgt7 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="431cb32562039bfd9017c5aa7dea77c9">if <span class="code" xmlns="http://www.w3.org/1999/xhtml">Fty</span> is a pointer to function type <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R(*)(U1, U2, ..., UN)</span> the return type is <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R</span>; </sentence></p></li><li>
<p></ class=tgtSentence msdn2.microsoft.com xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="431cb32562039bfd9017c5aa7dea77c9" mtps:Sentence>如果Fty是个<span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R(*)(U1, U2, ..., UN)</span> 函数指针，那么返回类型是R</ msdn2.microsoft.com mtps:Sentence></p></li><li>
<p><Sentence id=tgt8 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="92961a7fa98917045e0e4cf8af28a86b">if <span class="code" xmlns="http://www.w3.org/1999/xhtml">Fty</span> is a reference to function type <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R(&amp;)(U1, U2, ..., UN)</span> the return type is <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R</span>; </sentence></p></li><li>
<p></ class=tgtSentence msdn2.microsoft.com xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="92961a7fa98917045e0e4cf8af28a86b" mtps:Sentence>如果Fty是个<span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R(&amp;)(U1, U2, ..., UN)</span> 函数指针，那么返回类型是R</ msdn2.microsoft.com mtps:Sentence></p></li><li>
<p><Sentence id=tgt9 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="fc99fda7f5220af73d97358cc2424041">if <span class="code" xmlns="http://www.w3.org/1999/xhtml">Fty</span> is a pointer to member function type <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R(U1::*)(U2, ..., UN)</span> the return type is <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R</span>; </sentence></p></li><li></ class=tgtSentence msdn2.microsoft.com xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="fc99fda7f5220af73d97358cc2424041" mtps:Sentence>
<p></ class=tgtSentence msdn2.microsoft.com xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="92961a7fa98917045e0e4cf8af28a86b" mtps:Sentence>如果Fty是个<span class="parameter" xmlns="http://www.w3.org/1999/xhtml"><span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R(U1::*)(U2, ..., UN)成员</span></span>函数指针，那么返回类型是R</ msdn2.microsoft.com mtps:Sentence></p></li><li>
<p><Sentence id=tgt10 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="bc39f2474dd6f5737738d479e04f872d">if <span class="code" xmlns="http://www.w3.org/1999/xhtml">Fty</span> is a pointer to data member type <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R U1::*</span> the return type is <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R</span>; </sentence></p></li><li>
<p></ class=tgtSentence msdn2.microsoft.com xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="bc39f2474dd6f5737738d479e04f872d" mtps:Sentence>如果Fty是个<span class="parameter" xmlns="http://www.w3.org/1999/xhtml"><span class="parameter" xmlns="http://www.w3.org/1999/xhtml"><span class="parameter" xmlns="http://www.w3.org/1999/xhtml">R U1::*</span> 成员变量</span></span>指针，那么返回类型是R</ msdn2.microsoft.com mtps:Sentence></ msdn2.microsoft.com mtps:Sentence></p></li><li>
<p><Sentence id=tgt11 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="e0bc005a6984bd4fa230f4759ae660ce">if <span class="code" xmlns="http://www.w3.org/1999/xhtml">Fty</span> is a class with a member typedef <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">result_type</span> the return type is <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">Fty::result_type</span>; </sentence></p></li><li>
<p></ class=tgtSentence msdn2.microsoft.com xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="e0bc005a6984bd4fa230f4759ae660ce" mtps:Sentence>如果Fty是一个类并且其中定义了<span class="parameter" xmlns="http://www.w3.org/1999/xhtml">result_type</span> ，那么返回类型是<span class="parameter" xmlns="http://www.w3.org/1999/xhtml">Fty::result_type</span></ msdn2.microsoft.com mtps:Sentence></p></li><li>
<p><Sentence id=tgt12 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="797b1888b595eb0ce0e8fd824b2cc2e6">if <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">N</span> is 0 (that is, <span class="code" xmlns="http://www.w3.org/1999/xhtml">Ty</span> is of the form <span class="code" xmlns="http://www.w3.org/1999/xhtml">Fty()</span>) the return type is <span class="parameter" xmlns="http://www.w3.org/1999/xhtml">void</span>; </sentence></p></li><li>
<p></ class=tgtSentence msdn2.microsoft.com xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="797b1888b595eb0ce0e8fd824b2cc2e6" mtps:Sentence>如果Fty函数不带有任何的参数，那么返回类型是void</ msdn2.microsoft.com mtps:Sentence></p></li><li>
<p><Sentence id=tgt13 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="197268c8ff6cd2fad5263486a6e0151b"><span style="background-color: #ffffff; color: #000000">if </span><span style="background-color: #ffffff; color: #000000" class="code" xmlns="http://www.w3.org/1999/xhtml">Fty</span><span style="background-color: #ffffff; color: #000000"> is a class with a member template named </span><span style="background-color: #ffffff; color: #000000" class="parameter" xmlns="http://www.w3.org/1999/xhtml">result</span><span style="background-color: #ffffff; color: #000000"> the return type is </span><span style="background-color: #ffffff; color: #000000" class="parameter" xmlns="http://www.w3.org/1999/xhtml">Fty::result&lt;T1, T2, ..., TN&gt;::type</span><span style="background-color: #ffffff; color: #000000">; </span></sentence></p></li><li>
<p></ class=tgtSentence msdn2.microsoft.com xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="197268c8ff6cd2fad5263486a6e0151b" mtps:Sentence>如果Fty是个类并且有个成员模板是result,那么返回类型是Fty::<font color="#ffffff"><font color="#ffffff"><span style="color: #000000">result&lt;T1, T2, ..., TN&gt;::type</span></font></font></p></li><li>
<p><Sentence id=tgt14 class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="6e8d1a3ffb35d4959fe43654ecf52f10">in all other cases it is an error.</sentence></p></li><li>
<p><//msdn2.microsoft.com/mtps:Sentence class=tgtSentence xmlns="http://msdn2.microsoft.com/mtps" runat="server" sentenceid="6e8d1a3ffb35d4959fe43654ecf52f10">其它情况就会出错<///msdn2.microsoft.com/mtps:Sentence></p></li></ul>
<p></sentence></p></div><img src ="http://www.cppblog.com/Robertxiao/aggbug/152019.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/Robertxiao/" target="_blank">Robertxiao</a> 2011-07-29 10:24 <a href="http://www.cppblog.com/Robertxiao/articles/152019.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>