From bd968201c3276f1b472fac9d04b23b9d8502207d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tayeb?= Date: Tue, 8 Jun 2010 15:28:21 +0000 Subject: [PATCH] Try another workaround for VC++ and Intel compiler (CGAL::centroid). Add a call of overloaded CGAL::centroid function in test-suite. --- .../include/CGAL/centroid.h | 78 ++++++++++--------- .../barycenter.cpp | 3 +- 2 files changed, 44 insertions(+), 37 deletions(-) diff --git a/Principal_component_analysis/include/CGAL/centroid.h b/Principal_component_analysis/include/CGAL/centroid.h index 2311a1381ad..9423befe352 100644 --- a/Principal_component_analysis/include/CGAL/centroid.h +++ b/Principal_component_analysis/include/CGAL/centroid.h @@ -809,46 +809,44 @@ centroid(InputIterator begin, // computes the centroid of a set of kernel objects // takes an iterator range over kernel objects -// We use different overloads here in order to avoid a wrong match with -// CGAL::centroid(Point_3, Point_3, Point_3, Point_3) (with VC++ and Intel). -template < typename InputIterator, - typename K > -inline -typename Access::Point::value_type, K>::type>::type -centroid(InputIterator begin, - InputIterator end, - const K& k, - Dynamic_dimension_tag tag) +namespace internal { + +template < typename InputIterator, typename K, typename Dim_tag > +struct Dispatch_centroid_3 { - typedef typename std::iterator_traits::value_type Value_type; - return internal::centroid(begin, end, k,(Value_type*) NULL, tag); + typedef typename Access::Point::value_type, K>::type>::type result_type; + + result_type operator()(InputIterator begin, InputIterator end, const K& k, Dim_tag tag) const + { + typedef typename std::iterator_traits::value_type Value_type; + return centroid(begin, end, k,(Value_type*) NULL, tag); + } +}; + +#if defined(_MSC_VER) || defined (__INTEL_COMPILER) + // Workaround for VC++ and Intel compiler + // (avoids wrong template function instanciation) + template + struct Dispatch_centroid_3, Point_3, Point_3 > + { + typedef void result_type; + }; +#endif + +} // namespace internal + +template < typename InputIterator, typename K> +typename internal::Dispatch_centroid_3::result_type +centroid(InputIterator begin, InputIterator end, const K& k, Dynamic_dimension_tag tag) +{ + return internal::Dispatch_centroid_3()(begin,end,k,tag); } -template < typename InputIterator, typename K > -inline -typename Access::Point::value_type, K>::type>::type -centroid(InputIterator begin, InputIterator end, const K& k, Dimension_tag<0> tag) +template < typename InputIterator, typename K, int d > +typename internal::Dispatch_centroid_3 >::result_type +centroid(InputIterator begin, InputIterator end, const K& k, Dimension_tag tag) { - typedef typename std::iterator_traits::value_type Value_type; - return internal::centroid(begin, end, k,(Value_type*) NULL, tag); -} - -template < typename InputIterator, typename K > -inline -typename Access::Point::value_type, K>::type>::type -centroid(InputIterator begin, InputIterator end, const K& k, Dimension_tag<1> tag) -{ - typedef typename std::iterator_traits::value_type Value_type; - return internal::centroid(begin, end, k,(Value_type*) NULL, tag); -} - -template < typename InputIterator, typename K > -inline -typename Access::Point::value_type, K>::type>::type -centroid(InputIterator begin, InputIterator end, const K& k, Dimension_tag<2> tag) -{ - typedef typename std::iterator_traits::value_type Value_type; - return internal::centroid(begin, end, k,(Value_type*) NULL, tag); + return internal::Dispatch_centroid_3 >()(begin,end,k,tag); } namespace internal { @@ -868,6 +866,14 @@ struct Dispatch_centroid } }; +// Avoids wrong matching with +// CGAL::centroid(Point_3, Point_3, Point_3) +template < typename K > +struct Dispatch_centroid < Point_3, Point_3 > +{ + typedef void result_type; +}; + // this one takes an iterator range over kernel objects, and a dimension tag, // and uses Kernel_traits<> to find out its kernel. template < typename InputIterator, int dim > diff --git a/Principal_component_analysis/test/Principal_component_analysis/barycenter.cpp b/Principal_component_analysis/test/Principal_component_analysis/barycenter.cpp index 0c54d97e461..b55a30248e7 100644 --- a/Principal_component_analysis/test/Principal_component_analysis/barycenter.cpp +++ b/Principal_component_analysis/test/Principal_component_analysis/barycenter.cpp @@ -104,7 +104,8 @@ void test_3() == CGAL::midpoint(p0, p1) ); // Test other CGAL::centroid overloads - assert( CGAL::centroid(p0,p1,p0,p1) == CGAL::midpoint(p0,p1) ); + Point_3 c = CGAL::centroid(p0,p1,p0,p1); + c = CGAL::centroid(p0,p1,p0); }