added a mpl struct is_same_or_equal, similar to

boost::is_same / boost::is_base_and_derived
This commit is contained in:
Andreas Meyer 2007-02-17 21:25:09 +00:00
parent e758f82547
commit 1996f8c159
7 changed files with 79 additions and 45 deletions

2
.gitattributes vendored
View File

@ -1815,6 +1815,8 @@ Ridges_3/test/Ridges_3/data/ellipsoid.off -text svneol=unset#application/octet-s
Robustness/demo/Robustness/help/index.html svneol=native#text/html
Robustness/demo/Robustness/robustness.vcproj eol=crlf
STL_Extension/include/CGAL/Iterator_transform.h -text
STL_Extension/include/CGAL/type_traits.h -text
STL_Extension/test/STL_Extension/test_type_traits.cpp -text
Scripts/developer_scripts/create_assertions.sh eol=lf
Scripts/developer_scripts/create_macosx_installer -text
SearchStructures/doc_tex/SearchStructures/d-range.eps -text svneol=unset#application/postscript

View File

@ -13,6 +13,7 @@
#define CGAL_ALGEBRAIC_STRUCTURE_TRAITS_H
#include <CGAL/number_type_basic.h>
#include <CGAL/type_traits.h>
CGAL_BEGIN_NAMESPACE
@ -524,14 +525,6 @@ namespace INTERN_AST {
namespace CGALi{
#define CGAL_IS_SAME_OR_BASE_OF(BASE,T) \
( \
::boost::is_base_and_derived< BASE , T >::value || \
::boost::is_same< BASE , T >::value \
) \
template<class AS>
class Is_integral_domain_without_division {
@ -539,7 +532,7 @@ class Is_integral_domain_without_division {
typedef typename AST::Algebraic_category Tag;
public :
static const bool value
= CGAL_IS_SAME_OR_BASE_OF(Integral_domain_without_division_tag,Tag);
= ::CGAL::is_same_or_derived<Integral_domain_without_division_tag,Tag>::value;
};
template<class AS>
@ -548,7 +541,7 @@ class Is_integral_domain {
typedef typename AST::Algebraic_category Tag;
public :
static const bool value
= CGAL_IS_SAME_OR_BASE_OF(Integral_domain_tag,Tag);
= ::CGAL::is_same_or_derived<Integral_domain_tag,Tag>::value;
};
@ -558,7 +551,7 @@ class Is_unique_factorization_domain {
typedef typename AST::Algebraic_category Tag;
public :
static const bool value
= CGAL_IS_SAME_OR_BASE_OF(Unique_factorization_domain_tag,Tag);
= ::CGAL::is_same_or_derived<Unique_factorization_domain_tag,Tag>::value;
};
template<class AS>
@ -567,7 +560,7 @@ class Is_euclidean_ring {
typedef typename AST::Algebraic_category Tag;
public :
static const bool value
= CGAL_IS_SAME_OR_BASE_OF(Euclidean_ring_tag,Tag);
= ::CGAL::is_same_or_derived<Euclidean_ring_tag,Tag>::value;
};
@ -577,7 +570,7 @@ class Is_field {
typedef typename AST::Algebraic_category Tag;
public :
static const bool value
= CGAL_IS_SAME_OR_BASE_OF(Field_tag,Tag);
= ::CGAL::is_same_or_derived<Field_tag,Tag>::value;
};
@ -587,7 +580,7 @@ class Is_field_with_sqrt {
typedef typename AST::Algebraic_category Tag;
public :
static const bool value
= CGAL_IS_SAME_OR_BASE_OF(Field_with_sqrt_tag,Tag);
= ::CGAL::is_same_or_derived<Field_with_sqrt_tag,Tag>::value;
};
template<class AS>
@ -596,9 +589,23 @@ class Is_field_with_root_of {
typedef typename AST::Algebraic_category Tag;
public :
static const bool value
= CGAL_IS_SAME_OR_BASE_OF(Field_with_root_of_tag,Tag);
= ::CGAL::is_same_or_derived<Field_with_root_of_tag,Tag>::value;
};
// FIXME: @Michael: what about this? feel free to remove it if it
// does not make sense
/*
template< class AS, class CategoryTag >
class Algebraic_structure_has_category {
typedef Algebraic_structure_traits<AS> AST;
typedef typename AST::Algebraic_category Tag;
public :
static const bool value
= ::CGAL::is_same_or_derived<CategoryTag,Tag>::value;
};
*/
} // namespace CGALi

View File

@ -29,8 +29,7 @@
#include <iterator>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_same.hpp>
// Makro to define an additional operator for binary functors which takes
// two number types as parameters that are interoperable with the

View File

@ -29,14 +29,15 @@
#define CGAL_SQRT_EXTENSION_H
#include <CGAL/number_type_basic.h>
#include <CGAL/type_traits.h>
#include <numeric> // fro std::accumulate
#include <numeric> // for std::accumulate
#include <boost/type_traits/is_same.hpp>
#include <boost/numeric/interval.hpp> // Needed by To_interval
// FIXME: isnt boost::transform called below?
//#include <boost/iterator/transform_iterator.hpp>
//#include <boost/mpl/if.hpp>
//#include <CGAL/CGAL/number_type_basic.h>
#include <boost/mpl/if.hpp>
// We have to define the macros befor including Polynomials,
// since they cause a doxygen error otherwise.. (version 1.2.4)
@ -1500,14 +1501,9 @@ template <class A, class B> class CT_ext_not_to_fwsqrt;
//<EXT,ANY>
template <class Coeff, class Root, class B>
struct Coercion_traits_for_level<Sqrt_extension<Coeff, Root>, B , CTL_SQRT_EXT>
:public ::boost::mpl::if_c<
:public ::boost::mpl::if_<
// if B is fwsqrt
::boost::is_base_and_derived<
Field_with_sqrt_tag,
typename Algebraic_structure_traits<B>::Algebraic_category >::value ||
::boost::is_same<
Field_with_sqrt_tag,
typename Algebraic_structure_traits<B>::Algebraic_category >::value
::CGAL::is_same_or_derived< Field_with_sqrt_tag, typename Algebraic_structure_traits<B>::Algebraic_category >
,
//then take Intern::Coercion_traits for fwsqrt
INTERN_CT::CT_ext_to_fwsqrt<Sqrt_extension<Coeff,Root>, B>

View File

@ -41,8 +41,8 @@
#include <CGAL/basic.h>
#include <CGAL/memory.h>
#include <CGAL/type_traits.h>
#include <boost/type_traits.hpp>
#include <boost/static_assert.hpp>
#include <boost/mpl/if.hpp>
@ -54,10 +54,6 @@
//#define LiS_HANDLE_OLD_ALLOCATION
// LiS2CGAL: there are several:
// Handle Handle_for Handle_for_virtual Ref_counted
// boost has shared_ptr
// LiS2CGAL: add it as Handle_with_policy?
// LiS2CGAL: check whether CGAL::Handle is a subset and replacing it
// LiS2CGAL: Start: Copy and use it
// LiS2CGAL: Handle Package?
@ -405,8 +401,7 @@ namespace Intern {
typedef ::CGAL::Reference_counted_hierarchy_with_union<Alloc>
Reference_counted_hierarchy_with_union;
BOOST_STATIC_ASSERT((
::boost::is_base_and_derived< Reference_counted_hierarchy_with_union, T >::value ||
::boost::is_same < Reference_counted_hierarchy_with_union, T >::value ));
::CGAL::is_same_or_derived< Reference_counted_hierarchy_with_union, T >::value ));
}
typedef T Rep;
};
@ -774,8 +769,7 @@ public:
typedef Allocator_ Allocator;
enum { is_class_hierarchy =
::boost::is_base_and_derived< Reference_counted_hierarchy_base, T>::value ||
::boost::is_same < Reference_counted_hierarchy_base, T>::value };
::CGAL::is_same_or_derived< Reference_counted_hierarchy_base, T>::value };
typedef typename Handle_policy::template Rep_bind< T, is_class_hierarchy > Bind;
// instantiate Rep_bind to activate compile time check in there
static Bind bind;
@ -812,8 +806,7 @@ private:
#ifdef LiS_HANDLE_OLD_ALLOCATION
static Rep* new_rep( const Rep& rep) {
BOOST_STATIC_ASSERT( !(
::boost::is_base_and_derived< Reference_counted_hierarchy_base, T >::value ||
::boost::is_same < Reference_counted_hierarchy_base, T >::value ));
::CGAL::is_same_or_derived< Reference_counted_hierarchy_base, T >::value ));
return new Rep(rep);
}
@ -823,8 +816,7 @@ private:
static Rep* new_rep( const Rep& rep) {
BOOST_STATIC_ASSERT( !(
::boost::is_base_and_derived< Reference_counted_hierarchy_base, T >::value ||
::boost::is_same < Reference_counted_hierarchy_base, T >::value ));
::CGAL::is_same_or_derived< Reference_counted_hierarchy_base, T >::value ));
Rep* p = allocator.allocate(1);
allocator.construct(p, rep);
return p;
@ -919,8 +911,7 @@ protected:
//! constructor will work for class hierarchies of representations.
Handle_with_policy( Rep* p) : ptr_( p) {
BOOST_STATIC_ASSERT((
::boost::is_base_and_derived< Reference_counted_hierarchy_base, T >::value ||
::boost::is_same < Reference_counted_hierarchy_base, T >::value ));
::CGAL::is_same_or_derived< Reference_counted_hierarchy_base, T >::value ));
Bind bind; // trigger compile-time check
(void)bind;
}
@ -933,8 +924,7 @@ protected:
//! the template version with one argument.
void initialize_with( Rep* p) {
BOOST_STATIC_ASSERT((
::boost::is_base_and_derived< Reference_counted_hierarchy_base, T >::value ||
::boost::is_same < Reference_counted_hierarchy_base, T >::value ));
::CGAL::is_same_or_derived< Reference_counted_hierarchy_base, T >::value ));
Bind bind; // trigger compile-time check
(void)bind;
CGAL_precondition_msg( ptr_ == 0, "Handle_with_policy::initialize_with(): the "

View File

@ -0,0 +1,21 @@
#ifndef CGAL_TYPE_TRAITS_H
#define CGAL_TYPE_TRAITS_H
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/mpl/or.hpp>
namespace CGAL {
template< class Base, class Derived >
struct is_same_or_derived :
public ::boost::mpl::or_<
::boost::is_same< Base, Derived >,
::boost::is_base_and_derived< Base, Derived >
>::type
{};
};
#endif

View File

@ -0,0 +1,19 @@
#include <CGAL/Testsuite/assert.h>
#include <CGAL/type_traits.h>
struct A {};
struct B : public A {};
typedef A C;
int main() {
CGAL_test_assert( ( ::CGAL::is_same_or_derived< A,A >::value == 1 ) );
CGAL_test_assert( ( ::CGAL::is_same_or_derived< A,B >::value == 1 ) );
CGAL_test_assert( ( ::CGAL::is_same_or_derived< B,A >::value == 0 ) );
CGAL_test_assert( ( ::CGAL::is_same_or_derived< B,B >::value == 1 ) );
CGAL_test_assert( ( ::CGAL::is_same_or_derived< A,C >::value == 1 ) );
CGAL_test_assert( ( ::CGAL::is_same_or_derived< B,C >::value == 0 ) );
CGAL_test_assert( ( ::CGAL::is_same_or_derived< C,C >::value == 1 ) );
CGAL_test_assert( ( ::CGAL::is_same_or_derived< C,A >::value == 1 ) );
CGAL_test_assert( ( ::CGAL::is_same_or_derived< C,B >::value == 1 ) );
return 0;
}