作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个模板函数,可以在其中放置每种类型。现在确实该功能将始终有效。如果类型 T 是 int,则 int 总是来自函数。如果一个字符串进来,一个字符串就出来。
现在我刚刚查看了 boost 文档。 Boost 指示我必须使用 BOOST_AUTO_TEST_CASE_TEMPLATE。
假设我有以下情况:
BOOST_AUTO_TEST_SUITE (MyTestSuite)
typedef boost :: mpl :: list <int, long, short, double, float, std :: string> TestTypes;
BOOST_AUTO_TEST_CASE_TEMPLATE (MyTestCase, T, TestTypes)
{
// These three values will be separated by ',' and can be accessed seprately thanks to their individual getters.
std :: string input = "5,6,7";
Myclass <T> myClass (input);
BOOST_TEST (myClass.getFirst() == 5);
BOOST_TEST (myClass.getSecond() == 6);
BOOST_TEST (myClass.getThird() == 7);
}
BOOST_AUTO_TEST_SUITE_END()
如你所见,我不想检查我取回的类型是否正确,而是我取回的值是否与我给的值相同。因此,如果我给出 5 并且类型为 double,那么我的类(class)为 5.00。我的支票目前不这样做。如何确保我要查询的号码始终与我提供的类型相同?这听起来可能有点困难,但如果您需要更多信息,那么我将编辑此消息。
假设这行得通。然后我想使用该类型的最小值和最大值作为输入。我怎么做?如何获取 T 的最小值和最大值?
最佳答案
您可以使用decltype
和 STL traits:
BOOST_CHECK(std::is_same<T, decltype(myClass.getFirst())>::value);
Then I want to use the minimum and maximum value of that type as input. How do I do that?
关于c++ - 如何在 C++ 中将值与模板和 boost 进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55952764/
我是一名优秀的程序员,十分优秀!