[Boost-bugs] [Boost C++ Libraries] #12876: BOOST_CHECK_EQUAL fail for vector<int> with operator<< for vector<T>

Subject: [Boost-bugs] [Boost C++ Libraries] #12876: BOOST_CHECK_EQUAL fail for vector<int> with operator<< for vector<T>
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-03-01 02:39:00


#12876: BOOST_CHECK_EQUAL fail for vector<int> with operator<< for vector<T>
------------------------------+---------------------
 Reporter: 401819174@… | Owner: rogeeff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: test
  Version: Boost 1.61.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------
 #include <boost/test/unit_test.hpp>
 #include <iostream>
 #include <ostream>
 #include <vector>

 using namespace std;

 class PrintClass
 {

 };
 bool operator== (const PrintClass &l, const PrintClass &r)
 {
         std::cout << "value compare" << std::endl;
         return false;
 }


 template <typename T>
 std::ostream & operator<< (std::ostream & os, std::vector<T> const &v)
 {
         os << "has " << &v;
         return os;
 }

 template <typename T>
 bool operator== (const std::vector<T> &l, const std::vector<T> &r)
 {
         std::cout << "const vector compare" << std::endl;
         return false;
 }


 BOOST_AUTO_TEST_CASE(test_print_vector_int)
 {
         const std::vector<int> a{1};
         const std::vector<int> b{2};

         std::cout << a << std::endl; // work
         BOOST_CHECK_EQUAL(a, b); // don't work.
         // error: static assertion failed: Type has to implement
 operator<< to be printable

         //std::cout << boost::has_left_shift<std::ostream,
 vector<int>>::value << endl;

         // use user define class is ok
         std::vector<PrintClass> c{PrintClass()};
         std::vector<PrintClass> d{PrintClass()};
         std::cout << c << std::endl; // work
         BOOST_CHECK_EQUAL(c, d); // work
 }

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12876>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-03-01 02:43:25 UTC