diff --git a/doc/headers/facilities/identity.html b/doc/headers/facilities/identity.html index 9478e09..af9034b 100644 --- a/doc/headers/facilities/identity.html +++ b/doc/headers/facilities/identity.html @@ -5,7 +5,7 @@
- The facilities/identity.hpp header defines a utility macro to use with BOOST_PP_IF and BOOST_PP_IIF. + The facilities/identity.hpp header defines utility macros to use with BOOST_PP_IF and BOOST_PP_IIF.

Usage

@@ -14,11 +14,13 @@

Contents


© Copyright Housemarque Oy 2002
© Copyright Paul Mensonides 2002 +
© Copyright Edward Diener 2015

Distributed under the Boost Software License, Version 1.0. (See diff --git a/doc/headers/tuple/enum.html b/doc/headers/tuple/enum.html index 86f0c7b..5f9a11d 100644 --- a/doc/headers/tuple/enum.html +++ b/doc/headers/tuple/enum.html @@ -2,7 +2,7 @@ tuple/enum.hpp

- The tuple/enum.hpp header defines a macro to onvert a tuple to its comma-separated elements. + The tuple/enum.hpp header defines a macro to convert a tuple to its comma-separated elements.

Usage

diff --git a/doc/ref.html b/doc/ref.html index 4d2081f..102325a 100644 --- a/doc/ref.html +++ b/doc/ref.html @@ -99,6 +99,7 @@
  • GREATER_EQUAL_D
  • IDENTITY
  • +
  • IDENTITY_N
  • IF
  • IIF
  • INC
  • diff --git a/doc/ref/identity_n.html b/doc/ref/identity_n.html new file mode 100644 index 0000000..0c01dd3 --- /dev/null +++ b/doc/ref/identity_n.html @@ -0,0 +1,58 @@ + + + BOOST_PP_IDENTITY_N + + + +
    + The BOOST_PP_IDENTITY_N macro expands to its first argument when invoked. +
    +

    Usage

    +
    + BOOST_PP_IDENTITY_N(item,n)(n-arguments) +
    +

    Arguments

    +
    +
    item
    +
    + The result of the expansion. +
    +
    n
    +
    + The number of arguments when invoked. +
    +
    +

    Remarks

    +
    + This macro is designed to be used with BOOST_PP_IF and BOOST_PP_IIF when only one of the clauses needs to be invoked. +
    +

    See Also

    + +

    Requirements

    +
    + Header:  <boost/preprocessor/facilities/identity.hpp> +
    +

    Sample Code

    +
    +#include <boost/preprocessor/control/if.hpp>
    +#include <boost/preprocessor/facilities/identity.hpp>
    +
    +#define MACRO_CAT(y,z) y ## z
    +#define MACRO(n) BOOST_PP_IF(n, BOOST_PP_IDENTITY_N(x,2), MACRO_CAT)(a,b)
    +
    +MACRO(0) // expands to ab
    +MACRO(1) // expands to x
    +
    +
    +
    © Copyright Edward Diener 2015
    +
    +

    Distributed under the Boost Software License, Version 1.0. (See + accompanying file LICENSE_1_0.txt or + copy at www.boost.org/LICENSE_1_0.txt)

    +
    + + diff --git a/include/boost/preprocessor/facilities/identity.hpp b/include/boost/preprocessor/facilities/identity.hpp index 13ec4ca..8a7834d 100644 --- a/include/boost/preprocessor/facilities/identity.hpp +++ b/include/boost/preprocessor/facilities/identity.hpp @@ -8,6 +8,7 @@ # */ # # /* Revised by Paul Mensonides (2002) */ +# /* Revised by Edward Diener (2015) */ # # /* See http://www.boost.org for most recent version. */ # @@ -15,9 +16,12 @@ # define BOOST_PREPROCESSOR_FACILITIES_IDENTITY_HPP # # include +# include # # /* BOOST_PP_IDENTITY */ # # define BOOST_PP_IDENTITY(item) item BOOST_PP_EMPTY # +# define BOOST_PP_IDENTITY_N(item,n) item BOOST_PP_TUPLE_EAT_N(n) +# # endif diff --git a/include/boost/preprocessor/tuple/eat.hpp b/include/boost/preprocessor/tuple/eat.hpp index 708015e..7e8a100 100644 --- a/include/boost/preprocessor/tuple/eat.hpp +++ b/include/boost/preprocessor/tuple/eat.hpp @@ -8,7 +8,7 @@ # */ # # /* Revised by Paul Mensonides (2002-2011) */ -# /* Revised by Edward Diener (2011) */ +# /* Revised by Edward Diener (2011,2015) */ # # /* See http://www.boost.org for most recent version. */ # @@ -38,6 +38,15 @@ # endif # define BOOST_PP_TUPLE_EAT_I(size) BOOST_PP_TUPLE_EAT_ ## size # endif +# +# if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_MWCC() +# define BOOST_PP_TUPLE_EAT_N(size) BOOST_PP_TUPLE_EAT_N_I(size) +# else +# define BOOST_PP_TUPLE_EAT_N(size) BOOST_PP_TUPLE_EAT_N_OO((size)) +# define BOOST_PP_TUPLE_EAT_N_OO(par) BOOST_PP_TUPLE_EAT_N_I ## par +# endif +# define BOOST_PP_TUPLE_EAT_N_I(size) BOOST_PP_TUPLE_EAT_ ## size +# # define BOOST_PP_TUPLE_EAT_1(e0) # define BOOST_PP_TUPLE_EAT_2(e0, e1) # define BOOST_PP_TUPLE_EAT_3(e0, e1, e2) diff --git a/test/facilities.cxx b/test/facilities.cxx index f81b6a0..772c2cf 100644 --- a/test/facilities.cxx +++ b/test/facilities.cxx @@ -26,6 +26,7 @@ BEGIN BOOST_PP_APPLY((BOOST_PP_EMPTY))() 0 == 0 END BEGIN BOOST_PP_EXPAND(MACRO ARGS) == 1 END BEGIN BOOST_PP_IDENTITY(1)() == 1 END +BEGIN BOOST_PP_IDENTITY_N(36,10)(0,1,2,3,4,5,6,7,8,9) == 36 END BEGIN BOOST_PP_CAT(BOOST_PP_INTERCEPT, 2) 1 == 1 END