From b3c49d0ed2875d149404db1aeedfb5fba770baa0 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Mon, 30 Jan 2023 22:12:14 +0000 Subject: [PATCH 1/2] Replace BOOST_PP repeat macros with variadic templates --- Filtered_kernel/include/CGAL/Lazy.h | 114 +++++++++++----------------- 1 file changed, 43 insertions(+), 71 deletions(-) diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index e062002d3e6..d4a0895e49b 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -38,13 +38,6 @@ #include -#include -#include -#include -#include -#include -#include - #include #include #include @@ -797,13 +790,6 @@ public: } }; -// Macro helpers to build the kernel objects -#define CGAL_PARAM(z, n, t) std::declval() -#define CGAL_TYPEMAP_AC(z, n, t) typedef typename Type_mapper< t##n, LK, AK >::type A##n; -#define CGAL_TYPEMAP_EC(z, n, t) typedef typename Type_mapper< t##n, LK, EK >::type E##n; -#define CGAL_LEXACT(z,n,t) CGAL::exact( l##n ) -#define CGAL_LARGS(z, n, t) L##n const& l##n - #undef CGAL_LAZY_PRINT_TYPEID template < typename K1, typename K2 > @@ -1973,15 +1959,11 @@ struct Lazy_construction_variant { // you are on your own }; - #define CGAL_RESULT(z, n, d) \ - template< typename F, BOOST_PP_ENUM_PARAMS(n, class T) > \ - struct result { \ - BOOST_PP_REPEAT(n, CGAL_TYPEMAP_AC, T) \ - typedef typename Type_mapper< \ - decltype(std::declval()(BOOST_PP_ENUM(n, CGAL_PARAM, A))), AK, LK>::type type; \ - }; - - BOOST_PP_REPEAT_FROM_TO(1, 9, CGAL_RESULT, _) + template + struct result + { + typedef typename Type_mapper()(std::declval::type>()...)),AK,LK>::type type; + }; template decltype(auto) @@ -2120,26 +2102,23 @@ struct Lazy_construction { CGAL_NO_UNIQUE_ADDRESS AC ac; CGAL_NO_UNIQUE_ADDRESS EC ec; -#define CGAL_CONSTRUCTION_OPERATOR(z, n, d ) \ - template \ - decltype(auto) \ - operator()( BOOST_PP_ENUM(n, CGAL_LARGS, _) ) const { \ - typedef Lazy< AT, ET, E2A> Handle; \ - CGAL_BRANCH_PROFILER(std::string(" failures/calls to : ") + std::string(CGAL_PRETTY_FUNCTION), tmp); \ - { \ - Protect_FPU_rounding P; \ - try { \ - return result_type( Handle(new Lazy_rep_n(ac, ec, BOOST_PP_ENUM_PARAMS(n, l)))); \ - } catch (Uncertain_conversion_exception&) {} \ - } \ - CGAL_BRANCH_PROFILER_BRANCH(tmp); \ - Protect_FPU_rounding P2(CGAL_FE_TONEAREST); \ - CGAL_expensive_assertion(FPU_get_cw() == CGAL_FE_TONEAREST); \ - return result_type( Handle(new Lazy_rep_0(ec( BOOST_PP_ENUM(n, CGAL_LEXACT, _) ))) ); \ + template + decltype(auto) + operator()(const L&... l) const { + typedef Lazy < AT, ET, E2A > Handle; + CGAL_BRANCH_PROFILER(std::string(" failures/calls to : ") + std::string(CGAL_PRETTY_FUNCTION), tmp); + { + Protect_FPU_rounding P; + try { + return result_type(Handle(new Lazy_rep_n< AT, ET, AC, EC, E2A, noprune, L...>(ac, ec, l...))); + } catch (Uncertain_conversion_exception&) {} + } + CGAL_BRANCH_PROFILER_BRANCH(tmp); + Protect_FPU_rounding P2(CGAL_FE_TONEAREST); + CGAL_expensive_assertion(FPU_get_cw() == CGAL_FE_TONEAREST); + return result_type(Handle(new Lazy_rep_0< AT, ET, E2A >(ec(CGAL::exact(l)...)))); } - // arity 1-8 - BOOST_PP_REPEAT_FROM_TO(1, 9, CGAL_CONSTRUCTION_OPERATOR, _) // nullary decltype(auto) @@ -2174,35 +2153,32 @@ struct Lazy_construction CGAL_NO_UNIQUE_ADDRESS AC ac; CGAL_NO_UNIQUE_ADDRESS EC ec; - // acquire the result_type of the approximate kernel, map it back to the lazy kernel object - BOOST_PP_REPEAT_FROM_TO(1, 9, CGAL_RESULT, _) + template + struct result + { + typedef typename Type_mapper()(std::declval::type>()...)),AK,LK>::type type; + }; -#define CGAL_CONSTRUCTION_OPERATOR(z, n, d) \ - template \ - decltype(auto) \ - operator()( BOOST_PP_ENUM(n, CGAL_LARGS, _) ) const { \ - BOOST_PP_REPEAT(n, CGAL_TYPEMAP_EC, L) \ - BOOST_PP_REPEAT(n, CGAL_TYPEMAP_AC, L) \ - typedef typename Type_mapper()(BOOST_PP_ENUM(n, CGAL_PARAM, E))),EK,EK>::type ET; \ - typedef typename Type_mapper()(BOOST_PP_ENUM(n, CGAL_PARAM, A))),AK,AK>::type AT; \ - typedef Lazy< AT, ET, E2A> Handle; \ - typedef typename result::type result_type; \ - CGAL_BRANCH_PROFILER(std::string(" failures/calls to : ") + std::string(CGAL_PRETTY_FUNCTION), tmp); \ - { \ - Protect_FPU_rounding P; \ - try { \ - return result_type( Handle(new Lazy_rep_n(ac, ec, BOOST_PP_ENUM_PARAMS(n, l)))); \ - } catch (Uncertain_conversion_exception&) {} \ - } \ - CGAL_BRANCH_PROFILER_BRANCH(tmp); \ - Protect_FPU_rounding P2(CGAL_FE_TONEAREST); \ - CGAL_expensive_assertion(FPU_get_cw() == CGAL_FE_TONEAREST); \ - return result_type( Handle(new Lazy_rep_0(ec( BOOST_PP_ENUM(n, CGAL_LEXACT, _) ))) ); \ + template + decltype(auto) + operator()(const L&... l) const { + typedef typename Type_mapper()(std::declval::type>()...)),EK,EK>::type ET; + typedef typename Type_mapper()(std::declval::type>()...)),AK,AK>::type AT; + typedef Lazy Handle; + typedef typename result::type result_type; + CGAL_BRANCH_PROFILER(std::string(" failures/calls to : ") + std::string(CGAL_PRETTY_FUNCTION), tmp); + { + Protect_FPU_rounding P; + try { + return result_type(Handle(new Lazy_rep_n (ac, ec, l...))); + } catch (Uncertain_conversion_exception&) {} + } + CGAL_BRANCH_PROFILER_BRANCH(tmp); + Protect_FPU_rounding P2(CGAL_FE_TONEAREST); + CGAL_expensive_assertion(FPU_get_cw() == CGAL_FE_TONEAREST); + return result_type(Handle(new Lazy_rep_0 (ec(CGAL::exact(l)...)))); } - // arity 1-8 - BOOST_PP_REPEAT_FROM_TO(1, 9, CGAL_CONSTRUCTION_OPERATOR, _) - // nullary decltype(auto) operator()() const @@ -2218,10 +2194,6 @@ struct Lazy_construction } //namespace CGAL -#undef CGAL_TYPEMAP_AC -#undef CGAL_TYPEMAP_EC -#undef CGAL_LEXACT -#undef CGAL_LARGS #include From 5ed01d1498641963000204f4d1ccfe7d3a4ae795 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Tue, 31 Jan 2023 19:39:25 +0000 Subject: [PATCH 2/2] Remove unneeded undef --- Filtered_kernel/include/CGAL/Lazy.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index d4a0895e49b..e7024f6220b 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -2128,8 +2128,6 @@ struct Lazy_construction { return result_type( Handle() ); } -#undef CGAL_CONSTRUCTION_OPERATOR - };