Overload Operator << Boost Log

inline std::ostream& operator<<(std::ostream& p, const std::vector<unsigned int>& vector){
  p << "[ ";
  for(auto i:vector){
    p << " "<< i << " ,";
  }
  p<< "]";
  return p;
}

#define LOG_DEBUG_MESSAGE BOOST_LOG_SEV(my_logger::get(), debug)


std::vector<unsigned int> test {1, 2, 3};
LOG_DEBUG_MESSAGE << "test "<< test;
std::cout << test  << std::endl;

Hello,

I overloaded my <operator for std :: vector. When I use std :: cout, it works fine, but with boost log I get the following error:

boost / log / utility / formatting_ostream.hpp: 710: 19: error: cannot communicate "Promotion :: login :: v2_mt_posix :: basic_formatting_ostream :: ostream_type {aka std :: basic_ostream} 'lvalue to' std :: basic_ostream && '' strm.stream () <value;

/opt/gcc.4.9.1/include/++/4.9.1/ostream: 602: 5: note: 1 'std:: basic_ostream < _CharT, _Traits > & std:: operator < (std:: basic_ostream < _CharT, _Traits & &, const _Tp &) [ _CharT = char; _Traits = std:: char_traits; _Tp = std::vector]       < (basic_ostream < _CharT, _Traits > & __os, const _Tp & __x)

, boost . < ? . , . - , ?

+4
1

'boost:: log:: basic_formatting_ostream std:: ostream.

< < std::vector boost:: log:: formatting_ostream & .

:

inline boost::log::formatting_ostream& operator<<(boost::log::formatting_ostream& p,  std::vector<int>& vector)
{
        p << "[ ";
        for(auto i:vector){
            p << " "<< i << " ,";
        }
        p<< "]";
        return p;
}
+4

All Articles