Re: [Boost-bugs] [Boost C++ Libraries] #4455: clean up preprocessor/seq/fold_left.hpp

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #4455: clean up preprocessor/seq/fold_left.hpp
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-07-20 16:05:41

#4455: clean up preprocessor/seq/fold_left.hpp
  Reporter: anonymous | Owner: no-maintainer
      Type: Library Submissions | Status: new
 Milestone: Boost 1.44.0 | Component: preprocessor
   Version: Boost 1.44.0 | Severity: Optimization
Resolution: | Keywords:

Comment (by steven_watanabe):

 Replying to [ticket:4455 anonymous]:
> step 1:
> The definition of BOOST_PP_SEQ_FOLD_LEFT entails a call to
 BOOST_PP_AUTO_REC. In short, this call turns out to be completely
 pointless, as it will always return 1 as result, and can be simply
 replaced by this constant.
> This can be seen as follows:
> BOOST_PP_AUTO_REC operates on macros P(n), that
> - take integers from 1 to 256 as paramater;
> - are binary, i.e. yields only 0 or 1 as a result;
> - are monotonely rising, i.e. there is an integer n such that P(i) == 0
 for i < n and == 1 otherwise.
> BOOST_PP_AUTO_SEC is designed to find the 'leap position' where P
 assumes 1 for the first time.
> BOOST_PP_SEQ_FOLD_LEFT_P is such a P(n). Although the replacement of
 BOOST_PP_SEQ_FOLD_LEFT_P looks complex, a closer look at
> {{{
 (nil), 1)
> }}}
> reveals, that this expression, independently of n, will always expand to
 BOOST_PP_NIL, and after some more replacing, BOOST_PP_SEQ_FOLD_LEFT_P
 turns out to be constantly 1. Consequently, BOOST_PP_AUTO_REC, applied to
 this (constant) macro, will yield 1 as a result.

 Nope. BOOST_PP_SEQ_FOLD_LEFT_P expands to 1 iff. **we are not currently
 in an expansion of BOOST_PP_SEQ_FOLD_LEFT_I_ ## n**. If
 BOOST_PP_SEQ_FOLD_LEFT_I_ ## n is being expanded, then it will not be
 expanded again, since recursive calls to a macro are not expanded.
 BOOST_PP_AUTO_REC is used to find the first available index that is not on
 the macro expansion stack. This allows nested calls to
 BOOST_PP_SEQ_FOLD_LEFT. Note that the s parameter to the macro is not the
 index in the sequence. It is the next available index for reentering

Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

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