1 # /* Copyright (C) 2001 2 # * Housemarque Oy 3 # * http://www.housemarque.com 4 # * 5 # * Distributed under the Boost Software License, Version 1.0. (See 6 # * accompanying file LICENSE_1_0.txt or copy at 7 # * http://www.boost.org/LICENSE_1_0.txt) 8 # */ 9 # 10 # /* Revised by Paul Mensonides (2002) */ 11 # /* Revised by Edward Diener (2020) */ 12 # 13 # /* See http://www.boost.org for most recent version. */ 14 # 15 # ifndef BOOST_PREPROCESSOR_ARITHMETIC_ADD_HPP 16 # define BOOST_PREPROCESSOR_ARITHMETIC_ADD_HPP 17 # 18 # include <boost/preprocessor/config/config.hpp> 19 # 20 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT() 21 # 22 # include <boost/preprocessor/arithmetic/dec.hpp> 23 # include <boost/preprocessor/arithmetic/inc.hpp> 24 # include <boost/preprocessor/control/while.hpp> 25 # include <boost/preprocessor/tuple/elem.hpp> 26 # 27 # /* BOOST_PP_ADD */ 28 # 29 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG() 30 # define BOOST_PP_ADD(x, y) BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_WHILE(BOOST_PP_ADD_P, BOOST_PP_ADD_O, (x, y))) 31 # else 32 # define BOOST_PP_ADD(x, y) BOOST_PP_ADD_I(x, y) 33 # define BOOST_PP_ADD_I(x, y) BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_WHILE(BOOST_PP_ADD_P, BOOST_PP_ADD_O, (x, y))) 34 # endif 35 # 36 # define BOOST_PP_ADD_P(d, xy) BOOST_PP_TUPLE_ELEM(2, 1, xy) 37 # 38 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MWCC() 39 # define BOOST_PP_ADD_O(d, xy) BOOST_PP_ADD_O_I xy 40 # else 41 # define BOOST_PP_ADD_O(d, xy) BOOST_PP_ADD_O_I(BOOST_PP_TUPLE_ELEM(2, 0, xy), BOOST_PP_TUPLE_ELEM(2, 1, xy)) 42 # endif 43 # 44 # define BOOST_PP_ADD_O_I(x, y) (BOOST_PP_INC(x), BOOST_PP_DEC(y)) 45 # 46 # /* BOOST_PP_ADD_D */ 47 # 48 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG() 49 # define BOOST_PP_ADD_D(d, x, y) BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_WHILE_ ## d(BOOST_PP_ADD_P, BOOST_PP_ADD_O, (x, y))) 50 # else 51 # define BOOST_PP_ADD_D(d, x, y) BOOST_PP_ADD_D_I(d, x, y) 52 # define BOOST_PP_ADD_D_I(d, x, y) BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_WHILE_ ## d(BOOST_PP_ADD_P, BOOST_PP_ADD_O, (x, y))) 53 # endif 54 # 55 # else 56 # 57 # include <boost/preprocessor/arithmetic/dec.hpp> 58 # include <boost/preprocessor/arithmetic/inc.hpp> 59 # include <boost/preprocessor/control/iif.hpp> 60 # include <boost/preprocessor/control/while.hpp> 61 # include <boost/preprocessor/facilities/identity.hpp> 62 # include <boost/preprocessor/logical/bitand.hpp> 63 # include <boost/preprocessor/logical/bitor.hpp> 64 # include <boost/preprocessor/logical/bool.hpp> 65 # include <boost/preprocessor/logical/compl.hpp> 66 # include <boost/preprocessor/tuple/elem.hpp> 67 # include <boost/preprocessor/arithmetic/detail/is_maximum_number.hpp> 68 # include <boost/preprocessor/arithmetic/detail/is_minimum_number.hpp> 69 # 70 # /* BOOST_PP_ADD */ 71 # 72 # define BOOST_PP_ADD(x, y) BOOST_PP_IIF(BOOST_PP_BITOR(BOOST_PP_DETAIL_IS_MAXIMUM_NUMBER(y),BOOST_PP_DETAIL_IS_MINIMUM_NUMBER(x)),BOOST_PP_IDENTITY_N(y,2),BOOST_PP_ADD_DO)(x,y) 73 # 74 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG() 75 # define BOOST_PP_ADD_DO(x, y) BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_WHILE(BOOST_PP_ADD_P, BOOST_PP_ADD_O, (x, y))) 76 # else 77 # define BOOST_PP_ADD_DO(x, y) BOOST_PP_ADD_I(x, y) 78 # define BOOST_PP_ADD_I(x, y) BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_WHILE(BOOST_PP_ADD_P, BOOST_PP_ADD_O, (x, y))) 79 # endif 80 # 81 # define BOOST_PP_ADD_P(d, xy) BOOST_PP_BITAND(BOOST_PP_BOOL(BOOST_PP_TUPLE_ELEM(2, 1, xy)),BOOST_PP_COMPL(BOOST_PP_DETAIL_IS_MAXIMUM_NUMBER(BOOST_PP_TUPLE_ELEM(2, 0, xy)))) 82 # 83 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MWCC() 84 # define BOOST_PP_ADD_O(d, xy) BOOST_PP_ADD_O_I xy 85 # else 86 # define BOOST_PP_ADD_O(d, xy) BOOST_PP_ADD_O_I(BOOST_PP_TUPLE_ELEM(2, 0, xy), BOOST_PP_TUPLE_ELEM(2, 1, xy)) 87 # endif 88 # 89 # define BOOST_PP_ADD_O_I(x, y) (BOOST_PP_INC(x), BOOST_PP_DEC(y)) 90 # 91 # /* BOOST_PP_ADD_D */ 92 # 93 # define BOOST_PP_ADD_D(d, x, y) BOOST_PP_IIF(BOOST_PP_BITOR(BOOST_PP_DETAIL_IS_MAXIMUM_NUMBER(y),BOOST_PP_DETAIL_IS_MINIMUM_NUMBER(x)),BOOST_PP_IDENTITY_N(y,3),BOOST_PP_ADD_DO_D)(d,x,y) 94 # 95 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG() 96 # define BOOST_PP_ADD_DO_D(d, x, y) BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_WHILE_ ## d(BOOST_PP_ADD_P, BOOST_PP_ADD_O, (x, y))) 97 # else 98 # define BOOST_PP_ADD_DO_D(d, x, y) BOOST_PP_ADD_D_I(d, x, y) 99 # define BOOST_PP_ADD_D_I(d, x, y) BOOST_PP_TUPLE_ELEM(2, 0, BOOST_PP_WHILE_ ## d(BOOST_PP_ADD_P, BOOST_PP_ADD_O, (x, y))) 100 # endif 101 # 102 # endif 103 # 104 # endif 105