There is this code:
#include "gmock/gmock.h"
#include <boost/variant.hpp>
typedef boost::variant<std::vector<unsigned char>, std::vector<int>> CustomVariant;
// some overloads which don't work
std::ostream& operator<<(
std::ostream& stream,
const boost::variant<std::vector<unsigned char>>&)
{ return stream; }
std::ostream& operator<<(
std::ostream& stream,
const boost::variant<std::vector<int>>&)
{ return stream; }
std::ostream& operator<<(
std::ostream& stream,
const std::vector<unsigned char>&)
{ return stream; }
std::ostream& operator<<(
std::ostream& stream,
const std::vector<int>&)
{ return stream; }
class MyClass
{
MOCK_METHOD1(fun, bool(std::vector<CustomVariant> v));
};
int main()
{
MyClass a;
return 0;
}
There are two errors:
/usr/include/boost/variant/detail/variant_io.hpp:64:14: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘const std::vector<unsigned char>’)
out_ << operand;
/usr/include/boost/variant/detail/variant_io.hpp:64:14: error: cannot bind ‘std::basic_ostream<char>’ lvalue to ‘std::basic_ostream<char>&&’
out_ << operand;
It complains that there is not defined operator<<
for types std::basic_ostream<char>
and const std::vector<unsigned char>
, although it seems that it's defined. I tried some overloads but none of them worked. How to properly make this code to compile?
Compiling on g++ 6.3:
g++ main.cpp -lgmock -o main -L ./googletest-release-1.8.0/googlemock -pthread