Boost logo

Boost Users :

Subject: [Boost-users] fusion io problem
From: Olaf Peter (ope-devel_at_[hidden])
Date: 2013-05-05 02:03:41


Hello,

I run into the problem to provide ostream operator<< support for
spirit's debug facility and for lazyness using fusion's io support:

---8<---
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/include/io.hpp>
#include <iostream>

namespace fusion = boost::fusion;

namespace client {

     struct point {
             int x,y;
     };

     template<typename CharT>
     std::basic_ostream<CharT>& operator<<(std::basic_ostream<CharT>&
os, point const& p) {
         os << p;
         return os;
     }

     struct arc {
         int radius;
         point begin;
         point end;
     };

     template<typename CharT>
     std::basic_ostream<CharT>& operator<<(std::basic_ostream<CharT>&
os, arc const& a) {
         os << a;
         return os;
     }
}

BOOST_FUSION_ADAPT_STRUCT(
      client::point,
     (int, x)
     (int, y)
)

BOOST_FUSION_ADAPT_STRUCT(
      client::arc,
     (int, radius)
     (client::point, begin)
     (client::point, end)
)

int main()
{
     client::arc arc;
     std::cout << arc << '\n';
}

--->8---

This program crashs, I would assume operator<<(..., arc) calls infinity
recursive fusion's operator<< or similar - that's what I would interpret
from gdb's backtrace.

How to prevent this? I don't like to investigate much effort of
formatting to supporting spirit's debug support and conventional
debugging by tracing the selective printed output (like printf
debugging) since there is support for formatted output of fusion sequences.

Thanks,
Olaf


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net