#include <boost/preprocessor/arithmetic/mod.hpp> #include <boost/preprocessor/list/filter.hpp> #include <boost/preprocessor/logical/not.hpp> #define LIST (1, (2, (3, (4, (5, BOOST_PP_NIL))))) #define EVEN_P(d, _, num) BOOST_PP_NOT(BOOST_PP_MOD_D(d, num, 2)) #define EVEN(list) BOOST_PP_LIST_FILTER(EVEN_P, nil, list) EVEN(LIST) // expands to (2, (4, BOOST_PP_NIL)) #define ODD_P(d, _, num) BOOST_PP_MOD_D(d, num, 2) #define ODD(list) BOOST_PP_LIST_FILTER(ODD_P, nil, list) ODD(LIST) // expands to (1, (3, (5, BOOST_PP_NIL)))
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)