From 75b3fc84ecd0cd04c9602be0cb3b944b4e619080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Wed, 14 Dec 2011 14:29:07 +0000 Subject: [PATCH] * Now also tests homogeneous and passes run-time tests as well. * Fixed leftover bug Homogeneous function objects --- .../CGAL/Homogeneous/function_objects.h | 2 +- .../include/CGAL/_Result_of_kernel.h | 66 +++++++++++++++++-- Kernel_23/test/Kernel_23/test_result_of.cpp | 22 ++++--- 3 files changed, 74 insertions(+), 16 deletions(-) diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index c2af8973a8e..ba20fd0ae8d 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -3523,7 +3523,7 @@ namespace HomogeneousKernelFunctors { }; template - struct result { + struct result { typedef Point_2 type; }; diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_Result_of_kernel.h b/Kernel_23/test/Kernel_23/include/CGAL/_Result_of_kernel.h index 892fa3f7082..2ee5deee951 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_Result_of_kernel.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_Result_of_kernel.h @@ -1,6 +1,10 @@ #ifndef CGAL_RESULT_OF_KERNEL_H #define CGAL_RESULT_OF_KERNEL_H +#if !defined(CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES) && !defined(CGAL_CFG_NO_CPP0X_RVALUE_REFERENCE) && !defined(CGAL_CFG_NO_CPP0X_STATIC_ASSERT) + +#define CGAL_RESULT_OF_KERNEL 1 + #include #include @@ -11,8 +15,11 @@ #include #include -#include -#include +#include +#include + +#include + template struct printer; @@ -102,11 +109,13 @@ namespace CGAL { } }; - template < typename FT_, typename Kernel_ > + // usual copy pasta from simple_cartesian and cartesian plus an + // template template parameter to inject the true base + template < typename RT_, typename FT_, typename Kernel_, template class Inject> struct Result_of_base - : public Cartesian_base< Kernel_, FT_ > + : public Inject< RT_, FT_, Kernel_> { - typedef FT_ RT; + typedef RT_ RT; typedef FT_ FT; // The mechanism that allows to specify reference-counting or not. @@ -114,9 +123,24 @@ namespace CGAL { struct Handle { typedef T type; }; template < typename Kernel2 > - struct Base { typedef Result_of_base Type; }; + struct Base { typedef Result_of_base Type; }; + }; + // alias cartesian to something similar to Homogeneous. Requires gcc 4.7. + // NB. Kernel is either last of first argument to add a little more confusion. + + // template + // using Cartesian_base_3 = Cartesian_base; + + // hack instead + template + struct Cartesian_base_3 : public Cartesian_base { }; + + template < typename FT_, typename Kernel_ > + struct Result_of_cartesian_base : public Result_of_base + { typedef Kernel_ K; + #define CGAL_Kernel_pred(Y,Z) typedef CartesianKernelFunctors::Y Y; \ Y Z() const { return Y(); } #define CGAL_Kernel_cons(Y,Z) CGAL_Kernel_pred(Y,Z) @@ -124,10 +148,22 @@ namespace CGAL { #include }; + template < typename RT_, typename FT_, typename Kernel_ > + struct Result_of_homogeneous_base : public Result_of_base + { + typedef Kernel_ K; + + #define CGAL_Kernel_pred(Y,Z) typedef HomogeneousKernelFunctors::Y Y; \ + Y Z() const { return Y(); } + #define CGAL_Kernel_cons(Y,Z) CGAL_Kernel_pred(Y,Z) + + #include + }; + template < typename FT_ > struct Result_of_cartesian : public Type_equality_wrapper< - Result_of_base >, + Result_of_cartesian_base >, Result_of_cartesian > { // this has to be delayed until here as AnyFunctor will @@ -137,9 +173,25 @@ namespace CGAL { #define CGAL_Kernel_pred(Y,Z) typedef AnyFunctor< CartesianKernelFunctors::Y > Y; \ Y Z() const { return Y(); } #define CGAL_Kernel_cons(Y,Z) CGAL_Kernel_pred(Y,Z) + + #include + }; + + // same as above + template < typename RT_, typename FT_ > + struct Result_of_homogeneous + : public Type_equality_wrapper< + Result_of_homogeneous_base >, + Result_of_homogeneous > + { + typedef Result_of_homogeneous K; + #define CGAL_Kernel_pred(Y,Z) typedef AnyFunctor< HomogeneousKernelFunctors::Y > Y; \ + Y Z() const { return Y(); } + #define CGAL_Kernel_cons(Y,Z) CGAL_Kernel_pred(Y,Z) #include }; } +#endif /* C++11 GUARD */ #endif /* CGAL_RESULT_OF_KERNEL_H */ diff --git a/Kernel_23/test/Kernel_23/test_result_of.cpp b/Kernel_23/test/Kernel_23/test_result_of.cpp index 8af1027cf7f..e8faf4b4f6a 100644 --- a/Kernel_23/test/Kernel_23/test_result_of.cpp +++ b/Kernel_23/test/Kernel_23/test_result_of.cpp @@ -18,23 +18,29 @@ // // Author(s) : Philipp Moeller -#include -#include -#include +#include "CGAL/_Result_of_kernel.h" +#include "CGAL/_test_2.h" +#include "CGAL/_test_3.h" #include +#include + +#include "CGAL/Precise_numbers.h" template bool test(const K& k) { - return _test_2(k) || _test_3(k); + return _test_2(k) && _test_3(k); } int main() { - typedef CGAL::Result_of_cartesian< double > A; - A a; - - assert( test( a ) ); +#if defined(CGAL_RESULT_OF_KERNEL) + typedef CGAL::Result_of_cartesian< CGAL::Quotient > A; + typedef CGAL::Result_of_homogeneous< Precise_integer, CGAL::Quotient > B; + + test( A() ); + test( B() ); +#endif return 0; }