草庐IT

assert_param

全部标签

c++ - 在 Boost Test 框架中测试 assert

我使用BoostTest框架对我的C++代码进行单元测试,并想知道是否可以测试一个函数是否会断言?是的,听起来有点奇怪,但请耐心等待!我的许多函数在输入时检查输入参数,断言它们是否无效,对此进行测试会很有用。例如:voidMyFunction(intparam){assert(param>0);//paramcannotbelessthan1...}我希望能够做这样的事情:BOOST_CHECK_ASSERT(MyFunction(0),true);BOOST_CHECK_ASSERT(MyFunction(-1),true);BOOST_CHECK_ASSERT(MyFunction

c++ - 在 Boost Test 框架中测试 assert

我使用BoostTest框架对我的C++代码进行单元测试,并想知道是否可以测试一个函数是否会断言?是的,听起来有点奇怪,但请耐心等待!我的许多函数在输入时检查输入参数,断言它们是否无效,对此进行测试会很有用。例如:voidMyFunction(intparam){assert(param>0);//paramcannotbelessthan1...}我希望能够做这样的事情:BOOST_CHECK_ASSERT(MyFunction(0),true);BOOST_CHECK_ASSERT(MyFunction(-1),true);BOOST_CHECK_ASSERT(MyFunction

c++ - 使用static_assert时如何避免没有返回表达式的警告?

我有两个库可以使用,并且为了方便起见,我在它们使用的一些类型/结构之间编写了一个转换器。templatestructunsupportedType:std::false_type{};templateFormatBgetFormat(){static_assert(unsupportedType::value,"Thisisnotsupported!");}templateFormatBgetFormat(){returnFormatB(//someparameters);}templateFormatBgetFormat(){returnFormatB(//someotherpara

c++ - 使用static_assert时如何避免没有返回表达式的警告?

我有两个库可以使用,并且为了方便起见,我在它们使用的一些类型/结构之间编写了一个转换器。templatestructunsupportedType:std::false_type{};templateFormatBgetFormat(){static_assert(unsupportedType::value,"Thisisnotsupported!");}templateFormatBgetFormat(){returnFormatB(//someparameters);}templateFormatBgetFormat(){returnFormatB(//someotherpara

c++ - Doxygen @param 方向参数 [in],[out],[in,out] 示例输出

@param命令的可选方向参数已记录here作为以下之一:@param[in]@param[out]@param[in,out]我没有看到任何examplesites此信息如何出现在输出中。是否有示例说明此信息应如何出现在输出中? 最佳答案 对于线路:\param[in,out]console_ptr-pointertoinputfromtheconsole我明白了:Parameters[in,out]console_ptr-pointertoinputfromtheconsole. 关

c++ - Doxygen @param 方向参数 [in],[out],[in,out] 示例输出

@param命令的可选方向参数已记录here作为以下之一:@param[in]@param[out]@param[in,out]我没有看到任何examplesites此信息如何出现在输出中。是否有示例说明此信息应如何出现在输出中? 最佳答案 对于线路:\param[in,out]console_ptr-pointertoinputfromtheconsole我明白了:Parameters[in,out]console_ptr-pointertoinputfromtheconsole. 关

C++,实现函数时出现奇怪的编译器错误 `int next(std::string param)`

我被下面的代码严重咬了一口,浪费了我好几个小时的宝贵时间。#includeintnext(std::stringparam){return0;}voidfoo(){next(std::string{"abc"});}这会产生以下编译器错误(在VisualStudio2013上):1>------Buildstarted:Project:sandbox,Configuration:DebugWin32------1>test.cpp1>c:\programfiles(x86)\microsoftvisualstudio12.0\vc\include\xutility(371):error

C++,实现函数时出现奇怪的编译器错误 `int next(std::string param)`

我被下面的代码严重咬了一口,浪费了我好几个小时的宝贵时间。#includeintnext(std::stringparam){return0;}voidfoo(){next(std::string{"abc"});}这会产生以下编译器错误(在VisualStudio2013上):1>------Buildstarted:Project:sandbox,Configuration:DebugWin32------1>test.cpp1>c:\programfiles(x86)\microsoftvisualstudio12.0\vc\include\xutility(371):error

c++ - 何时使用 `static_assert` 而不是 SFINAE?

我一直在使用(并且看到使用)static_assert来标记模板参数值的不想要的值。但是,对于我遇到的所有情况,通过SFINAE禁用那些不需要的值似乎更好、更优雅。例如:template::value>::type>structFoo{...};代替:templatestructFoo{static_assert(std::is_floating_point::value,"Foo:Tmustbefloatingpoint:-(");...};所以我的问题是:我什么时候应该使用static_assert而不是SFINAE,为什么?编辑:我认为到目前为止我学到的内容如下:1.SFINAE

c++ - 何时使用 `static_assert` 而不是 SFINAE?

我一直在使用(并且看到使用)static_assert来标记模板参数值的不想要的值。但是,对于我遇到的所有情况,通过SFINAE禁用那些不需要的值似乎更好、更优雅。例如:template::value>::type>structFoo{...};代替:templatestructFoo{static_assert(std::is_floating_point::value,"Foo:Tmustbefloatingpoint:-(");...};所以我的问题是:我什么时候应该使用static_assert而不是SFINAE,为什么?编辑:我认为到目前为止我学到的内容如下:1.SFINAE