123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- /*-----------------------------------------------------------------------------+
- Copyright (c) 2008-2009: Joachim Faulhaber
- +------------------------------------------------------------------------------+
- Distributed under the Boost Software License, Version 1.0.
- (See accompanying file LICENCE.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
- +-----------------------------------------------------------------------------*/
- #ifndef BOOST_ICL_IS_COMBINABLE_HPP_JOFA_090115
- #define BOOST_ICL_IS_COMBINABLE_HPP_JOFA_090115
- #include <boost/mpl/bool.hpp>
- #include <boost/mpl/if.hpp>
- #include <boost/mpl/and.hpp>
- #include <boost/mpl/or.hpp>
- #include <boost/mpl/not.hpp>
- #include <boost/type_traits/is_same.hpp>
- #include <boost/icl/type_traits/is_concept_equivalent.hpp>
- #include <boost/icl/type_traits/is_interval_container.hpp>
- namespace boost{namespace icl
- {
- template<class Type>
- struct is_overloadable
- {
- typedef is_overloadable<Type> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (boost::is_same<Type, typename Type::overloadable_type>::value)
- );
- };
- //------------------------------------------------------------------------------
- template<class LeftT, class RightT>
- struct is_codomain_equal
- {
- typedef is_codomain_equal<LeftT, RightT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (boost::is_same<typename LeftT::codomain_type,
- typename RightT::codomain_type>::value)
- );
- };
- //NOTE: Equality of compare order implies the equality of the domain_types
- template<class LeftT, class RightT>
- struct is_key_compare_equal
- {
- typedef is_key_compare_equal<LeftT, RightT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (boost::is_same<typename LeftT::key_compare,
- typename RightT::key_compare>::value)
- );
- };
- template<class LeftT, class RightT>
- struct is_codomain_type_equal
- {
- typedef is_codomain_type_equal<LeftT, RightT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::and_<is_key_compare_equal<LeftT, RightT>,
- is_codomain_equal<LeftT, RightT> >::value)
- );
- };
- // For equal containers concepts, domain order and codomain type must match.
- template<template<class>class IsConcept, class LeftT, class RightT>
- struct is_concept_compatible
- {
- typedef is_concept_compatible<IsConcept, LeftT, RightT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::and_<
- IsConcept<LeftT>
- , IsConcept<RightT>
- , is_codomain_type_equal<LeftT, RightT>
- >::value)
- );
- };
- template<template<class>class LeftConcept,
- template<class>class RightConcept,
- class LeftT, class RightT>
- struct is_concept_combinable
- {
- typedef is_concept_combinable<LeftConcept, RightConcept, LeftT, RightT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::and_<
- LeftConcept<LeftT>
- , RightConcept<RightT>
- , is_key_compare_equal<LeftT, RightT>
- >::value)
- );
- };
- template<class LeftT, class RightT>
- struct is_intra_combinable
- {
- typedef is_intra_combinable<LeftT, RightT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_<
- is_concept_compatible<is_interval_set, LeftT, RightT>
- , is_concept_compatible<is_interval_map, LeftT, RightT>
- >::value)
- );
- };
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- template<class LeftT, class RightT>
- struct is_cross_combinable
- {
- typedef is_cross_combinable<LeftT, RightT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_<
- is_concept_combinable<is_interval_set, is_interval_map, LeftT, RightT>
- , is_concept_combinable<is_interval_map, is_interval_set, LeftT, RightT>
- >::value)
- );
- };
- template<class LeftT, class RightT>
- struct is_inter_combinable
- {
- typedef is_inter_combinable<LeftT, RightT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_<is_intra_combinable<LeftT,RightT>,
- is_cross_combinable<LeftT,RightT> >::value)
- );
- };
- //------------------------------------------------------------------------------
- // is_fragment_of
- //------------------------------------------------------------------------------
- template<class FragmentT, class Type>
- struct is_fragment_of
- {
- typedef is_fragment_of type;
- BOOST_STATIC_CONSTANT(bool, value = false);
- };
- template<class Type>
- struct is_fragment_of<typename Type::element_type, Type>
- {
- typedef is_fragment_of type;
- BOOST_STATIC_CONSTANT(bool, value = true);
- };
- template<class Type>
- struct is_fragment_of<typename Type::segment_type, Type>
- {
- typedef is_fragment_of type;
- BOOST_STATIC_CONSTANT(bool, value = true);
- };
- //------------------------------------------------------------------------------
- // is_key_of
- //------------------------------------------------------------------------------
- template<class KeyT, class Type>
- struct is_key_of
- {
- typedef is_key_of type;
- BOOST_STATIC_CONSTANT(bool, value = false);
- };
- template<class Type>
- struct is_key_of<typename Type::domain_type, Type>
- {
- typedef is_key_of type;
- BOOST_STATIC_CONSTANT(bool, value = true);
- };
- template<class Type>
- struct is_key_of<typename Type::interval_type, Type>
- {
- typedef is_key_of type;
- BOOST_STATIC_CONSTANT(bool, value = true);
- };
- //------------------------------------------------------------------------------
- // is_interval_set_derivative
- //------------------------------------------------------------------------------
- template<class Type, class AssociateT>
- struct is_interval_set_derivative;
- template<class Type>
- struct is_interval_set_derivative<Type, typename Type::domain_type>
- {
- typedef is_interval_set_derivative type;
- BOOST_STATIC_CONSTANT(bool, value = (is_interval_container<Type>::value));
- };
- template<class Type>
- struct is_interval_set_derivative<Type, typename Type::interval_type>
- {
- typedef is_interval_set_derivative type;
- BOOST_STATIC_CONSTANT(bool, value = (is_interval_container<Type>::value));
- };
- template<class Type, class AssociateT>
- struct is_interval_set_derivative
- {
- typedef is_interval_set_derivative<Type, AssociateT> type;
- BOOST_STATIC_CONSTANT(bool, value = false);
- };
- //------------------------------------------------------------------------------
- // is_interval_map_derivative
- //------------------------------------------------------------------------------
- template<class Type, class AssociateT>
- struct is_interval_map_derivative;
- template<class Type>
- struct is_interval_map_derivative<Type, typename Type::domain_mapping_type>
- {
- typedef is_interval_map_derivative type;
- BOOST_STATIC_CONSTANT(bool, value = (is_interval_container<Type>::value));
- };
- template<class Type>
- struct is_interval_map_derivative<Type, typename Type::interval_mapping_type>
- {
- typedef is_interval_map_derivative type;
- BOOST_STATIC_CONSTANT(bool, value = (is_interval_container<Type>::value));
- };
- template<class Type>
- struct is_interval_map_derivative<Type, typename Type::value_type>
- {
- typedef is_interval_map_derivative type;
- BOOST_STATIC_CONSTANT(bool, value = (is_interval_container<Type>::value));
- };
- template<class Type, class AssociateT>
- struct is_interval_map_derivative
- {
- typedef is_interval_map_derivative<Type, AssociateT> type;
- BOOST_STATIC_CONSTANT(bool, value = false);
- };
- //------------------------------------------------------------------------------
- // is_intra_derivative
- //------------------------------------------------------------------------------
- template<class Type, class AssociateT>
- struct is_intra_derivative
- {
- typedef is_intra_derivative<Type, AssociateT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_
- <
- mpl::and_<is_interval_set<Type>,
- is_interval_set_derivative<Type, AssociateT> >
- , mpl::and_<is_interval_map<Type>,
- is_interval_map_derivative<Type, AssociateT> >
- >::value)
- );
- };
- template<class Type, class AssociateT>
- struct is_cross_derivative
- {
- typedef is_cross_derivative<Type, AssociateT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::and_<
- is_interval_map<Type>
- , is_interval_set_derivative<Type, AssociateT>
- >::value)
- );
- };
- template<class Type, class AssociateT>
- struct is_inter_derivative
- {
- typedef is_inter_derivative<Type, AssociateT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_<
- is_intra_derivative<Type, AssociateT>
- , is_cross_derivative<Type, AssociateT>
- >::value)
- );
- };
- //------------------------------------------------------------------------------
- //- right combinable
- //------------------------------------------------------------------------------
- template<class GuideT, class CompanionT>
- struct is_interval_set_right_combinable
- {
- typedef is_interval_set_right_combinable<GuideT, CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::and_
- <
- is_interval_set<GuideT>
- , mpl::or_
- <
- is_interval_set_derivative<GuideT, CompanionT>
- , is_concept_compatible<is_interval_set, GuideT, CompanionT>
- >
- >::value)
- );
- };
- template<class GuideT, class CompanionT>
- struct is_interval_map_right_intra_combinable //NOTE equivalent to is_fragment_type_of
- {
- typedef is_interval_map_right_intra_combinable<GuideT, CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::and_
- <
- is_interval_map<GuideT>
- , mpl::or_
- <
- is_interval_map_derivative<GuideT, CompanionT>
- , is_concept_compatible<is_interval_map, GuideT, CompanionT>
- >
- >::value)
- );
- };
- template<class GuideT, class CompanionT>
- struct is_interval_map_right_cross_combinable //NOTE equivalent to key_type_of<Comp, Guide>
- {
- typedef is_interval_map_right_cross_combinable<GuideT, CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::and_
- <
- is_interval_map<GuideT>
- , mpl::or_
- <
- is_cross_derivative<GuideT, CompanionT>
- , is_concept_combinable<is_interval_map, is_interval_set, GuideT, CompanionT>
- >
- >::value)
- );
- };
- template<class GuideT, class CompanionT>
- struct is_interval_map_right_inter_combinable
- {
- typedef is_interval_map_right_inter_combinable<GuideT, CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_<
- is_interval_map_right_intra_combinable<GuideT, CompanionT>
- , is_interval_map_right_cross_combinable<GuideT, CompanionT>
- >::value)
- );
- };
- template<class GuideT, class CompanionT>
- struct is_right_intra_combinable
- {
- typedef is_right_intra_combinable<GuideT, CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_
- <
- is_interval_set_right_combinable<GuideT, CompanionT>
- , is_interval_map_right_intra_combinable<GuideT, CompanionT>
- >::value)
- );
- };
- template<class GuideT, class CompanionT>
- struct is_right_inter_combinable
- {
- typedef is_right_inter_combinable<GuideT, CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_
- <
- is_interval_set_right_combinable<GuideT, CompanionT>
- , is_interval_map_right_inter_combinable<GuideT, CompanionT>
- >::value)
- );
- };
- template<class GuideT, class IntervalSetT>
- struct combines_right_to_interval_set
- {
- typedef combines_right_to_interval_set<GuideT, IntervalSetT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (is_concept_combinable<is_interval_container, is_interval_set,
- GuideT, IntervalSetT>::value)
- );
- };
- template<class GuideT, class IntervalMapT>
- struct combines_right_to_interval_map
- {
- typedef combines_right_to_interval_map<GuideT, IntervalMapT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (is_concept_compatible<is_interval_map, GuideT, IntervalMapT>::value) );
- };
- template<class GuideT, class IntervalContainerT>
- struct combines_right_to_interval_container
- {
- typedef combines_right_to_interval_container<GuideT, IntervalContainerT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_<combines_right_to_interval_set<GuideT, IntervalContainerT>,
- combines_right_to_interval_map<GuideT, IntervalContainerT> >::value)
- );
- };
- //------------------------------------------------------------------------------
- //- segmentational_fineness
- //------------------------------------------------------------------------------
- template<class Type> struct unknown_fineness
- {
- typedef unknown_fineness<Type> type;
- static const int value = 0;
- };
- template<class Type> struct known_fineness
- {
- typedef known_fineness<Type> type;
- static const int value = Type::fineness;
- };
- template<class Type>struct segmentational_fineness
- {
- typedef segmentational_fineness<Type> type;
- static const int value =
- mpl::if_<is_interval_container<Type>,
- known_fineness<Type>,
- unknown_fineness<Type>
- >::type::value;
- };
- //------------------------------------------------------------------------------
- // is_interval_set_companion
- //------------------------------------------------------------------------------
- // CompanionT is either an interval_set or a derivative of set level:
- // element_type=domain_type, segment_type=interval_type
- template<class GuideT, class CompanionT> struct is_interval_set_companion
- {
- typedef is_interval_set_companion<GuideT,CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_
- <
- combines_right_to_interval_set<GuideT,CompanionT>
- , is_interval_set_derivative<GuideT,CompanionT>
- >::value)
- );
- };
- //------------------------------------------------------------------------------
- // is_interval_map_companion
- //------------------------------------------------------------------------------
- template<class GuideT, class CompanionT> struct is_interval_map_companion
- {
- typedef is_interval_map_companion<GuideT,CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_
- <
- combines_right_to_interval_map<GuideT,CompanionT>
- , is_interval_map_derivative<GuideT,CompanionT>
- >::value)
- );
- };
- //------------------------------------------------------------------------------
- //- is_coarser_interval_{set,map}_companion
- //------------------------------------------------------------------------------
- template<class GuideT, class CompanionT>
- struct is_coarser_interval_set_companion
- {
- typedef is_coarser_interval_set_companion<GuideT, CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::and_
- <
- is_interval_set_companion<GuideT, CompanionT>
- , mpl::bool_<( segmentational_fineness<GuideT>::value
- > segmentational_fineness<CompanionT>::value)>
- >::value)
- );
- };
- template<class GuideT, class CompanionT>
- struct is_coarser_interval_map_companion
- {
- typedef is_coarser_interval_map_companion<GuideT, CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::and_
- <
- is_interval_map_companion<GuideT, CompanionT>
- , mpl::bool_<( segmentational_fineness<GuideT>::value
- > segmentational_fineness<CompanionT>::value)>
- >::value)
- );
- };
- //------------------------------------------------------------------------------
- // is_binary_interval_{set,map}_combinable
- //------------------------------------------------------------------------------
- template<class GuideT, class CompanionT>
- struct is_binary_interval_set_combinable
- {
- typedef is_binary_interval_set_combinable<GuideT,CompanionT> type;
- static const int value =
- mpl::and_< is_interval_set<GuideT>
- , is_coarser_interval_set_companion<GuideT, CompanionT>
- >::value;
- };
- template<class GuideT, class CompanionT>
- struct is_binary_interval_map_combinable
- {
- typedef is_binary_interval_map_combinable<GuideT,CompanionT> type;
- static const int value =
- mpl::and_< is_interval_map<GuideT>
- , is_coarser_interval_map_companion<GuideT, CompanionT>
- >::value;
- };
- template<class GuideT, class CompanionT>
- struct is_binary_intra_combinable
- {
- typedef is_binary_intra_combinable<GuideT,CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_<is_binary_interval_set_combinable<GuideT, CompanionT>,
- is_binary_interval_map_combinable<GuideT, CompanionT>
- >::value)
- );
- };
- template<class GuideT, class CompanionT>
- struct is_binary_cross_combinable
- {
- typedef is_binary_cross_combinable<GuideT,CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::and_
- < is_interval_map<GuideT>
- , mpl::or_< is_coarser_interval_map_companion<GuideT, CompanionT>
- , is_interval_set_companion<GuideT, CompanionT> >
- >::value)
- );
- };
- template<class GuideT, class CompanionT>
- struct is_binary_inter_combinable
- {
- typedef is_binary_inter_combinable<GuideT,CompanionT> type;
- BOOST_STATIC_CONSTANT(bool, value =
- (mpl::or_
- <
- mpl::and_<is_interval_map<GuideT>,
- is_binary_cross_combinable<GuideT, CompanionT> >
- , mpl::and_<is_interval_set<GuideT>,
- is_binary_intra_combinable<GuideT, CompanionT> >
- >::value)
- );
- };
- }} // namespace icl boost
- #endif
|