Re: [Boost-bugs] [Boost C++ Libraries] #6126: Signed integer members of Boost.Fusion adapted ADTs are not output correctly with Boost.Spirit.Karma rules

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6126: Signed integer members of Boost.Fusion adapted ADTs are not output correctly with Boost.Spirit.Karma rules
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-02-08 14:27:33


#6126: Signed integer members of Boost.Fusion adapted ADTs are not output
correctly with Boost.Spirit.Karma rules
-------------------------------+--------------------------------------------
  Reporter: t0rt1e@… | Owner: hkaiser
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: spirit
   Version: Boost 1.48.0 | Severity: Regression
Resolution: | Keywords: patch proposed, Boost.Spirit.Karma, Boost.Fusion, BOOST_FUSION_ADAPT_CLASS, BOOST_FUSION_ADAPT_ADT, short, int, long
-------------------------------+--------------------------------------------

Comment (by t0rt1e@…):

> Replying to [comment:13 bugs@…]:
 [snip]
> For the OP, I guess the best way to fix it would be to make the
 accessors return (const) references: (see attached)
>
> struct XR
> {
> short x;
>
> explicit XR(short num = 0) : x(num) {}
> const short& getx() const { return x; }
> short& getx() { return x; }
> void setx(short v) { x = v; }
> };
>
> BOOST_FUSION_ADAPT_ADT(XR, (short&, const short&, obj.getx(),
 obj.setx(val)))
>
> This also removed all the other valgrind messages that were previously
 unaccounted for.

 Without any alternative, I went through the pain to reimplement
 {{{boost::rational<long>}}} for my project so that its getters return
 {{{const long&}}}. For some reasons that I don't fully understand, the
 with {{{BOOST_FUSION_ADAPT_ADT()}}} adapted class showed still the same
 wrong output when used in the Karma rules. I used:
 {{{
 BOOST_FUSION_ADAPT_ADT(
   bufilt::rational,
   (const long&, const long&, obj.numerator(), /**/)
   (const long&, const long&, obj.denominator(), /**/)
 )
 }}}
 Then, I tried to use {{{BOOST_FUSION_ADAPT_STRUCT()}}} in the following
 way:
 {{{
 BOOST_FUSION_ADAPT_STRUCT(
   bufilt::rational,
   (const long&, numerator())
   (const long&, denominator())
 )
 }}}
 after remembering having seen a post from someone with a similar problem
 on the Boost or Spirit mailing list, for which this did the trick. This
 surprisingly worked! (I just need read access to the struct members for
 use in the Karma rules.)

 So this resolves my urgent problem, but the solution remains a hack that I
 would like to get rid off again.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6126#comment:20>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:08 UTC