Discussion:
[Boost-users] [test] how to test std::pair with BOOST_TEST
ttan
2016-05-29 14:36:29 UTC
Permalink
The following snippet does not compile with VS2015 and boost 1.61. What
should the correct way to do it? Thanks.
// compile with cl.exe /EHSc
#define BOOST_TEST_MODULE pair
{
return std::make_pair(0, 0);
}
BOOST_AUTO_TEST_CASE(range)
{
BOOST_TEST(std::make_pair(0, 0) == v());
}
whereas v() returns a variable of the type
These are different types and there is no equality operator to compare
them.
Thanks, my code above is misleading. Iwas actually intended to illustrate
the support of std::pair by BOOST_TEST, like below

BOOST_AUTO_TEST_CASE(range)
{
(std::make_pair(uint32_t(0), uint32_t(0)) == v()); // this is OK
BOOST_TEST(std::make_pair(uint32_t(0), uint32_t(0)) == v()); // this not
}

judging from the error, operator << is not support by std::pair in
boost.test. What is the best way, I mean where, to add the support?

C:\3rd\boost_1_61_0\boost/test/tools/detail/print_helper.hpp(47): error
C2338: Type has to implement operator<< to be printable



--
View this message in context: http://boost.2283326.n4.nabble.com/test-how-to-test-std-pair-with-BOOST-TEST-tp4686592p4686595.html
Sent from the Boost - Users mailing list archive at Nabble.com.
Edward Diener
2016-05-29 18:39:23 UTC
Permalink
Post by ttan
The following snippet does not compile with VS2015 and boost 1.61. What
should the correct way to do it? Thanks.
// compile with cl.exe /EHSc
#define BOOST_TEST_MODULE pair
{
return std::make_pair(0, 0);
}
BOOST_AUTO_TEST_CASE(range)
{
BOOST_TEST(std::make_pair(0, 0) == v());
}
whereas v() returns a variable of the type
These are different types and there is no equality operator to compare
them.
Thanks, my code above is misleading. Iwas actually intended to illustrate
the support of std::pair by BOOST_TEST, like below
BOOST_AUTO_TEST_CASE(range)
{
(std::make_pair(uint32_t(0), uint32_t(0)) == v()); // this is OK
BOOST_TEST(std::make_pair(uint32_t(0), uint32_t(0)) == v()); // this not
}
judging from the error, operator << is not support by std::pair in
boost.test. What is the best way, I mean where, to add the support?
Something like:

#include <ostream>

template<typename T>
std::ostream & operator << (std::ostream & os,const std::pair<T,T> & pr)
{
os << pr.first << ' ' << pr.second;
}

Look up "C++ writing output operator" on the Internet.
Post by ttan
C:\3rd\boost_1_61_0\boost/test/tools/detail/print_helper.hpp(47): error
C2338: Type has to implement operator<< to be printable
Continue reading on narkive:
Loading...