久久久久久久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网站 | 久久精品一区二区国产 | 夜夜欢视频| 免费国产一区二区 | 欧美日韩免费在线观看 | 精品久久一区二区三区 | 亚洲xxxxx | 99色综合| 91在线免费视频观看 | 蜜臀久久99精品久久久久宅男 | 久久黄色影院 | 亚洲久久在线 | 四级黄色片 | www黄色片| 婷婷中文字幕 | 黄色综合网 | 亚洲精品一区二区三区在线观看 | 狠狠干伊人 | 久久久久免费视频 | 亚洲国产日韩在线 | 久草福利在线 | 国产亚洲欧美在线 | 亚洲一区二区免费 | 在线观看av的网站 | 久久精品亚洲 | 日韩色网 | 国产精品免费一区 | 欧美一级色 |