diff --git a/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Cartesian_wrap.h b/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Cartesian_wrap.h index 87e61d58ae8..c2d80b9dfdb 100644 --- a/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Cartesian_wrap.h +++ b/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Cartesian_wrap.h @@ -2,11 +2,67 @@ #define CGAL_KERNEL_D_CARTESIAN_WRAP_H #include +#include #include #include #include +#include namespace CGAL { +namespace internal { +BOOST_MPL_HAS_XXX_TRAIT_DEF(Is_wrapper) +template::value> struct Is_wrapper { + enum { value=false }; + typedef Tag_false type; +}; +template struct Is_wrapper { + typedef typename T::Is_wrapper type; + enum { value=type::value }; +}; + +template::value> struct Is_wrapper_iterator { + enum { value=false }; + typedef Tag_false type; +}; +template struct Is_wrapper_iterator : + Is_wrapper::value_type> +{ }; + +struct Forward_rep { +//TODO: make a good C++0X version with perfect forwarding +//#ifdef CGAL_CXX0X +//template ::type>::value&&!Is_wrapper_iterator::type>::value>::type> +//T&& operator()(typename std::remove_reference::type&& t) const {return static_cast(t);}; +//template ::type>::value&&!Is_wrapper_iterator::type>::value>::type> +//T&& operator()(typename std::remove_reference::type& t) const {return static_cast(t);}; +// +//template ::type>::value>::type> +//typename Type_copy_cvref::type::Rep>::type&& +//operator()(T&& t) const { +// return static_cast::type::Rep>::type&&>(t.rep()); +//}; +// +//template ::type>::value>::type> +//transforming_iterator::type> +//operator()(T&& t) const { +// return make_transforming_iterator(std::forward(t),Forward_rep()); +//}; +//#else +template ::value,bool=Is_wrapper_iterator::value> struct result_; +template struct result_{typedef T type;}; +template struct result_{typedef typename decay::type::Rep type;}; +template struct result_{typedef transforming_iterator::type> type;}; +template struct result; +template struct result : result_ {}; + +template typename boost::disable_if,Is_wrapper_iterator >,T>::type const& operator()(T const& t) const {return t;} + +template typename boost::enable_if,T>::type::Rep const& operator()(T const& t) const {return t.rep();} + +template transforming_iterator,T>::type> operator()(T const& t) const {return make_transforming_iterator(t,Forward_rep());} +//#endif +}; +} template < typename Base_ > struct Cartesian_wrap : public Base_ @@ -21,8 +77,6 @@ struct Cartesian_wrap : public Base_ template struct map_type { typedef X type; }; #include - //TODO: adapt all functors - //TODO: safely apply .rep() to the arguments (and transforming_iterator) template struct Construct { typedef typename Kernel_base::template Construct::type B; struct type { @@ -30,23 +84,71 @@ struct Cartesian_wrap : public Base_ typedef typename map_kernel_obj::type result_type; #ifdef CGAL_CXX0X template result_type operator()(U&&...u)const{ - return result_type(Eval_functor(),B(),std::forward(u)...); + return result_type(Eval_functor(),B(),internal::Forward_rep()(u)...); } #else +#define VAR(Z,N,_) internal::Forward_rep()(u##N) #define CODE(Z,N,_) template result_type \ operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,U,const&u))const{ \ - return result_type(Eval_functor(),B(),BOOST_PP_ENUM_PARAMS(N,u)); \ + return result_type(Eval_functor(),B(),BOOST_PP_ENUM(N,VAR,)); \ } BOOST_PP_REPEAT_FROM_TO(1,11,CODE,_) +#undef CODE +#undef VAR #endif }; }; + + //TODO: adapt all functors + //TODO: safely apply .rep() to the arguments (and transforming_iterator) + //FIXME: looks like only those 2 are missing template struct Construct { typedef typename Kernel_base::template Construct::type type; }; template struct Construct { typedef typename Kernel_base::template Construct::type type; }; + + template struct Predicate { + typedef typename Kernel_base::template Predicate::type B; + struct type { + typedef typename B::result_type result_type; +#ifdef CGAL_CXX0X + template result_type operator()(U&&...u)const{ + return B()(internal::Forward_rep()(u)...); + } +#else +#define VAR(Z,N,_) internal::Forward_rep()(u##N) +#define CODE(Z,N,_) template result_type \ + operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,U,const&u))const{ \ + return B()(BOOST_PP_ENUM(N,VAR,)); \ + } + BOOST_PP_REPEAT_FROM_TO(1,11,CODE,_) +#undef CODE +#undef VAR +#endif + }; + }; + template struct Compute { + typedef typename Kernel_base::template Compute::type B; + struct type { + typedef typename B::result_type result_type; +#ifdef CGAL_CXX0X + template result_type operator()(U&&...u)const{ + return B()(internal::Forward_rep()(u)...); + } +#else +#define VAR(Z,N,_) internal::Forward_rep()(u##N) +#define CODE(Z,N,_) template result_type \ + operator()(BOOST_PP_ENUM_BINARY_PARAMS(N,U,const&u))const{ \ + return B()(BOOST_PP_ENUM(N,VAR,)); \ + } + BOOST_PP_REPEAT_FROM_TO(1,11,CODE,_) +#undef CODE +#undef VAR +#endif + }; + }; }; } //namespace CGAL diff --git a/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Point_d.h b/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Point_d.h index ca3f0a30526..c3d9b48f54d 100644 --- a/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Point_d.h +++ b/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Point_d.h @@ -30,6 +30,7 @@ class Point_d : public R_::Kernel_base::Point public: + typedef Tag_true Is_wrapper; typedef typename R_::Default_ambient_dimension Ambient_dimension; typedef Dimension_tag<0> Feature_dimension; diff --git a/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Segment_d.h b/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Segment_d.h index ca779f9fa5f..38528f878db 100644 --- a/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Segment_d.h +++ b/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Segment_d.h @@ -31,6 +31,7 @@ class Segment_d : public R_::Kernel_base::Segment public: + typedef Tag_true Is_wrapper; typedef typename R_::Default_ambient_dimension Ambient_dimension; typedef Dimension_tag<1> Feature_dimension; diff --git a/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Vector_d.h b/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Vector_d.h index 021360dd477..dc318909c77 100644 --- a/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Vector_d.h +++ b/NewKernel_d/include/CGAL/Kernel_d/Wrapper/Vector_d.h @@ -30,6 +30,7 @@ class Vector_d : public R_::Kernel_base::Vector public: + typedef Tag_true Is_wrapper; typedef typename R_::Default_ambient_dimension Ambient_dimension; typedef Dimension_tag<0> Feature_dimension; diff --git a/NewKernel_d/include/CGAL/marcutils.h b/NewKernel_d/include/CGAL/marcutils.h index 1425c78b892..844b97a2933 100644 --- a/NewKernel_d/include/CGAL/marcutils.h +++ b/NewKernel_d/include/CGAL/marcutils.h @@ -129,6 +129,19 @@ namespace CGAL { #else template struct decay : boost::remove_cv::type> {}; #endif + + template struct Type_copy_ref { typedef U type; }; + template struct Type_copy_ref { typedef U& type; }; +#ifdef CGAL_CXX0X + template struct Type_copy_ref { typedef U&& type; }; +#endif + template struct Type_copy_cv { typedef U type; }; + template struct Type_copy_cv { typedef U const type; }; + template struct Type_copy_cv { typedef U volatile type; }; + template struct Type_copy_cv { typedef U const volatile type; }; + + template struct Type_copy_cvref : + Type_copy_ref::type,U>::type> {}; } #endif diff --git a/NewKernel_d/test/NewKernel_d/test.cpp b/NewKernel_d/test/NewKernel_d/test.cpp index 2a002d6a020..9d131a9e8f6 100644 --- a/NewKernel_d/test/NewKernel_d/test.cpp +++ b/NewKernel_d/test/NewKernel_d/test.cpp @@ -15,12 +15,12 @@ typedef CGAL::Cartesian_base_d > KE; typedef K0 K2; #elif 0 typedef CGAL::Cartesian_filter_NT K2; -#elif 1 +#elif 0 typedef CGAL::Cartesian_filter_K K2; #elif 1 struct K2: CGAL::Lazy_cartesian,K2>{}; #endif -#if 1 +#if 0 typedef K2 K1; #elif 1 typedef CGAL::Cartesian_wrap K1;