Assert that code does NOT compile

后端 未结 6 959
长发绾君心
长发绾君心 2020-12-03 04:54

In short:

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

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 05:42

    You might have to structure your code a bit differently to use it, but it sounds like you might be looking for

    static_assert ( bool_constexpr , message )

    Performs compile-time assertion checking (since C++11): Explanation: bool_constexpr - a constant expression that is contextually convertible to bool; message - string literal that will appear as compiler error if bool_constexpr is false. A static assert declaration may appear at block scope (as a block declaration) and inside a class body (as a member declaration)

提交回复
热议问题