[test] how to test std::pair with BOOST_TEST
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 #include <boost/test/included/unit_test.hpp> std::pair<uint32_t, uint32_t> v() { return std::make_pair(0, 0); } BOOST_AUTO_TEST_CASE(range) { BOOST_TEST(std::make_pair(0, 0) == v()); } Here's the error message: C:\3rd\boost_1_61_0\boost/test/tools/assertion.hpp(163): error C2678: binary '==': no operator found which takes a left-hand operand of type 'std::pair<int,int>' (or there is no acceptable conversion) C:\3rd\boost_1_61_0\boost/function/function_base.hpp(740): note: could be 'bool boost::operator ==(boost::detail::function::useless_clear_type *,const boost::function_base &)' C:\3rd\boost_1_61_0\boost/function/function_base.hpp(728): note: or 'bool boost::operator ==(const boost::function_base &,boost::detail::function::useless_clear_type *)' C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\exception(329): note: or 'bool std::operator ==(const std::exception_ptr &,const std::exception_ptr &) throw()' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\exception(334): note: or 'bool std::operator ==(std::nullptr_t,const std::exception_ptr &) throw()' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\exception(339): note: or 'bool std::operator ==(const std::exception_ptr &,std::nullptr_t) throw()' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\system_error(365): note: or 'bool std::operator ==(const std::error_code &,const std::error_code &) noexcept' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\system_error(373): note: or 'bool std::operator ==(const std::error_code &,const std::error_condition &) noexcept' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\system_error(381): note: or 'bool std::operator ==(const std::error_condition &,const std::error_code &) noexcept' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\system_error(389): note: or 'bool std::operator ==(const std::error_condition &,const std::error_condition &) noexcept' [found using argument-dependent lookup] C:\3rd\boost_1_61_0\boost/function/function_base.hpp(799): note: or 'bool boost::operator ==<T>(Functor,const boost::function_base &)' with [ T=std::pair<int,int>, Functor=std::pair<int,int> ] C:\3rd\boost_1_61_0\boost/function/function_base.hpp(790): note: or 'bool boost::operator ==<T>(const boost::function_base &,Functor)' with [ T=std::pair<uint32_t,uint32_t>, Functor=std::pair<uint32_t,uint32_t> ] C:\3rd\boost_1_61_0\boost/test/tools/assertion.hpp(163): note: while trying to match the argument list '(std::pair<int,int>, std::pair<uint32_t,uint32_t>)' C:\3rd\boost_1_61_0\boost/test/tools/assertion.hpp(326): note: see reference to class template instantiation 'boost::test_tools::assertion::op::EQ<ValType,T,void>' being compiled with [ ValType=std::pair<int,int>, T=std::pair<uint32_t,uint32_t> ] s.cpp(14): note: see reference to class template instantiation 'boost::test_tools::assertion::binary_expr<ExprType,std::pair<uint32_t,uint32_t>,boost::test_tools::assertion::op::EQ<ValType,T,void>>' being compiled with [ ExprType=boost::test_tools::assertion::value_expr<std::pair<int,int>>, ValType=std::pair<int,int>, T=std::pair<uint32_t,uint32_t> ] C:\3rd\boost_1_61_0\boost/test/tools/assertion.hpp(377): warning C4624: 'boost::test_tools::assertion::binary_expr<ExprType,std::pair<uint32_t,uint32_t>,boost::test_tools::assertion::op::EQ<ValType,T,void>>': destructor was implicitly defined as deleted with [ ExprType=boost::test_tools::assertion::value_expr<std::pair<int,int>>, ValType=std::pair<int,int>, T=std::pair<uint32_t,uint32_t> ]
On May 29, 2016 8:10:12 AM EDT, "Tan, Tom (Shanghai)" <TTan@husky.ca> wrote:
The following snippet does not compile with VS2015 and boost 1.61. What should the correct way to do it? Thanks.
This is not a boost question per se. Besides, the solution is described in the error. Good luck.
// compile with cl.exe /EHSc #define BOOST_TEST_MODULE pair #include <boost/test/included/unit_test.hpp>
std::pair<uint32_t, uint32_t> v() {
return std::make_pair(0, 0);
}
BOOST_AUTO_TEST_CASE(range) { BOOST_TEST(std::make_pair(0, 0) == v()); }
Here's the error message: C:\3rd\boost_1_61_0\boost/test/tools/assertion.hpp(163): error C2678: binary '==': no operator found which takes a left-hand operand of type 'std::pair<int,int>' (or there is no acceptable conversion) C:\3rd\boost_1_61_0\boost/function/function_base.hpp(740): note: could be 'bool boost::operator ==(boost::detail::function::useless_clear_type *,const boost::function_base &)' C:\3rd\boost_1_61_0\boost/function/function_base.hpp(728): note: or 'bool boost::operator ==(const boost::function_base &,boost::detail::function::useless_clear_type *)' C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\exception(329): note: or 'bool std::operator ==(const std::exception_ptr &,const std::exception_ptr &) throw()' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\exception(334): note: or 'bool std::operator ==(std::nullptr_t,const std::exception_ptr &) throw()' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\exception(339): note: or 'bool std::operator ==(const std::exception_ptr &,std::nullptr_t) throw()' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\system_error(365): note: or 'bool std::operator ==(const std::error_code &,const std::error_code &) noexcept' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\system_error(373): note: or 'bool std::operator ==(const std::error_code &,const std::error_condition &) noexcept' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\system_error(381): note: or 'bool std::operator ==(const std::error_condition &,const std::error_code &) noexcept' [found using argument-dependent lookup] C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\system_error(389): note: or 'bool std::operator ==(const std::error_condition &,const std::error_condition &) noexcept' [found using argument-dependent lookup] C:\3rd\boost_1_61_0\boost/function/function_base.hpp(799): note: or 'bool boost::operator ==<T>(Functor,const boost::function_base &)' with [ T=std::pair<int,int>, Functor=std::pair<int,int> ] C:\3rd\boost_1_61_0\boost/function/function_base.hpp(790): note: or 'bool boost::operator ==<T>(const boost::function_base &,Functor)' with [ T=std::pair<uint32_t,uint32_t>, Functor=std::pair<uint32_t,uint32_t> ] C:\3rd\boost_1_61_0\boost/test/tools/assertion.hpp(163): note: while trying to match the argument list '(std::pair<int,int>, std::pair<uint32_t,uint32_t>)' C:\3rd\boost_1_61_0\boost/test/tools/assertion.hpp(326): note: see reference to class template instantiation 'boost::test_tools::assertion::op::EQ<ValType,T,void>' being compiled with [ ValType=std::pair<int,int>, T=std::pair<uint32_t,uint32_t> ] s.cpp(14): note: see reference to class template instantiation 'boost::test_tools::assertion::binary_expr<ExprType,std::pair<uint32_t,uint32_t>,boost::test_tools::assertion::op::EQ<ValType,T,void>>' being compiled with [ ExprType=boost::test_tools::assertion::value_expr<std::pair<int,int>>, ValType=std::pair<int,int>, T=std::pair<uint32_t,uint32_t> ] C:\3rd\boost_1_61_0\boost/test/tools/assertion.hpp(377): warning C4624: 'boost::test_tools::assertion::binary_expr<ExprType,std::pair<uint32_t,uint32_t>,boost::test_tools::assertion::op::EQ<ValType,T,void>>': destructor was implicitly defined as deleted with [ ExprType=boost::test_tools::assertion::value_expr<std::pair<int,int>>, ValType=std::pair<int,int>, T=std::pair<uint32_t,uint32_t> ]
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Sent from my Android device with K-9 Mail. Please excuse my brevity.
On 5/29/2016 8:10 AM, Tan, Tom (Shanghai) wrote:
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
#include <boost/test/included/unit_test.hpp>
std::pair<uint32_t, uint32_t> v()
{
return std::make_pair(0, 0);
}
BOOST_AUTO_TEST_CASE(range)
{
BOOST_TEST(std::make_pair(0, 0) == v());
}
Here’s the error message:
C:\3rd\boost_1_61_0\boost/test/tools/assertion.hpp(163): error C2678: binary '==': no operator found which takes a left-hand operand of type 'std::pair<int,int>' (or there is no acceptable conversion)
std::make_pair(0,0) returns a value with the type std::pair<int,int> whereas v() returns a variable of the type std::pair<uint32_t,uint32_t>. These are different types and there is no equality operator to compare them.
Edward Diener-3 wrote
On 5/29/2016 8:10 AM, Tan, Tom (Shanghai) wrote:
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
#include <boost/test/included/unit_test.hpp>
std::pair<uint32_t, uint32_t> v()
{
return std::make_pair(0, 0);
}
BOOST_AUTO_TEST_CASE(range)
{
BOOST_TEST(std::make_pair(0, 0) == v()); }
std::make_pair(0,0) returns a value with the type std::pair<int,int> whereas v() returns a variable of the type std::pair<uint32_t,uint32_t>. 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... Sent from the Boost - Users mailing list archive at Nabble.com.
On 5/29/2016 10:36 AM, ttan wrote:
Edward Diener-3 wrote
On 5/29/2016 8:10 AM, Tan, Tom (Shanghai) wrote:
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
#include <boost/test/included/unit_test.hpp>
std::pair<uint32_t, uint32_t> v()
{
return std::make_pair(0, 0);
}
BOOST_AUTO_TEST_CASE(range)
{
BOOST_TEST(std::make_pair(0, 0) == v()); }
std::make_pair(0,0) returns a value with the type std::pair<int,int> whereas v() returns a variable of the type std::pair<uint32_t,uint32_t>. 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.
C:\3rd\boost_1_61_0\boost/test/tools/detail/print_helper.hpp(47): error C2338: Type has to implement operator<< to be printable
participants (4)
-
Edward Diener
-
Michael
-
Tan, Tom (Shanghai)
-
ttan