Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:23

0001 /*-----------------------------------------------------------------------------+
0002 Copyright (c) 2010-2010: Joachim Faulhaber
0003 +------------------------------------------------------------------------------+
0004    Distributed under the Boost Software License, Version 1.0.
0005       (See accompanying file LICENCE.txt or copy at
0006            http://www.boost.org/LICENSE_1_0.txt)
0007 +-----------------------------------------------------------------------------*/
0008 #ifndef BOOST_ICL_RIGHT_OPEN_INTERVAL_HPP_JOFA_100323
0009 #define BOOST_ICL_RIGHT_OPEN_INTERVAL_HPP_JOFA_100323
0010 
0011 #include <functional>
0012 #include <boost/static_assert.hpp>
0013 #include <boost/concept/assert.hpp>
0014 #include <boost/icl/detail/concept_check.hpp>
0015 #include <boost/icl/concept/interval.hpp>
0016 #include <boost/icl/type_traits/succ_pred.hpp>
0017 #include <boost/icl/type_traits/value_size.hpp>
0018 #include <boost/icl/type_traits/type_to_string.hpp>
0019 
0020 namespace boost{namespace icl
0021 {
0022 
0023 template <class DomainT,
0024           ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)>
0025 class right_open_interval
0026 {
0027 public:
0028     typedef right_open_interval<DomainT,Compare> type;
0029     typedef DomainT domain_type;
0030     typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
0031 
0032 public:
0033     //==========================================================================
0034     //= Construct, copy, destruct
0035     //==========================================================================
0036     /** Default constructor; yields an empty interval <tt>[0,0)</tt>. */
0037     right_open_interval()
0038         : _lwb(identity_element<DomainT>::value()), _upb(identity_element<DomainT>::value())
0039     {
0040         BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
0041         BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
0042     }
0043 
0044     //NOTE: Compiler generated copy constructor is used
0045 
0046     /** Constructor for a singleton interval <tt>[val,val+1)</tt> */
0047     explicit right_open_interval(const DomainT& val)
0048         : _lwb(val), _upb(icl::successor<DomainT,domain_compare>::apply(val))
0049     {
0050         BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
0051         BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
0052         // Only for discrete types this ctor creates an interval containing
0053         // a single element only.
0054         BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));
0055     }
0056 
0057     /** Interval from <tt>low</tt> to <tt>up</tt> with bounds <tt>bounds</tt> */
0058     right_open_interval(const DomainT& low, const DomainT& up) :
0059         _lwb(low), _upb(up)
0060     {
0061         BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
0062         BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
0063     }
0064 
0065     domain_type lower()const{ return _lwb; }
0066     domain_type upper()const{ return _upb; }
0067 
0068 private:
0069     domain_type _lwb;
0070     domain_type _upb;
0071 };
0072 
0073 //==============================================================================
0074 //=T right_open_interval -> concept intervals
0075 //==============================================================================
0076 template<class DomainT, ICL_COMPARE Compare>
0077 struct interval_traits< icl::right_open_interval<DomainT, Compare> >
0078 {
0079     typedef DomainT domain_type;
0080     typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
0081     typedef icl::right_open_interval<DomainT, Compare> interval_type;
0082 
0083     static interval_type construct(const domain_type& lo, const domain_type& up)
0084     {
0085         return interval_type(lo, up);
0086     }
0087 
0088     static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); }
0089     static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); }
0090 };
0091 
0092 
0093 //==============================================================================
0094 //= Type traits
0095 //==============================================================================
0096 template <class DomainT, ICL_COMPARE Compare>
0097 struct interval_bound_type< right_open_interval<DomainT,Compare> >
0098 {
0099     typedef interval_bound_type type;
0100     BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_right_open);
0101 };
0102 
0103 template <class DomainT, ICL_COMPARE Compare>
0104 struct type_to_string<icl::right_open_interval<DomainT,Compare> >
0105 {
0106     static std::string apply()
0107     { return "[I)<"+ type_to_string<DomainT>::apply() +">"; }
0108 };
0109 
0110 template<class DomainT, ICL_COMPARE Compare>
0111 struct value_size<icl::right_open_interval<DomainT,Compare> >
0112 {
0113     static std::size_t apply(const icl::right_open_interval<DomainT>&)
0114     { return 2; }
0115 };
0116 
0117 }} // namespace icl boost
0118 
0119 #endif