久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <small id='cT1uq'></small><noframes id='cT1uq'>

        <bdo id='cT1uq'></bdo><ul id='cT1uq'></ul>
    1. <tfoot id='cT1uq'></tfoot>

      <i id='cT1uq'><tr id='cT1uq'><dt id='cT1uq'><q id='cT1uq'><span id='cT1uq'><b id='cT1uq'><form id='cT1uq'><ins id='cT1uq'></ins><ul id='cT1uq'></ul><sub id='cT1uq'></sub></form><legend id='cT1uq'></legend><bdo id='cT1uq'><pre id='cT1uq'><center id='cT1uq'></center></pre></bdo></b><th id='cT1uq'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='cT1uq'><tfoot id='cT1uq'></tfoot><dl id='cT1uq'><fieldset id='cT1uq'></fieldset></dl></div>

      <legend id='cT1uq'><style id='cT1uq'><dir id='cT1uq'><q id='cT1uq'></q></dir></style></legend>

        C++模板參數類型推斷

        c++ template parameter type inference(C++模板參數類型推斷)
        • <tfoot id='ARAVJ'></tfoot>
        • <legend id='ARAVJ'><style id='ARAVJ'><dir id='ARAVJ'><q id='ARAVJ'></q></dir></style></legend>
              <i id='ARAVJ'><tr id='ARAVJ'><dt id='ARAVJ'><q id='ARAVJ'><span id='ARAVJ'><b id='ARAVJ'><form id='ARAVJ'><ins id='ARAVJ'></ins><ul id='ARAVJ'></ul><sub id='ARAVJ'></sub></form><legend id='ARAVJ'></legend><bdo id='ARAVJ'><pre id='ARAVJ'><center id='ARAVJ'></center></pre></bdo></b><th id='ARAVJ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ARAVJ'><tfoot id='ARAVJ'></tfoot><dl id='ARAVJ'><fieldset id='ARAVJ'></fieldset></dl></div>

                <bdo id='ARAVJ'></bdo><ul id='ARAVJ'></ul>
              • <small id='ARAVJ'></small><noframes id='ARAVJ'>

                  <tbody id='ARAVJ'></tbody>

                  本文介紹了C++模板參數類型推斷的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我在 C++ 中有這樣一個模板

                  I have such a template in C++

                  template<typename T, T* P> struct Ptr {};
                  

                  所以我可以這樣使用它:

                  so I can use it as such:

                  const int i = 0;
                  Ptr<int, &i> ptr;
                  

                  Ptr<decltype(i), &i> ptr;
                  

                  但我不想指定類型 int 或身份 i 兩次,我只想使用

                  But I don't want to specify the type int or identity i twice, I want to use just

                  Ptr<&i> ptr;
                  

                  并讓編譯器自己找出 int 類型部分.

                  and let the compiler figure out the int type part by itself.

                  我如何聲明我的模板來做到這一點?

                  How can I declare my template to do that ?

                  我讀過這個問題,但答案是使用宏,這不好:模板c++的模板?

                  I've read this question but the answer is using macros, that's not nice: template of template c++?

                  我可以通過沒有宏的模板來做到這一點嗎?我使用的是 Visual C++ 2013.

                  can I do this by just template without macros ? I'm using Visual C++ 2013.

                  推薦答案

                  UPDATE

                  c++17 引入了P0127R2 使用 auto 聲明非類型模板參數",允許聲明非類型模板使用 auto 作為實際類型占位符的參數:

                  c++17 introduced "P0127R2 Declaring non-type template parameters with auto", allowing to declare a non-type template parameter(s) with auto as a placeholder for the actual type:

                  template <auto P> struct Ptr {};
                  

                  也就是說,P 是一個非類型模板參數.它的類型可以通過 decltype(P) 推斷出來.

                  That is, P is a non-type template parameter. Its type can be inferred with decltype(P).

                  auto 遵循眾所周知的推導和偏序規則.在您的情況下,可以將類型限制為僅接受指針:

                  auto in a template parameter list is subject to well-known deduction and partial ordering rules. In your case, the type can be constrained to accept pointers only:

                  template <auto* P> struct Ptr {};
                  

                  請注意,即使對于更詳細的檢查,使用 auto 的語法也足夠了,例如:

                  Note that the syntax utilizing auto is sufficient even for more detailed inspection, e.g.:

                  template <typename F>
                  struct FunctionBase;
                  
                  template <typename R, typename... Args>
                  struct FunctionBase<R(*)(Args...)> {};
                  
                  template <auto F>
                  struct Function : FunctionBase<decltype(F)> {};
                  

                  也可以使用推斷類型作為其他模板參數的約束:

                  It's also possible to use the inferred type as a contraint for other template parameters:

                  template <auto I, decltype(I)... Is>
                  struct List {};
                  

                  <小時>

                  舊答案

                  既然您問的是一個沒有宏定義幫助的基于類模板的純解決方案,那么答案很簡單:至于現在(2014 年 12 月,c++14) 不可能.

                  Since you are asking about a pure class template-based solution without the help of macro definitions then the answer is simple: as for now (Dec 2014, c++14) it is not possible.

                  這個問題已經被 WG21 C++ 標準委員會確定為需要,并且有幾個建議讓模板自動推斷非類型模板參數的類型.

                  This issue has been already identified by the WG21 C++ Standard Committee as a need and there are several proposals to let templates automatically infer the type of non-type template arguments.

                  最接近的是N3601 隱式模板參數:

                  此示例的目的是消除對冗余 template 習語的需要.這個習語被廣泛使用,在谷歌上的點擊量超過 10 萬次.

                  Implicit template parameters

                  The purpose of this example is to eliminate the need for the redundant template<typename T, T t> idiom. This idiom is widely used, with over 100k hits on Google.

                  目標是能夠替換像template這樣的模板聲明.struct C; 和另一個聲明,這樣我們就可以像 C<&X::f> 一樣實例化模板,而不必說 C.

                  The goal is to be able to replace a template declaration like template<typename T, T t> struct C; with another declaration so that we can instantatiate the template like C<&X::f> instead of having to say C<decltype(&X::f), &X::f>.

                  基本思想是能夠說template;struct C {/* ... *

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Why do two functions have the same address?(為什么兩個函數的地址相同?)
                  Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復制構造的?)
                  mixing templates with polymorphism(混合模板與多態性)
                  When should I use the keyword quot;typenamequot; when using templates(我什么時候應該使用關鍵字“typename?使用模板時)
                  Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標準庫)
                  gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數模板,而 clang 不能)

                    <i id='k15I8'><tr id='k15I8'><dt id='k15I8'><q id='k15I8'><span id='k15I8'><b id='k15I8'><form id='k15I8'><ins id='k15I8'></ins><ul id='k15I8'></ul><sub id='k15I8'></sub></form><legend id='k15I8'></legend><bdo id='k15I8'><pre id='k15I8'><center id='k15I8'></center></pre></bdo></b><th id='k15I8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='k15I8'><tfoot id='k15I8'></tfoot><dl id='k15I8'><fieldset id='k15I8'></fieldset></dl></div>
                    <tfoot id='k15I8'></tfoot>
                      <bdo id='k15I8'></bdo><ul id='k15I8'></ul>
                    • <small id='k15I8'></small><noframes id='k15I8'>

                      <legend id='k15I8'><style id='k15I8'><dir id='k15I8'><q id='k15I8'></q></dir></style></legend>
                              <tbody id='k15I8'></tbody>
                            主站蜘蛛池模板: 成人在线小视频 | 国产女人高潮视频 | 视频一区二区在线播放 | 美日韩在线视频 | 久久99精品久久久久久 | 国产涩涩| 国产日韩免费 | 五月天婷婷丁香 | 偷拍一区二区 | 国产精品久久久久久久久久久久久久久 | 亚洲精品乱码久久久久久 | 日本中文字幕一区 | 草草在线观看 | 久久这里只有精品6 | 天天cao| 日本天堂网 | 国产毛片一级 | 日韩综合精品 | 福利网站在线观看 | 中文字幕一区二区三区四区 | 久久视频在线免费观看 | 九色视频丨porny丨丝袜 | 亚洲激情网 | 国产乱国产乱300精品 | 黄色成人小视频 | 日韩影音 | 免费日韩视频 | 国产精品一区二区视频 | 国产激情小说 | 少妇一级淫片免费观看 | 精品视频在线播放 | 蜜桃91丨九色丨蝌蚪91桃色 | 国产福利视频在线观看 | 久久人人视频 | 在线色网 | 亚洲欧美中文字幕 | 国产精品毛片va一区二区三区 | 欧美日韩精品一区 | 一区二区三区四区精品 | 日日干干 | 成人av一区二区三区在线观看 |