1 # /* ************************************************************************** 2 # * * 3 # * (C) Copyright Paul Mensonides 2002. 4 # * Distributed under the Boost Software License, Version 1.0. (See 5 # * accompanying file LICENSE_1_0.txt or copy at 6 # * http://www.boost.org/LICENSE_1_0.txt) 7 # * * 8 # ************************************************************************** */ 9 # 10 # /* See http://www.boost.org for most recent version. */ 11 # 12 # ifndef BOOST_PREPROCESSOR_ARRAY_REPLACE_HPP 13 # define BOOST_PREPROCESSOR_ARRAY_REPLACE_HPP 14 # 15 # include <boost/preprocessor/config/config.hpp> 16 # 17 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT() 18 # 19 # include <boost/preprocessor/arithmetic/inc.hpp> 20 # include <boost/preprocessor/array/elem.hpp> 21 # include <boost/preprocessor/array/push_back.hpp> 22 # include <boost/preprocessor/comparison/not_equal.hpp> 23 # include <boost/preprocessor/config/config.hpp> 24 # include <boost/preprocessor/control/deduce_d.hpp> 25 # include <boost/preprocessor/control/iif.hpp> 26 # include <boost/preprocessor/control/while.hpp> 27 # include <boost/preprocessor/tuple/elem.hpp> 28 # 29 # /* BOOST_PP_ARRAY_REPLACE */ 30 # 31 # define BOOST_PP_ARRAY_REPLACE(array, i, elem) BOOST_PP_ARRAY_REPLACE_I(BOOST_PP_DEDUCE_D(), array, i, elem) 32 # define BOOST_PP_ARRAY_REPLACE_I(d, array, i, elem) BOOST_PP_ARRAY_REPLACE_D(d, array, i, elem) 33 # 34 # /* BOOST_PP_ARRAY_REPLACE_D */ 35 # 36 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG() 37 # define BOOST_PP_ARRAY_REPLACE_D(d, array, i, elem) BOOST_PP_TUPLE_ELEM(5, 3, BOOST_PP_WHILE_ ## d(BOOST_PP_ARRAY_REPLACE_P, BOOST_PP_ARRAY_REPLACE_O, (0, i, elem, (0, ()), array))) 38 # else 39 # define BOOST_PP_ARRAY_REPLACE_D(d, array, i, elem) BOOST_PP_ARRAY_REPLACE_D_I(d, array, i, elem) 40 # define BOOST_PP_ARRAY_REPLACE_D_I(d, array, i, elem) BOOST_PP_TUPLE_ELEM(5, 3, BOOST_PP_WHILE_ ## d(BOOST_PP_ARRAY_REPLACE_P, BOOST_PP_ARRAY_REPLACE_O, (0, i, elem, (0, ()), array))) 41 # endif 42 # 43 # define BOOST_PP_ARRAY_REPLACE_P(d, state) BOOST_PP_NOT_EQUAL(BOOST_PP_TUPLE_ELEM(5, 0, state), BOOST_PP_ARRAY_SIZE(BOOST_PP_TUPLE_ELEM(5, 4, state))) 44 # 45 # if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT() 46 # define BOOST_PP_ARRAY_REPLACE_O(d, state) BOOST_PP_ARRAY_REPLACE_O_I state 47 # else 48 # define BOOST_PP_ARRAY_REPLACE_O(d, state) BOOST_PP_ARRAY_REPLACE_O_I(BOOST_PP_TUPLE_ELEM(5, 0, state), BOOST_PP_TUPLE_ELEM(5, 1, state), BOOST_PP_TUPLE_ELEM(5, 2, state), BOOST_PP_TUPLE_ELEM(5, 3, state), BOOST_PP_TUPLE_ELEM(5, 4, state)) 49 # endif 50 # 51 # define BOOST_PP_ARRAY_REPLACE_O_I(n, i, elem, res, arr) (BOOST_PP_INC(n), i, elem, BOOST_PP_ARRAY_PUSH_BACK(res, BOOST_PP_IIF(BOOST_PP_NOT_EQUAL(n, i), BOOST_PP_ARRAY_ELEM(n, arr), elem)), arr) 52 # 53 # else 54 # 55 # include <boost/preprocessor/arithmetic/inc.hpp> 56 # include <boost/preprocessor/array/elem.hpp> 57 # include <boost/preprocessor/array/push_back.hpp> 58 # include <boost/preprocessor/comparison/not_equal.hpp> 59 # include <boost/preprocessor/control/deduce_d.hpp> 60 # include <boost/preprocessor/control/iif.hpp> 61 # include <boost/preprocessor/control/while.hpp> 62 # if BOOST_PP_LIMIT_TUPLE == 256 63 # include <boost/preprocessor/logical/not.hpp> 64 # endif 65 # include <boost/preprocessor/tuple/elem.hpp> 66 # 67 # /* BOOST_PP_ARRAY_REPLACE */ 68 # 69 # define BOOST_PP_ARRAY_REPLACE(array, i, elem) BOOST_PP_ARRAY_REPLACE_I(BOOST_PP_DEDUCE_D(), array, i, elem) 70 # define BOOST_PP_ARRAY_REPLACE_I(d, array, i, elem) BOOST_PP_ARRAY_REPLACE_D(d, array, i, elem) 71 # 72 # /* BOOST_PP_ARRAY_REPLACE_D */ 73 # 74 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG() 75 # if BOOST_PP_LIMIT_TUPLE == 256 76 # define BOOST_PP_ARRAY_REPLACE_D(d, array, i, elem) BOOST_PP_ARRAY_REPLACE_ZERO_D(d, array, i, elem, BOOST_PP_NOT(i)) 77 # else 78 # define BOOST_PP_ARRAY_REPLACE_D(d, array, i, elem) BOOST_PP_TUPLE_ELEM(5, 3, BOOST_PP_WHILE_ ## d(BOOST_PP_ARRAY_REPLACE_P, BOOST_PP_ARRAY_REPLACE_O, (0, i, elem, (0, ()), array))) 79 # endif 80 # else 81 # define BOOST_PP_ARRAY_REPLACE_D(d, array, i, elem) BOOST_PP_ARRAY_REPLACE_D_I(d, array, i, elem) 82 # if BOOST_PP_LIMIT_TUPLE == 256 83 # define BOOST_PP_ARRAY_REPLACE_D_I(d, array, i, elem) BOOST_PP_ARRAY_REPLACE_ZERO_D(d, array, i, elem, BOOST_PP_NOT(i)) 84 # else 85 # define BOOST_PP_ARRAY_REPLACE_D_I(d, array, i, elem) BOOST_PP_TUPLE_ELEM(5, 3, BOOST_PP_WHILE_ ## d(BOOST_PP_ARRAY_REPLACE_P, BOOST_PP_ARRAY_REPLACE_O, (0, i, elem, (0, ()), array))) 86 # endif 87 # endif 88 # 89 # if BOOST_PP_LIMIT_TUPLE == 256 90 # define BOOST_PP_ARRAY_REPLACE_ZERO_D(d, array, i, elem, zero) \ 91 BOOST_PP_TUPLE_ELEM(5, 3, BOOST_PP_WHILE_ ## d(BOOST_PP_ARRAY_REPLACE_P, BOOST_PP_ARRAY_REPLACE_O, \ 92 (1, i, elem, BOOST_PP_IIF(zero,(1, (elem)),(1, (BOOST_PP_ARRAY_ELEM(0,array)))), array))) 93 # endif 94 # 95 # define BOOST_PP_ARRAY_REPLACE_P(d, state) BOOST_PP_NOT_EQUAL(BOOST_PP_TUPLE_ELEM(5, 0, state), BOOST_PP_ARRAY_SIZE(BOOST_PP_TUPLE_ELEM(5, 4, state))) 96 # 97 # if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT() 98 # define BOOST_PP_ARRAY_REPLACE_O(d, state) BOOST_PP_ARRAY_REPLACE_O_I state 99 # else 100 # define BOOST_PP_ARRAY_REPLACE_O(d, state) BOOST_PP_ARRAY_REPLACE_O_I(BOOST_PP_TUPLE_ELEM(5, 0, state), BOOST_PP_TUPLE_ELEM(5, 1, state), BOOST_PP_TUPLE_ELEM(5, 2, state), BOOST_PP_TUPLE_ELEM(5, 3, state), BOOST_PP_TUPLE_ELEM(5, 4, state)) 101 # endif 102 # 103 # define BOOST_PP_ARRAY_REPLACE_O_I(n, i, elem, res, arr) (BOOST_PP_INC(n), i, elem, BOOST_PP_ARRAY_PUSH_BACK(res, BOOST_PP_IIF(BOOST_PP_NOT_EQUAL(n, i), BOOST_PP_ARRAY_ELEM(n, arr), elem)), arr) 104 # 105 # endif 106 # 107 # endif 108