mirror of https://github.com/CGAL/cgal
Added tests to verify the types returned by boost::result_of match the
real tests and ajusted the type of Construct_vertex_3 for Iso_cuboid_3
This commit is contained in:
parent
fd5edd2745
commit
659d2295d0
|
|
@ -1853,7 +1853,9 @@ Kernel_23/examples/Kernel_23/MyPointC2_iostream.h -text
|
|||
Kernel_23/examples/Kernel_23/cartesian_converter.cpp -text
|
||||
Kernel_23/include/CGAL/functions_on_enums.h -text
|
||||
Kernel_23/include/CGAL/internal/Projection_traits_3.h -text
|
||||
Kernel_23/test/Kernel_23/include/CGAL/_Result_of_kernel.h -text
|
||||
Kernel_23/test/Kernel_23/overload_bug.cpp -text
|
||||
Kernel_23/test/Kernel_23/test_result_of.cpp -text
|
||||
Kernel_d/doc_tex/Kernel_d/hypercube.png -text
|
||||
Kernel_d/doc_tex/Kernel_d_ref/Kernel_Compute_coordinate_d.tex -text
|
||||
Kernel_d/doc_tex/Kernel_d_ref/Kernel_Less_coordinate_d.tex -text
|
||||
|
|
|
|||
|
|
@ -102,13 +102,13 @@ public:
|
|||
return R().construct_max_vertex_3_object()(*this);
|
||||
}
|
||||
|
||||
typename boost::result_of<typename R::Construct_vertex_3( Iso_cuboid_3 )>::type
|
||||
typename boost::result_of<typename R::Construct_vertex_3( Iso_cuboid_3, int )>::type
|
||||
vertex(int i) const
|
||||
{
|
||||
return R().construct_vertex_3_object()(*this,i);
|
||||
}
|
||||
|
||||
typename boost::result_of<typename R::Construct_vertex_3( Iso_cuboid_3 )>::type
|
||||
typename boost::result_of<typename R::Construct_vertex_3( Iso_cuboid_3, int )>::type
|
||||
operator[](int i) const
|
||||
{
|
||||
return R().construct_vertex_3_object()(*this,i);
|
||||
|
|
|
|||
|
|
@ -1109,13 +1109,13 @@ namespace CommonKernelFunctors {
|
|||
typedef typename K::Segment_3 Segment_3;
|
||||
typedef typename K::Iso_cuboid_3 Iso_cuboid_3;
|
||||
public:
|
||||
typedef Point_3 result_type;
|
||||
typedef const Point_3& result_type;
|
||||
|
||||
Point_3
|
||||
result_type
|
||||
operator()(const Iso_cuboid_3& r) const
|
||||
{ return (r.rep().max)(); }
|
||||
|
||||
const Point_3&
|
||||
result_type
|
||||
operator()(const Segment_3& s) const
|
||||
{ return (s.rep().max)(); }
|
||||
};
|
||||
|
|
@ -1127,13 +1127,13 @@ namespace CommonKernelFunctors {
|
|||
typedef typename K::Segment_3 Segment_3;
|
||||
typedef typename K::Iso_cuboid_3 Iso_cuboid_3;
|
||||
public:
|
||||
typedef Point_3 result_type;
|
||||
typedef const Point_3& result_type;
|
||||
|
||||
Point_3
|
||||
result_type
|
||||
operator()(const Iso_cuboid_3& r) const
|
||||
{ return (r.rep().min)(); }
|
||||
|
||||
const Point_3&
|
||||
result_type
|
||||
operator()(const Segment_3& s) const
|
||||
{ return (s.rep().min)(); }
|
||||
};
|
||||
|
|
@ -1895,23 +1895,23 @@ namespace CommonKernelFunctors {
|
|||
};
|
||||
|
||||
template<typename T>
|
||||
struct result<T(Iso_cuboid_3)> {
|
||||
struct result<T(Iso_cuboid_3, int)> {
|
||||
typedef Point_3 type;
|
||||
};
|
||||
|
||||
typename result< Construct_vertex_3(Segment_3) >::type
|
||||
const Point_3&
|
||||
operator()( const Segment_3& s, int i) const
|
||||
{ return s.rep().vertex(i); }
|
||||
|
||||
typename result< Construct_vertex_3(Triangle_3) >::type
|
||||
const Point_3&
|
||||
operator()( const Triangle_3& t, int i) const
|
||||
{ return t.rep().vertex(i); }
|
||||
|
||||
typename result< Construct_vertex_3(Iso_cuboid_3) >::type
|
||||
Point_3
|
||||
operator()( const Iso_cuboid_3& r, int i) const
|
||||
{ typename result< Construct_vertex_3(Iso_cuboid_3) >::type asdf; return r.rep().vertex(i); }
|
||||
{ return r.rep().vertex(i); }
|
||||
|
||||
typename result< Construct_vertex_3(Tetrahedron_3) >::type
|
||||
const Point_3&
|
||||
operator()( const Tetrahedron_3& t, int i) const
|
||||
{ return t.rep().vertex(i); }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
#include <boost/type_traits.hpp>
|
||||
#include <CGAL/Kernel/Return_base_tag.h>
|
||||
#include <CGAL/Bbox_3.h>
|
||||
#include <CGAL/representation_tags.h>
|
||||
#include <CGAL/Dimension.h>
|
||||
|
||||
namespace CGAL {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,145 @@
|
|||
#ifndef CGAL_RESULT_OF_KERNEL_H
|
||||
#define CGAL_RESULT_OF_KERNEL_H
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include <boost/mpl/has_xxx.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
#include <boost/type_traits/is_scalar.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/utility/result_of.hpp>
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Simple_homogeneous.h>
|
||||
|
||||
template<typename T>
|
||||
struct printer;
|
||||
|
||||
namespace CGAL {
|
||||
// avoid crashes with what we already have in namespace internal
|
||||
namespace result_of_kernel {
|
||||
// required for smooth wrapping of the functors
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(Rep)
|
||||
|
||||
template<typename A, typename B>
|
||||
struct Lazy_is_same {
|
||||
typedef boost::is_same<A, typename B::Rep> type;
|
||||
};
|
||||
|
||||
// trickery to get rid of the inequality that appears with the
|
||||
// return_base_tag versions of construct calls
|
||||
template<typename A, typename B, bool t = boost::mpl::or_<
|
||||
boost::is_same<A, B>,
|
||||
typename
|
||||
boost::mpl::eval_if< has_Rep<B>,
|
||||
Lazy_is_same<A, B>,
|
||||
boost::false_type >::type
|
||||
>::value >
|
||||
struct Rep_equal;
|
||||
|
||||
template<typename A, typename B>
|
||||
struct Rep_equal<A, B, true> : boost::true_type {};
|
||||
template<typename A, typename B>
|
||||
struct Rep_equal<A, B, false> : boost::false_type {};
|
||||
}
|
||||
|
||||
// This functor can wrap any DefaultConstructible functor. Iff there
|
||||
// is a result_type typedef it needs to be forwarded. In all other
|
||||
// cases boost::result_of is necessary to determine the return type.
|
||||
template<typename F, bool result_type = result_of_kernel::has_result_type<F>::value >
|
||||
struct AnyFunctor;
|
||||
|
||||
template<typename F>
|
||||
struct AnyFunctor<F, true> {
|
||||
typedef typename F::result_type result_type;
|
||||
|
||||
template<typename... Args>
|
||||
auto operator()(Args&&... args) const -> typename std::result_of<F(Args...)>::type {
|
||||
F f;
|
||||
// check the equality of a c++03 boost::result_of and a c++11 result_of
|
||||
typedef typename std::result_of<F(Args...)>::type c11_return_type;
|
||||
typedef typename F::result_type c03_return_type;
|
||||
|
||||
static_assert((result_of_kernel::Rep_equal<c11_return_type, c03_return_type>::value),
|
||||
"Type difference between actual return type and boost::result_of<>::type");
|
||||
|
||||
return f(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename F>
|
||||
struct AnyFunctor<F, false> {
|
||||
template<typename>
|
||||
struct result;
|
||||
|
||||
template<typename Func, typename... Args>
|
||||
struct result<Func(Args...)> {
|
||||
typedef typename boost::result_of<F(Args...)>::type type;
|
||||
};
|
||||
|
||||
// same as above
|
||||
template<typename... Args>
|
||||
auto operator()(Args&&... args) const -> typename std::result_of<F(Args...)>::type {
|
||||
F f;
|
||||
typedef typename std::result_of<F(Args...)>::type c11_return_type;
|
||||
typedef typename boost::result_of<F(
|
||||
typename
|
||||
std::remove_cv<
|
||||
typename
|
||||
std::remove_reference<
|
||||
Args&&
|
||||
>::type
|
||||
>::type ...
|
||||
)>::type c03_return_type;
|
||||
|
||||
static_assert((result_of_kernel::Rep_equal<c11_return_type, c03_return_type>::value),
|
||||
"Type difference between actual return type and boost::result_of<>::type");
|
||||
|
||||
return f(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template < typename FT_, typename Kernel_ >
|
||||
struct Result_of_base
|
||||
: public Cartesian_base< Kernel_, FT_ >
|
||||
{
|
||||
typedef FT_ RT;
|
||||
typedef FT_ FT;
|
||||
|
||||
// The mechanism that allows to specify reference-counting or not.
|
||||
template < typename T >
|
||||
struct Handle { typedef T type; };
|
||||
|
||||
template < typename Kernel2 >
|
||||
struct Base { typedef Result_of_base<FT_, Kernel2> Type; };
|
||||
|
||||
typedef Kernel_ K;
|
||||
#define CGAL_Kernel_pred(Y,Z) typedef CartesianKernelFunctors::Y<K> Y; \
|
||||
Y Z() const { return Y(); }
|
||||
#define CGAL_Kernel_cons(Y,Z) CGAL_Kernel_pred(Y,Z)
|
||||
|
||||
#include <CGAL/Kernel/interface_macros.h>
|
||||
};
|
||||
|
||||
template < typename FT_ >
|
||||
struct Result_of_cartesian
|
||||
: public Type_equality_wrapper<
|
||||
Result_of_base<FT_, Result_of_cartesian<FT_> >,
|
||||
Result_of_cartesian<FT_> >
|
||||
{
|
||||
// this has to be delayed until here as AnyFunctor will
|
||||
// instantiate its arguments and only here lookup for all the
|
||||
// typedefs inside the functor will be possible
|
||||
typedef Result_of_cartesian K;
|
||||
#define CGAL_Kernel_pred(Y,Z) typedef AnyFunctor< CartesianKernelFunctors::Y<K> > Y; \
|
||||
Y Z() const { return Y(); }
|
||||
#define CGAL_Kernel_cons(Y,Z) CGAL_Kernel_pred(Y,Z)
|
||||
|
||||
#include <CGAL/Kernel/interface_macros.h>
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* CGAL_RESULT_OF_KERNEL_H */
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (c) 2011 GeometryFactory (France). All rights reserved.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Licensees holding a valid commercial license may use this file in
|
||||
// accordance with the commercial license agreement provided with the software.
|
||||
//
|
||||
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; version 2.1 of the License.
|
||||
// See the file LICENSE.LGPL distributed with CGAL.
|
||||
//
|
||||
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
||||
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// $URL$
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
// Author(s) : Philipp Moeller
|
||||
|
||||
#include <CGAL/_Result_of_kernel.h>
|
||||
#include <CGAL/_test_2.h>
|
||||
#include <CGAL/_test_3.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
|
||||
template<typename K>
|
||||
bool test(const K& k) {
|
||||
return _test_2(k) || _test_3(k);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef CGAL::Result_of_cartesian< double > A;
|
||||
A a;
|
||||
|
||||
assert( test( a ) );
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue