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

    <legend id='RQ2Gs'><style id='RQ2Gs'><dir id='RQ2Gs'><q id='RQ2Gs'></q></dir></style></legend>
    1. <small id='RQ2Gs'></small><noframes id='RQ2Gs'>

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

      帶有模板容器的模板類

      Template class with template container(帶有模板容器的模板類)
        <tbody id='2FHYx'></tbody>

      • <small id='2FHYx'></small><noframes id='2FHYx'>

        • <legend id='2FHYx'><style id='2FHYx'><dir id='2FHYx'><q id='2FHYx'></q></dir></style></legend>
            <bdo id='2FHYx'></bdo><ul id='2FHYx'></ul>

                <tfoot id='2FHYx'></tfoot>
                <i id='2FHYx'><tr id='2FHYx'><dt id='2FHYx'><q id='2FHYx'><span id='2FHYx'><b id='2FHYx'><form id='2FHYx'><ins id='2FHYx'></ins><ul id='2FHYx'></ul><sub id='2FHYx'></sub></form><legend id='2FHYx'></legend><bdo id='2FHYx'><pre id='2FHYx'><center id='2FHYx'></center></pre></bdo></b><th id='2FHYx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='2FHYx'><tfoot id='2FHYx'></tfoot><dl id='2FHYx'><fieldset id='2FHYx'></fieldset></dl></div>
              1. 本文介紹了帶有模板容器的模板類的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                如何將具有不同容器的模板類(適配器)聲明為模板參數?例如,我需要聲明類:

                How can I declare template class (adaptor) with different containers as template arguments? For example, I need to declare class:

                template<typename T, typename Container>
                class MyMultibyteString
                {
                    Container buffer;
                    ...
                };
                

                我希望它基于向量.如何讓它硬定義?(為了防止有人寫這樣的聲明MyMultibyteString>).

                And I want it to my based on vector. How to make it hard-defined? (to prevent someone from writing such declaration MyMultibyteString<int, vector<char>>).

                此外,如何實現這樣的構造:

                Moreover, how to implement such construction:

                MyMultibyteString<int, std::vector> mbs;
                

                不將模板參數傳遞給容器.

                without passing template argument to container.

                推薦答案

                你應該使用模板模板參數:

                template<typename T, template <typename, typename> class Container>
                //                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                class MyMultibyteString
                {
                    Container<T, std::allocator<T>> buffer;
                    // ...
                };
                

                這將允許你寫:

                MyMultibyteString<int, std::vector> mbs;
                

                這是一個編譯現場示例.編寫上述內容的另一種方式可能是:

                Here is a compiling live example. An alternative way of writing the above could be:

                template<typename T,
                    template <typename, typename = std::allocator<T>> class Container>
                //  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                class MyMultibyteString
                {
                    Container<T> buffer; // <== No more need to specify the second argument here
                    // ...
                };
                

                這是相應的現場示例.

                唯一需要注意的是,模板模板參數聲明中的參數數量和類型必須與要作為模板傳遞的相應類模板的定義中的參數數量和類型完全匹配參數,不管這些參數中的一些可能有默認值.

                The only thing you have to pay attention to is that the number and type of arguments in the template template parameter declaration must match exactly the number and type of arguments in the definition of the corresponding class template you want to pass as a template argument, regardless of the fact that some of those parameters may have default values.

                例如,類模板std::vector接受兩個模板參數(元素類型和分配器類型),盡管第二個具有默認值 std::allocator.因此,您可以寫:

                For instance, the class template std::vector accepts two template parameters (the element type and the allocator type), although the second one has the default value std::allocator<T>. Because of this, you could not write:

                template<typename T, template <typename> class Container>
                //                             ^^^^^^^^
                //                             Notice: just one template parameter declared!
                class MyMultibyteString
                {
                    Container<T> buffer;
                    // ...
                };
                
                // ...
                
                MyMultibyteString<int, std::vector> mbs; // ERROR!
                //                     ^^^^^^^^^^^
                //                     The std::vector class template accepts *two*
                //                     template parameters (even though the second
                //                     one has a default argument)
                

                這意味著您將無法編寫一個可以同時接受 std::setstd::vector 作為模板模板參數的類模板,因為與 std::vector 不同,std::set> 類模板接受三個模板參數.

                This means that you won't be able to write one single class template that can accept both std::set and std::vector as a template template parameter, because unlike std::vector, the std::set class template accepts three template parameters.

                這篇關于帶有模板容器的模板類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                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 不能)
              2. <legend id='xtLS0'><style id='xtLS0'><dir id='xtLS0'><q id='xtLS0'></q></dir></style></legend>
              3. <tfoot id='xtLS0'></tfoot>

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

                    <small id='xtLS0'></small><noframes id='xtLS0'>

                            <tbody id='xtLS0'></tbody>
                          主站蜘蛛池模板: 久久久久久久一区 | 国产精品久久久久久av公交车 | 欧美精品成人一区二区三区四区 | 最近免费日本视频在线 | 91久久久www播放日本观看 | 国产成人在线视频播放 | 91视频www.| 午夜婷婷激情 | 欧美日韩视频 | 一级看片 | 国产一二三区在线 | 成人精品一区二区三区中文字幕 | 久久小视频 | 欧美综合一区 | 日本精品一区二区三区在线观看视频 | 国产亚洲第一页 | 在线观看www高清视频 | 精品国产乱码久久久久久闺蜜 | 国产一级一片免费播放 | 一级做a | 米奇成人网 | 免费高清成人 | 91精品在线看 | 欧美一级欧美三级在线观看 | 在线日韩不卡 | 91精品国产麻豆 | 精品成人 | 91视频免费在观看 | 国产一区免费 | 91国在线高清视频 | 一区二区三区免费观看 | 噜噜噜噜狠狠狠7777视频 | 欧美精品免费观看二区 | 国产精品久久久久久久一区探花 | 婷婷综合色 | 免费性视频 | 一区视频在线播放 | 高清国产一区二区 | 国产精品久久久久久久免费大片 | 我我色综合 | 亚洲一级视频在线 |