Added remove_parens and tests.

This commit is contained in:
Edward Diener
2014-05-03 02:15:47 -04:00
parent dec4cfd273
commit 70e775452a
3 changed files with 52 additions and 0 deletions

View File

@ -17,5 +17,6 @@
# include <boost/preprocessor/punctuation/is_begin_parens.hpp> # include <boost/preprocessor/punctuation/is_begin_parens.hpp>
# include <boost/preprocessor/punctuation/paren.hpp> # include <boost/preprocessor/punctuation/paren.hpp>
# include <boost/preprocessor/punctuation/paren_if.hpp> # include <boost/preprocessor/punctuation/paren_if.hpp>
# include <boost/preprocessor/punctuation/remove_parens.hpp>
# #
# endif # endif

View File

@ -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 <boost/preprocessor/config/config.hpp>
#if BOOST_PP_VARIADICS
#include <boost/preprocessor/control/iif.hpp>
#include <boost/preprocessor/facilities/identity.hpp>
#include <boost/preprocessor/punctuation/is_begin_parens.hpp>
#include <boost/preprocessor/tuple/enum.hpp>
#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 */

View File

@ -23,6 +23,11 @@
# define A_SEQ (r)($)(#) # define A_SEQ (r)($)(#)
# define AN_ARRAY (4,(5,7,f,x)) # define AN_ARRAY (4,(5,7,f,x))
# define A_LIST (e,(g,(&,BOOST_PP_NIL))) # 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 // 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(A_LIST) == 1 END
BEGIN BOOST_PP_IS_BEGIN_PARENS((y)2(x)) == 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 #endif