Question

I am trying to create Google Mock object for some interface class which uses boost::variant

#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <boost/variant.hpp>
#include <vector>

typedef std::vector<int> VectorOfInt;
typedef boost::variant<VectorOfInt> VariantOfVector;

class InterfaceClass
{
public:
     virtual ~InterfaceClass() {}
     virtual void SetSome( const VariantOfVector& ) = 0;
     virtual const VariantOfVector& GetSome() const = 0;
};

class MockInterfaceClass
{
public:
     MOCK_METHOD1( SetSome, void( const VariantOfVector& ) );
     MOCK_CONST_METHOD0( GetSome, const VariantOfVector&() );
};

When I compile it with

g++ mytest.cpp -o mytest

i get

/usr/include/boost/variant/detail/variant_io.hpp:64: error: no match for ‘operator<<’ in ‘((const boost::detail::variant::printer > >*)this)->boost::detail::variant::printer > >::out_ << operand’

Does boost::variant work with std::vector? It seems boost::variant works with any type I define but std:vector. Why?

Boost version - 1.45 g++ version - 4.4.5

Was it helpful?

Solution

It seems that the mock attempts to apply operator << to your variant. You have to define operator << for its contents, i.e. for std::vector template.

OTHER TIPS

As Igor R. answered, you need to add operator << (without namespace) like this:

std::ostream& operator <<(std::ostream& out, VariantOfVector const& rhs)
{
    //Print or apply your visitor to **rhs**
    return out;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top