Re: [Boost-bugs] [Boost C++ Libraries] #4400: BOOST_PP_SEQ_REPLACE fails in corner cases

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #4400: BOOST_PP_SEQ_REPLACE fails in corner cases
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-07-03 11:35:58


#4400: BOOST_PP_SEQ_REPLACE fails in corner cases
-------------------------------------------+--------------------------------
  Reporter: Wolf Lammen <ookami1@…> | Owner: no-maintainer
      Type: Bugs | Status: new
 Milestone: Boost 1.44.0 | Component: preprocessor
   Version: Boost 1.44.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------------------+--------------------------------

Comment (by Wolf Lammen <ookami1@…>):

 After fiddling with the code a bit, I suggest, as a safe and quick fix, a
 replacement of

 boost/preprocessor/seq/replace.hpp


 by


 {{{
 ******
 # *
 *
 # * (C) Copyright Paul Mensonides 2002.
 # * Distributed under the Boost Software License, Version 1.0. (See
 # * accompanying file LICENSE_1_0.txt or copy at
 # * http://www.boost.org/LICENSE_1_0.txt)
 # *
 *
 #
 **************************************************************************
 */
 #
 # /* See http://www.boost.org for most recent version. */
 #
 # ifndef BOOST_PREPROCESSOR_SEQ_REPLACE_HPP
 # define BOOST_PREPROCESSOR_SEQ_REPLACE_HPP
 #
 # include <boost/preprocessor/arithmetic/inc.hpp>
 # include <boost/preprocessor/config/config.hpp>
 # include <boost/preprocessor/seq/first_n.hpp>
 #
 # /* BOOST_PP_SEQ_REPLACE */
 #
 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG()
 # define BOOST_PP_SEQ_REPLACE(seq, i, elem) BOOST_PP_SEQ_FIRST_N(i,
 seq) (elem) BOOST_PP_SEQ_REST_NP1(i, seq)
 # define BOOST_PP_SEQ_REST_NP1(n, seq) BOOST_PP_TUPLE_ELEM(2, 1,
 BOOST_PP_SEQ_SPLIT(BOOST_PP_INC(n), seq BOOST_PP_EMPTY))()
 # else
 # define BOOST_PP_SEQ_REPLACE(seq, i, elem) BOOST_PP_SEQ_REPLACE_I(seq,
 i, elem)
 # define BOOST_PP_SEQ_REPLACE_I(seq, i, elem) BOOST_PP_SEQ_FIRST_N(i,
 seq) (elem) BOOST_PP_SEQ_REST_NP1(i, seq)
 # define BOOST_PP_SEQ_REST_NP1(i, seq) BOOST_PP_SEQ_REST_NP1_I(n, seq)
 # define BOOST_PP_SEQ_REST_NP1_I(n, seq) BOOST_PP_TUPLE_ELEM(2, 1,
 BOOST_PP_SEQ_SPLIT(BOOST_PP_INC(n), seq BOOST_PP_EMPTY))()
 # endif
 #
 # endif

 }}}


 The idea behind this rework is to use a dedicated version of
 BOOST_PP_REST_N, called BOOST_PP_REST_NP1 here (NP1 stands for N + 1), and
 not rely on undocumented behavor of BOOST_PP_REST_N any more.


 Since the former code called BOOST_PP_REST_N with its first argument at
 least 1, the replacement code can be simplified a little. The sentinel
 element (nil) in the replacement code of BOOST_PP_REST_N is needed to
 allows for 0 as n, which is not used here, so (nil) can be eliminated. As
 a consequence, arithmetic ssaturation can be avoided as well.


 Cheers


 Wolf Lammen

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4400#comment:1>
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:03 UTC