Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:43:28

0001 // Copyright Cromwell D. Enage 2013.
0002 // Distributed under the Boost Software License, Version 1.0.
0003 // (See accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_PARAMETER_AUX_PREPROCESSOR_INC_BINARY_SEQ_HPP
0007 #define BOOST_PARAMETER_AUX_PREPROCESSOR_INC_BINARY_SEQ_HPP
0008 
0009 #include <boost/preprocessor/seq/push_back.hpp>
0010 
0011 // This macro keeps the rest of the sequence if carry == 0.
0012 #define BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ_0(seq, element) \
0013     (BOOST_PP_SEQ_PUSH_BACK(seq, element), 0)
0014 /**/
0015 
0016 #include <boost/preprocessor/control/iif.hpp>
0017 
0018 // This macro updates the rest of the sequence if carry == 1.
0019 #define BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ_1(seq, element) \
0020     (BOOST_PP_SEQ_PUSH_BACK(seq, BOOST_PP_IIF(element, 0, 1)), element)
0021 /**/
0022 
0023 #include <boost/preprocessor/tuple/elem.hpp>
0024 #include <boost/preprocessor/cat.hpp>
0025 
0026 // This macro maintains a tuple (seq, carry), where seq is the intermediate
0027 // result and carry is a flag that will unset upon finding an element == 0.
0028 #define BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ_OP(s, result_tuple, element) \
0029     BOOST_PP_CAT( \
0030         BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ_ \
0031       , BOOST_PP_TUPLE_ELEM(2, 1, result_tuple) \
0032     )(BOOST_PP_TUPLE_ELEM(2, 0, result_tuple), element)
0033 /**/
0034 
0035 // This macro keeps the sequence at its original length if carry == 0.
0036 #define BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ_IMPL_0(seq) seq
0037 /**/
0038 
0039 // This macro appends a zero to seq if carry == 1.
0040 #define BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ_IMPL_1(seq) \
0041     BOOST_PP_SEQ_PUSH_BACK(seq, 0)
0042 /**/
0043 
0044 // This macro takes in the tuple (seq, carry), with carry indicating whether
0045 // or not seq originally contained all 1s.  If so, then seq now contains all
0046 // 0s, and this macro pushes an extra 0 before expanding to the new sequence.
0047 // Otherwise, this macro expands to seq as is.
0048 #define BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ_IMPL(seq_and_carry) \
0049     BOOST_PP_CAT( \
0050         BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ_IMPL_ \
0051       , BOOST_PP_TUPLE_ELEM(2, 1, seq_and_carry) \
0052     )(BOOST_PP_TUPLE_ELEM(2, 0, seq_and_carry))
0053 /**/
0054 
0055 #include <boost/preprocessor/seq/seq.hpp>
0056 #include <boost/preprocessor/seq/fold_left.hpp>
0057 
0058 // This macro treats the specified sequence of 1s and 0s like a binary number
0059 // in reverse and expands to a sequence representing the next value up.
0060 // However, if the input sequence contains all 1s, then the output sequence
0061 // will contain one more element but all 0s.
0062 //
0063 // Examples:
0064 // seq = (1)(0)(1)(0) --> return (0)(1)(1)(0)
0065 // seq = (1)(1)(1)(0) --> return (0)(0)(0)(1)
0066 // seq = (1)(1)(1)(1) --> return (0)(0)(0)(0)(0)
0067 #define BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ(seq) \
0068     BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ_IMPL( \
0069         BOOST_PP_SEQ_FOLD_LEFT( \
0070             BOOST_PARAMETER_AUX_PP_INC_BINARY_SEQ_OP \
0071           , (BOOST_PP_SEQ_NIL, 1) \
0072           , seq \
0073         ) \
0074     )
0075 /**/
0076 
0077 #endif  // include guard
0078