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

    <bdo id='AnIHa'></bdo><ul id='AnIHa'></ul>
    <legend id='AnIHa'><style id='AnIHa'><dir id='AnIHa'><q id='AnIHa'></q></dir></style></legend>

    <tfoot id='AnIHa'></tfoot>

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

      1. 在 static_assert 輸出中集成類型名稱?

        Integrate type name in static_assert output?(在 static_assert 輸出中集成類型名稱?)
        • <tfoot id='HM0jh'></tfoot>

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

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

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

                • <bdo id='HM0jh'></bdo><ul id='HM0jh'></ul>
                    <tbody id='HM0jh'></tbody>
                  本文介紹了在 static_assert 輸出中集成類型名稱?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我喜歡提供有用的錯誤/消息,我也想為我的 static_assert 這樣做.問題是,它們依賴于模板參數.通常,由于引發的錯誤,這些參數會在途中或其他地方顯示,但它們要么模糊不清,要么沒有分組,因此它們是有意義的.示例:

                  I like to give helpful errors / messages, and I also want to do so for my static_asserts. The problem is, that they depend on template parameters. Normally, those parameters will get displayed on way or an other due to the error raised, but they are either obscure or not grouped so they make sense. Example:

                  template<class T>
                  struct fake_dependency{
                    static bool const value = false;
                  };
                  
                  template<class T, class Tag>
                  struct Foo{
                    Foo(){}
                  
                    template<class OtherTag>
                    Foo(Foo<T, OtherTag> const&){
                      static_assert(fake_dependency<T>::value, "Cannot create Foo<T,Tag> from Foo<T,OtherTag>.");
                    }
                  };
                  
                  int main(){
                      Foo<int, struct TagA> fA;
                      Foo<int, struct TagB> fB(fA);
                  }
                  

                  MSVC 上的輸出:

                  srcmain.cpp(74): error C2338: Cannot create Foo<T,Tag> from Foo<T,OtherTag>.
                            srcmain.cpp(84) : see reference to function template instantiation 'Foo<T,Tag>::Foo<main::TagA>(const Foo<T,main::TagA> &)' being compiled
                            with
                            [
                                T=int,
                                Tag=main::TagB
                            ]
                  

                  一個標簽在函數模板中提到,另一個在類模板下面.沒那么好.讓我們看看 GCC 輸出:

                  One tag is mentioned in the function template itself, the other below with the class template. Not so nice. Lets see what GCC outputs:

                  prog.cpp: In constructor 'Foo<T, Tag>::Foo(const Foo<T, OtherTag>&) [with OtherTag = main()::TagA, T = int, Tag = main()::TagB]':
                  prog.cpp:18:32:   instantiated from here
                  prog.cpp:12:5: error: static assertion failed: "Cannot create Foo<T,Tag> from Foo<T,OtherTag>."
                  

                  好多了,但仍然不是 static_assert 所在的位置.現在想象更多的參數,或更多的模板,或兩者兼而有之.顫抖

                  Much better, but still not really where the static_assert is. And now imagine some more parameters, or more templates, or both. shivers

                  解決這個問題的一種方法是使用中間結構,它將兩個標簽都作為模板參數:

                  One way to work around that is to use an intermediate struct, which takes both Tags as template parameters:

                  template<class Tag, class OtherTag>
                  struct static_Foo_assert{
                      static_assert(fake_dependency<Tag>::value, "Cannot create Foo<T,Tag> from Foo<T,OtherTag>.");
                  };
                  
                  template<class T, class Tag>
                  struct Foo{
                    Foo(){}
                  
                    template<class OtherTag>
                    Foo(Foo<T, OtherTag> const&){
                        static_Foo_assert<Tag, OtherTag> x;
                    }
                  };
                  

                  現在讓我們再次查看輸出:

                  Now lets see the output again:

                  srcmain.cpp(70): error C2338: Cannot create Foo<T,Tag> from Foo<T,OtherTag>.
                            srcmain.cpp(79) : see reference to class template instantiation 'static_Foo_assert<Tag,OtherTag>' being compiled
                            with
                            [
                                Tag=main::TagB,
                                OtherTag=main::TagA
                            ]
                  

                  好多了!以下是 GCC 的聲明:

                  prog.cpp: In instantiation of 'static_Foo_assert<main()::TagB, main()::TagA>':
                  prog.cpp:17:40:   instantiated from 'Foo<T, Tag>::Foo(const Foo<T, OtherTag>&) [with OtherTag = main()::TagA, T = int, Tag = main()::TagB]'
                  prog.cpp:23:32:   instantiated from here
                  prog.cpp:8:5: error: static assertion failed: "Cannot create Foo<T,Tag> from Foo<T,OtherTag>."
                  

                  看起來還不錯.問題:我需要為每個模板創建這樣的結構,因為 static_assert 中的錯誤消息需要是字符串文字...

                  Looks not bad. The problem: I need to create such a struct for every template, since the error message in static_assert needs to be a string literal...

                  現在,對于我的問題:我們能否以某種方式將類型名稱直接包含在 static_assert 中?喜歡

                  Now, for my question: Can we somehow include the type names directly into the static_assert? Like

                  static_assert(..., "Cannot create Foo<" T "," Tag "> from Foo<" T "," OtherTag ">.");
                  

                  示例輸出:

                  無法從 Foo 創建 Foo.

                  或者,如果這無法實現,我們能否以某種方式使錯誤消息成為額外的模板參數,以使其可通過?

                  Or, if that isn't achievable, can we somehow make the error message an extra template parameter, as to make it passable?

                  推薦答案

                  My Hack

                  代碼:

                  template <typename Assertion>
                  struct AssertValue : AssertionChecker<Assertion::value, Assertion>
                  {
                      static_assert(AssertionValue, "Assertion failed <see below for more information>");
                      static bool const value = Assertion::value;
                  };
                  

                  它允許您檢查任何 ::value 斷言并在失敗時轉儲類型.

                  It allows for you to check any ::value assertion and dump the types if it failed.

                  // Bad indentation used to show parts
                  static_assert(
                      AssertValue<
                          std::my_check<
                              T0, decltype(*somethingComplicated), T7::value_type
                          >
                      >, 
                      "something horrible happened"
                  );
                  

                  其中 std::my_check<...>::value 是檢查的布爾結果

                  where std::my_check<...>::value is the boolean result of the check

                  有關完整的 SSCCE 示例,請參閱:IDEOne 示例

                  For a full SSCCE example see: IDEOne Example

                  示例的錯誤信息:

                  prog.cpp: In instantiation of 'AssertValue<std::is_base_of<IMyInterface, MyBadType> >':
                  prog.cpp:37:69:   instantiated from 'void MyFunction(IteratorType, IteratorType) [with IteratorType = __gnu_cxx::__normal_iterator<MyBadType*, std::vector<MyBadType> >]'
                  prog.cpp:60:38:   instantiated from here
                  prog.cpp:9:5: error: static assertion failed: "Assertion failed <see below for more information>"
                  prog.cpp: In function 'void MyFunction(IteratorType, IteratorType) [with IteratorType = __gnu_cxx::__normal_iterator<MyBadType*, std::vector<MyBadType> >]':
                  prog.cpp:60:38:   instantiated from here
                  prog.cpp:39:5: error: static assertion failed: "iterator passed does not reference IMyInterface items"
                  

                  說明

                  如果斷言失敗,它將打印 AssertValue 的模板參數,因此打印您支票的完整模板擴展.例如,如果您正在檢查 std::is_base_of,它將打印檢查的完整類型,例如:std::is_base_of.然后你就知道在失敗的斷言中使用了哪些類型.

                  Explanation

                  If the assertion fails, it will print the template arguments of AssertValue and therefore print the full template expansion of your check. For example, if you were checking a std::is_base_of it will print the full type of the check, e.g.: std::is_base_of<IMyInterface, MyBadType>. Then you know exactly what types were used in the failed assertion.

                  唯一的問題是這只適用于將結果放在 ::value 中的模板.然而,type_traits 主要使用這個并且是 goto 標準.

                  The only problem is that this only works on templates that put their result in ::value. However type_traits mostly uses this and is the goto standard.

                  這篇關于在 static_assert 輸出中集成類型名稱?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 不能)

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

                    1. <tfoot id='HL0J1'></tfoot>

                        <bdo id='HL0J1'></bdo><ul id='HL0J1'></ul>
                              <tbody id='HL0J1'></tbody>
                            主站蜘蛛池模板: 天天综合久久 | 免费一级淫片aaa片毛片a级 | 日韩欧美在线一区 | 久久免费精品 | 日本成人在线观看网站 | 一区二区在线不卡 | 欧美在线一二三 | 国产在线一区二区 | 久久综合激情 | 国产欧美日韩综合精品一区二区 | 九七午夜剧场福利写真 | 久久影院一区 | 91精品久久久久久久久中文字幕 | 91精品久久久久久综合五月天 | 先锋资源吧| 四虎影| 国产免费观看久久黄av片涩av | 亚洲最色网站 | 亚洲精品电影在线观看 | 国产精品69毛片高清亚洲 | 超碰在线免费公开 | 亚洲精品www. | av福利网 | 日韩久久久久 | 五月婷婷丁香婷婷 | 美女福利视频 | 中文字幕一区二区三区四区不卡 | 一区二区三区四区免费在线观看 | 久久无毛| 先锋av资源在线 | 欧美性网 | av男人的天堂av | 黄在线免费观看 | 欧美亚洲国产一区二区三区 | 国产成人精品一区二区三区四区 | 电影91久久久 | 欧美精品v国产精品v日韩精品 | 精品一区二区久久久久久久网站 | 日韩av一区二区在线观看 | 超黄毛片 | 黄色一级大片在线免费看产 |