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

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

      1. <small id='3MTtZ'></small><noframes id='3MTtZ'>

      2. 断言代码不能编译

        Assert that code does NOT compile(断言代码不能编译)

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

            <small id='0AW66'></small><noframes id='0AW66'>

                  <tbody id='0AW66'></tbody>
                  <tfoot id='0AW66'></tfoot>

                • <legend id='0AW66'><style id='0AW66'><dir id='0AW66'><q id='0AW66'></q></dir></style></legend>
                  本文介绍了断言代码不能编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  简而言之:

                  如何编写测试,检查我的类是否不可复制或可复制分配,而只能移动和可移动分配?

                  How to write a test, that checks that my class is not copyable or copy-assignable, but is only moveable and move-assignable?

                  一般来说:

                  如何编写测试以确保特定代码不会编译?像这样:

                  How to write a test, that makes sure that a specific code does not compile? Like this:

                  // Movable, but non-copyable class
                  struct A
                  {
                    A(const A&) = delete;
                    A(A&&) {}
                  };
                  
                  void DoCopy()
                  {
                    A a1;
                    A a2 = a1;
                  }
                  
                  void DoMove()
                  {
                    A a1;
                    A a2 = std::move(a1);
                  }
                  
                  void main()
                  {
                    // How to define these checks?
                    if (COMPILES(DoMove)) std::cout << "Passed" << std::endl;
                    if (DOES_NOT_COMPILE(DoCopy)) std::cout << "Passed" << std::endl;
                  }
                  

                  我猜想与 SFINAE 有关系,但是否有一些现成的解决方案,也许在提升?

                  I guess something to do with SFINAE, but are there some ready solutions, maybe in boost?

                  推荐答案

                  一篇好文章的结尾给出了很好的答案可诊断有效性" by Andrzej Krzemieński:

                  A good answer is given at the end of a great article "Diagnosable validity" by Andrzej Krzemieński:

                  检查给定构造是否编译失败的一种实用方法是从 C++ 外部进行:准备一个带有错误构造的小型测试程序,编译它,然后测试编译器是否报告编译失败.这就是负面"单元测试如何与 Boost.Build 一起工作.有关示例,请参阅此负面测试表单 Boost.Optional 库:optional_test_fail_convert_from_null.cpp.在配置文件中标注为compile-fail,表示只有编译失败才通过测试.

                  A practical way to check if a given construct fails to compile is to do it from outside C++: prepare a small test program with erroneous construct, compile it, and test if compiler reports compilation failure. This is how "negative" unit tests work with Boost.Build. For an example, see this negative test form Boost.Optional library: optional_test_fail_convert_from_null.cpp. In configuration file it is annotated as compile-fail, meaning that test passes only if compilation fails.

                  这篇关于断言代码不能编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)

                • <i id='O2nkb'><tr id='O2nkb'><dt id='O2nkb'><q id='O2nkb'><span id='O2nkb'><b id='O2nkb'><form id='O2nkb'><ins id='O2nkb'></ins><ul id='O2nkb'></ul><sub id='O2nkb'></sub></form><legend id='O2nkb'></legend><bdo id='O2nkb'><pre id='O2nkb'><center id='O2nkb'></center></pre></bdo></b><th id='O2nkb'></th></span></q></dt></tr></i><div id='O2nkb'><tfoot id='O2nkb'></tfoot><dl id='O2nkb'><fieldset id='O2nkb'></fieldset></dl></div>
                      • <tfoot id='O2nkb'></tfoot>
                        • <bdo id='O2nkb'></bdo><ul id='O2nkb'></ul>
                            <tbody id='O2nkb'></tbody>
                          <legend id='O2nkb'><style id='O2nkb'><dir id='O2nkb'><q id='O2nkb'></q></dir></style></legend>

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