From 70e775452ace77c19506282d84be29eade10b636 Mon Sep 17 00:00:00 2001 From: Edward Diener Date: Sat, 3 May 2014 02:15:47 -0400 Subject: [PATCH] Added remove_parens and tests. --- include/boost/preprocessor/punctuation.hpp | 1 + .../punctuation/remove_parens.hpp | 39 +++++++++++++++++++ test/punctuation.cxx | 12 ++++++ 3 files changed, 52 insertions(+) create mode 100644 include/boost/preprocessor/punctuation/remove_parens.hpp diff --git a/include/boost/preprocessor/punctuation.hpp b/include/boost/preprocessor/punctuation.hpp index a96bbff..56dd064 100644 --- a/include/boost/preprocessor/punctuation.hpp +++ b/include/boost/preprocessor/punctuation.hpp @@ -17,5 +17,6 @@ # include # include # include +# include # # endif diff --git a/include/boost/preprocessor/punctuation/remove_parens.hpp b/include/boost/preprocessor/punctuation/remove_parens.hpp new file mode 100644 index 0000000..4700936 --- /dev/null +++ b/include/boost/preprocessor/punctuation/remove_parens.hpp @@ -0,0 +1,39 @@ +# /* ************************************************************************** +# * * +# * (C) Copyright Edward Diener 2014. +# * 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_REMOVE_PARENS_HPP +#define BOOST_PREPROCESSOR_REMOVE_PARENS_HPP + +#include + +#if BOOST_PP_VARIADICS + +#include +#include +#include +#include + +#define BOOST_PP_REMOVE_PARENS(param) \ + BOOST_PP_IIF \ + ( \ + BOOST_PP_IS_BEGIN_PARENS(param), \ + BOOST_PP_REMOVE_PARENS_DO, \ + BOOST_PP_IDENTITY \ + ) \ + (param)() \ +/**/ + +#define BOOST_PP_REMOVE_PARENS_DO(param) \ + BOOST_PP_IDENTITY(BOOST_PP_TUPLE_ENUM(param)) \ +/**/ + +#endif /* BOOST_PP_VARIADICS */ +#endif /* BOOST_PREPROCESSOR_REMOVE_PARENS_HPP */ diff --git a/test/punctuation.cxx b/test/punctuation.cxx index 3eb364b..8e60e9a 100644 --- a/test/punctuation.cxx +++ b/test/punctuation.cxx @@ -23,6 +23,11 @@ # define A_SEQ (r)($)(#) # define AN_ARRAY (4,(5,7,f,x)) # define A_LIST (e,(g,(&,BOOST_PP_NIL))) +# define DATA (5 + 3) * 4 +# define DATA2 4 * (5 + 3) +# define DATA3 4 * (5 + 3) * (2 + 1) +# define DATA4 (5 + 3) * (2 + 1) * 4 + // is_begin_parens @@ -39,4 +44,11 @@ BEGIN BOOST_PP_IS_BEGIN_PARENS(AN_ARRAY) == 1 END BEGIN BOOST_PP_IS_BEGIN_PARENS(A_LIST) == 1 END BEGIN BOOST_PP_IS_BEGIN_PARENS((y)2(x)) == 1 END +// remove_parens + +BEGIN BOOST_PP_REMOVE_PARENS(DATA) == 17 END +BEGIN BOOST_PP_REMOVE_PARENS(DATA2)== 32 END +BEGIN BOOST_PP_REMOVE_PARENS(DATA3)== 96 END +BEGIN BOOST_PP_REMOVE_PARENS(DATA4)== 41 END + #endif