From 84d83bf996c667574dc1157dc1b21e5ceb90462c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Fri, 7 Dec 2012 12:11:31 +0100 Subject: [PATCH] Use the improved Type_mapper to implement parts of Cartesian_converter --- .../include/CGAL/Cartesian_converter.h | 77 ++++++++----------- 1 file changed, 31 insertions(+), 46 deletions(-) diff --git a/Cartesian_kernel/include/CGAL/Cartesian_converter.h b/Cartesian_kernel/include/CGAL/Cartesian_converter.h index 9c1604ea54e..48519d997cc 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian_converter.h +++ b/Cartesian_kernel/include/CGAL/Cartesian_converter.h @@ -57,32 +57,30 @@ struct Default_converter { typedef ::CGAL::NT_converter Type; }; -template -struct Transform_type_mapper { - typedef typename boost::mpl::transform< Seq, typename boost::mpl::lambda< Type_mapper< boost::mpl::_1, K1, K2 > >::type >::type type; -}; - // Out will be a variant, source kernel and target kernel -template +template struct Converting_visitor : boost::static_visitor<> { - Converting_visitor(const Conv& conv, Out& out) : conv(&conv), out(&out) {} - const Conv* conv; - Out* out; + Converting_visitor(const Converter& conv, Output& out) : conv(&conv), out(&out) {} + const Converter* conv; + Output* out; template - void operator()(const T& t) { - *out = conv->operator()(t); - } + void operator()(const T& t) { *out = conv->operator()(t); } template void operator()(const std::vector& t) { - typedef typename Type_mapper< T, typename Conv::Source_kernel, typename Conv::Target_kernel >::type value_type; - std::vector< value_type > tmp(t.size()); + typedef typename + Type_mapper< T, typename Converter::Source_kernel, + typename Converter::Target_kernel >::type + value_type; - for(std::size_t i = 0; i < t.size(); ++i) { - tmp[i] = conv->operator()(t[i]); + std::vector< value_type > tmp; + tmp.reserve(t.size()); + for(typename std::vector< T >::iterator it = t.begin(); + it != t.end(); ++it) { + tmp.push_back(conv->operator()(*it)); } - + *out = tmp; } }; @@ -138,49 +136,36 @@ public: // new list into a variant // visit to get the type, and copy construct inside the return type template - boost::optional< - typename boost::make_variant_over< - typename internal::Transform_type_mapper< - typename boost::mpl::remove< boost::mpl::vector< BOOST_VARIANT_ENUM_PARAMS(U) >, - boost::detail::variant::void_ >::type - , K1, K2 >::type - >::type > + typename + Type_mapper< boost::optional< boost::variant< BOOST_VARIANT_ENUM_PARAMS(U) > >, + K1, K2 >::type operator()(const boost::optional< boost::variant< BOOST_VARIANT_ENUM_PARAMS(U) > >& o) const { - typedef boost::optional< - typename boost::make_variant_over< - typename internal::Transform_type_mapper< - typename boost::mpl::remove< boost::mpl::vector< BOOST_VARIANT_ENUM_PARAMS(U) >, - boost::detail::variant::void_ >::type - , K1, K2 >::type - >::type > result_type; + typedef typename + Type_mapper< boost::optional< boost::variant< BOOST_VARIANT_ENUM_PARAMS(U) > >, + K1, K2 >::type result_type; result_type res; if(!o) { // empty converts to empty return res; } - internal::Converting_visitor conv_visitor = internal::Converting_visitor(*this, res); + internal::Converting_visitor + conv_visitor = internal::Converting_visitor(*this, res); boost::apply_visitor(conv_visitor, *o); return res; } template - typename boost::make_variant_over< - typename internal::Transform_type_mapper< - typename boost::mpl::remove< boost::mpl::vector< BOOST_VARIANT_ENUM_PARAMS(U) >, - boost::detail::variant::void_ >::type - , K1, K2 >::type - >::type + typename + Type_mapper< boost::variant< BOOST_VARIANT_ENUM_PARAMS(U) >, + K1, K2 >::type operator()(const boost::variant< BOOST_VARIANT_ENUM_PARAMS(U) > & o) const { - typedef - typename boost::make_variant_over< - typename internal::Transform_type_mapper< - typename boost::mpl::remove< boost::mpl::vector< BOOST_VARIANT_ENUM_PARAMS(U) >, - boost::detail::variant::void_ >::type - , K1, K2 >::type - >::type result_type; + typedef typename + Type_mapper< boost::variant< BOOST_VARIANT_ENUM_PARAMS(U) >, + K1, K2 >::type result_type; result_type res; - internal::Converting_visitor conv_visitor = internal::Converting_visitor(*this, res); + internal::Converting_visitor + conv_visitor = internal::Converting_visitor(*this, res); boost::apply_visitor(conv_visitor, o); return res; }