// Copyright (c) 2014 // INRIA Saclay-Ile de France (France) // // This file is part of CGAL (www.cgal.org) // // $URL: https://github.com/CGAL/cgal/blob/v5.1/NewKernel_d/include/CGAL/NewKernel_d/utils.h $ // $Id: utils.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Marc Glisse #ifndef CGAL_MARCUTILS #define CGAL_MARCUTILS #include #if defined(BOOST_MSVC) # pragma warning(push) # pragma warning(disable:4003) // not enough actual parameters for macro 'BOOST_PP_EXPAND_I' // https://lists.boost.org/boost-users/2014/11/83291.php #endif #include #include #include #include #include #include #include #include #include namespace CGAL { namespace internal { BOOST_MPL_HAS_XXX_TRAIT_DEF(type) } template ::value /*false*/> struct Has_type_different_from : boost::false_type {}; template struct Has_type_different_from : boost::mpl::not_ > {}; template struct Wrap_type { typedef T type; }; // tell a function f(a,b,c) that its real argument is a(b,c) struct Eval_functor {}; // forget the first argument. Useful to make something dependant // (and thus usable in SFINAE), although that's not a great design. template struct Second_arg { typedef B type; }; // like std::forward, except for basic types where it does a cast, to // avoid issues with narrowing conversions template inline typename std::conditional::value&&std::is_arithmetic::type>::value,T,U&&>::type forward_safe(V&& u) { return std::forward(u); } template struct Constructible_from_each; template struct Constructible_from_each{ enum { value=std::is_convertible::value&&Constructible_from_each::value }; }; template struct Constructible_from_each{ enum { value=true }; }; template struct Scale { T const& scale; Scale(T const& t):scale(t){} template decltype(auto) operator()(FT&& x)const { return (scale*std::forward(x)); } }; template struct Divide { T const& scale; Divide(T const& t):scale(t){} template //FIXME: gcc complains for Gmpq //decltype(auto) operator()(FT&& x)const NT operator()(FT&& x)const { return Rational_traits(). make_rational(std::forward(x),scale); } }; template struct has_cheap_constructor : boost::is_arithmetic{}; template struct has_cheap_constructor > { enum { value=true }; }; // like std::multiplies but allows mixing types // in C++11 in doesn't need to be a template template < class Ret > struct multiplies { template decltype(auto) operator()(A&&a,B&&b)const { return std::forward(a)*std::forward(b); } }; template < class Ret > struct division { template decltype(auto) operator()(A&&a,B&&b)const { return std::forward(a)/std::forward(b); } }; using std::decay; template struct Type_copy_ref { typedef U type; }; template struct Type_copy_ref { typedef U& type; }; template struct Type_copy_ref { typedef U&& type; }; 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> {}; struct Dereference_functor { template struct result{}; template struct result { typedef typename std::iterator_traits::reference type; }; template decltype(auto) operator()(It const&i)const{ return *i; } }; namespace internal { template inline decltype(auto) do_call_on_tuple_elements(F&&f, std::tuple&&t, std::index_sequence&&) { return f(std::get(std::move(t))...); } } // internal template inline decltype(auto) call_on_tuple_elements(F&&f, std::tuple&&t) { return internal::do_call_on_tuple_elements(std::forward(f),std::move(t), std::make_index_sequence()); } template struct Factory { typedef A result_type; template result_type operator()(U&&...u)const{ return A(std::forward(u)...); } }; } // TODO: make a Cartesian-only variant // WARNING: do not use the Req* parameters too much, they can cause circular instanciations and are only useful for dispatching. #define CGAL_STRIP_PAREN_(...) __VA_ARGS__ #define CGAL_STRIP_PAREN(...) CGAL_STRIP_PAREN_ __VA_ARGS__ // What to do with O? pass it down to other functors or drop it? #define CGAL_KD_DEFAULT_FUNCTOR(Tg,Name,ReqTyp,ReqFun) \ template \ struct Get_functor::value \ || !Provides_types >::value \ || !Provides_functors >::value \ , int, void>::type> \ { \ typedef CGAL_STRIP_PAREN_ Name type; \ typedef K Bound_kernel; \ } // Not used yet, may need some changes. #define CGAL_KD_DEFAULT_TYPE(Tg,Name,ReqTyp,ReqFun) \ template \ struct Get_type::value \ || !Provides_types >::value \ || !Provides_functors >::value \ , int, void>::type> \ { \ typedef CGAL_STRIP_PAREN_ Name type; \ typedef K Bound_kernel; \ } #if defined(BOOST_MSVC) # pragma warning(pop) #endif #endif