{"id":2956,"date":"2020-12-21T12:24:45","date_gmt":"2020-12-21T04:24:45","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=2956"},"modified":"2020-12-21T14:14:12","modified_gmt":"2020-12-21T06:14:12","slug":"unrealtemplate-h","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=2956","title":{"rendered":"C++\u6a21\u677f\u5e94\u7528\u793a\u4f8b"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/\/ microsoft stl\n\n\/\/ STRUCT TEMPLATE remove_reference\ntemplate &lt;class _Ty>\nstruct remove_reference {\n    using type                 = _Ty;\n    using _Const_thru_ref_type = const _Ty;\n};\n\ntemplate &lt;class _Ty>\nstruct remove_reference&lt;_Ty&amp;> {\n    using type                 = _Ty;\n    using _Const_thru_ref_type = const _Ty&amp;;\n};\n\ntemplate &lt;class _Ty>\nstruct remove_reference&lt;_Ty&amp;&amp;> {\n    using type                 = _Ty;\n    using _Const_thru_ref_type = const _Ty&amp;&amp;;\n};\n\ntemplate &lt;class _Ty>\nusing remove_reference_t = typename remove_reference&lt;_Ty>::type;\n\n\n\n\/\/ epic unreal \n\n\/**\n * TRemoveReference&lt;type> will remove any references from a type.\n *\/\ntemplate &lt;typename T> struct TRemoveReference      { typedef T Type; };\ntemplate &lt;typename T> struct TRemoveReference&lt;T&amp; > { typedef T Type; };\ntemplate &lt;typename T> struct TRemoveReference&lt;T&amp;&amp;> { typedef T Type; };\n\n\/**\n * Removes one level of pointer from a type, e.g.:\n *\n * TRemovePointer&lt;      int32  >::Type == int32\n * TRemovePointer&lt;      int32* >::Type == int32\n * TRemovePointer&lt;      int32**>::Type == int32*\n * TRemovePointer&lt;const int32* >::Type == const int32\n *\/\ntemplate &lt;typename T> struct TRemovePointer     { typedef T Type; };\ntemplate &lt;typename T> struct TRemovePointer&lt;T*> { typedef T Type; };\n\n\/**\n * MoveTemp will cast a reference to an rvalue reference.\n * This is UE's equivalent of std::move except that it will not compile when passed an rvalue or\n * const object, because we would prefer to be informed when MoveTemp will have no effect.\n *\/\ntemplate &lt;typename T>\nFORCEINLINE typename TRemoveReference&lt;T>::Type&amp;&amp; MoveTemp(T&amp;&amp; Obj)\n{\n\ttypedef typename TRemoveReference&lt;T>::Type CastType;\n\n\t\/\/ Validate that we're not being passed an rvalue or a const object - the former is redundant, the latter is almost certainly a mistake\n\tstatic_assert(TIsLValueReferenceType&lt;T>::Value, \"MoveTemp called on an rvalue\");\n\tstatic_assert(!TAreTypesEqual&lt;CastType&amp;, const CastType&amp;>::Value, \"MoveTemp called on a const object\");\n\n\treturn (CastType&amp;&amp;)Obj;\n}\n\n\/**\n * MoveTemp will cast a reference to an rvalue reference.\n * This is UE's equivalent of std::move.  It doesn't static assert like MoveTemp, because it is useful in\n * templates or macros where it's not obvious what the argument is, but you want to take advantage of move semantics\n * where you can but not stop compilation.\n *\/\ntemplate &lt;typename T>\nFORCEINLINE typename TRemoveReference&lt;T>::Type&amp;&amp; MoveTempIfPossible(T&amp;&amp; Obj)\n{\n\ttypedef typename TRemoveReference&lt;T>::Type CastType;\n\treturn (CastType&amp;&amp;)Obj;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2956"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2956"}],"version-history":[{"count":3,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2956\/revisions"}],"predecessor-version":[{"id":2975,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2956\/revisions\/2975"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}