Add custom messages in assert?

后端 未结 8 1021
心在旅途
心在旅途 2020-12-04 07:18

Is there a way to add or edit the message thrown by assert? I\'d like to use something like

assert(a == b, \"A must be equal to B\");

Then

8条回答
  •  误落风尘
    2020-12-04 07:42

    BOOST_ASSERT_MSG(expre, msg)
    

    http://www.boost.org/doc/libs/1_51_0/libs/utility/assert.html

    You could either use that directly or copy Boost's code. Also note Boost assert is header only, so you could just grab that single file if you didn't want to install all of Boost.

提交回复
热议问题