Re: [Boost-bugs] [Boost C++ Libraries] #849: boost::format and operator priority rule

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #849: boost::format and operator priority rule
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2007-08-18 14:34:42


#849: boost::format and operator priority rule
----------------------+-----------------------------------------------------
  Reporter: nobody | Owner: samuel_krempp
      Type: Bugs | Status: closed
 Milestone: | Component: format
   Version: None | Severity: Problem
Resolution: invalid | Keywords:
----------------------+-----------------------------------------------------
Changes (by grafik):

  * component: None => format

Old description:

> {{{
> boost::format uses operator % to "feed" a string to a formatter, as in
>
> cout<<format("Choose %1% of %2%") % 5 % 37; //writes "Choose 5 of 37"
>
> This leads to a compile-time error when arithmetic operations are used
> without parenthesizing, e.g.
>
> cout<<format("Choose %1% of %2%") % total-remaining+1 % total; //WRONG,
> tries to apply operator - to a formatter
>
> because operator % has a higher priority than operator - .
>
> This is indeed quite a common case; I suggest that operator % be replaced
> with an operator with lower priority, such as << . I can't figure out why
> operator % was chosen, is there a reason to use it?
>
> Thanks,
>
> --federico poloni
> }}}

New description:

 {{{
 boost::format uses operator % to "feed" a string to a formatter, as in

 cout<<format("Choose %1% of %2%") % 5 % 37; //writes "Choose 5 of 37"

 This leads to a compile-time error when arithmetic operations are used
 without parenthesizing, e.g.

 cout<<format("Choose %1% of %2%") % total-remaining+1 % total; //WRONG,
 tries to apply operator - to a formatter

 because operator % has a higher priority than operator - .

 This is indeed quite a common case; I suggest that operator % be replaced
 with an operator with lower priority, such as << . I can't figure out why
 operator % was chosen, is there a reason to use it?

 Thanks,

 --federico poloni
 }}}

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/849#comment:6>
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:49:56 UTC