1

In one of my rules a have qi::locals<> with stl container as parameter. When I compile my program without BOOST_SPIRIT_QI_DEBUG, everything works fine. But when I turn BOOST_SPIRIT_QI_DEBUG on, program can't be compiled because of missing operator <<.

Simplified snippet:

typedef std::list< int > TlstValues;

template <typename Iterator, typename Skipper>
struct G_test : qi::grammar<Iterator, Skipper>
{
  ...
  G_test() : G_test::base_type(rule_test)
  {
    ...
    BOOST_SPIRIT_DEBUG_NODE(rule_test);
  }

  qi::rule<Iterator, qi::locals<TlstValues>, Skipper> rule_test;
}

error:

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'TlstExpressionItems' (or there is no acceptable conversion)

I tried to define streaming operator for TlstValues but without effect. Error was still the same. My operator definition:

std::ostream& operator << (std::ostream& os, TlstValues & z)
{
return os;
} 

Can someone please advise me how to define required operator to make BOOST_SPIRIT_DEBUG work?

Thanks and regards Rick

1 Answer 1

2

The simplest way to force ADL to find your streaming operator is to put it into the namespace std:

namespace std
{
    std::ostream& operator<< (std::ostream& os, TlstValues& z)
    {
        // do your stuff here
        return os;
    } 
}

Yes, I know, this is formally not allowed. However, from a pragmatic standpoint it's still the easiest way.

The Standards conformant solution is to specialize the Spirit customization point print_attribute_debug for your attribute type:

// your specialization needs to be in namespace boost::spirit::traits
namespace boost { namespace spirit { namespace traits
{
    template <typename Out>
    struct print_attribute_debug<Out, TlstValues>
    {
        static void call(Out& out, TlstValues const& val)
        {
            // do your output here; Out is a std::ostream
        }
    };
}}}
1
  • Thanks! I tried a solution with std namespace and it works. Thank you.
    – Rick
    Mar 13, 2011 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.