Chris@16: /*-----------------------------------------------------------------------------+ Chris@16: Copyright (c) 2010-2010: Joachim Faulhaber Chris@16: +------------------------------------------------------------------------------+ Chris@16: Distributed under the Boost Software License, Version 1.0. Chris@16: (See accompanying file LICENCE.txt or copy at Chris@16: http://www.boost.org/LICENSE_1_0.txt) Chris@16: +-----------------------------------------------------------------------------*/ Chris@16: #ifndef BOOST_ICL_RIGHT_OPEN_INTERVAL_HPP_JOFA_100323 Chris@16: #define BOOST_ICL_RIGHT_OPEN_INTERVAL_HPP_JOFA_100323 Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost{namespace icl Chris@16: { Chris@16: Chris@16: template Chris@16: class right_open_interval Chris@16: { Chris@16: public: Chris@16: typedef right_open_interval type; Chris@16: typedef DomainT domain_type; Chris@16: typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare; Chris@16: Chris@16: public: Chris@16: //========================================================================== Chris@16: //= Construct, copy, destruct Chris@16: //========================================================================== Chris@16: /** Default constructor; yields an empty interval [0,0). */ Chris@16: right_open_interval() Chris@16: : _lwb(identity_element::value()), _upb(identity_element::value()) Chris@16: { Chris@16: BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept)); Chris@16: BOOST_CONCEPT_ASSERT((LessThanComparableConcept)); Chris@16: } Chris@16: Chris@16: //NOTE: Compiler generated copy constructor is used Chris@16: Chris@16: /** Constructor for a singleton interval [val,val+1) */ Chris@16: explicit right_open_interval(const DomainT& val) Chris@16: : _lwb(val), _upb(icl::successor::apply(val)) Chris@16: { Chris@16: BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept)); Chris@16: BOOST_CONCEPT_ASSERT((LessThanComparableConcept)); Chris@16: // Only for discrete types this ctor creates an interval containing Chris@16: // a single element only. Chris@16: BOOST_STATIC_ASSERT((icl::is_discrete::value)); Chris@16: } Chris@16: Chris@16: /** Interval from low to up with bounds bounds */ Chris@16: right_open_interval(const DomainT& low, const DomainT& up) : Chris@16: _lwb(low), _upb(up) Chris@16: { Chris@16: BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept)); Chris@16: BOOST_CONCEPT_ASSERT((LessThanComparableConcept)); Chris@16: } Chris@16: Chris@16: domain_type lower()const{ return _lwb; } Chris@16: domain_type upper()const{ return _upb; } Chris@16: Chris@16: private: Chris@16: domain_type _lwb; Chris@16: domain_type _upb; Chris@16: }; Chris@16: Chris@16: //============================================================================== Chris@16: //=T right_open_interval -> concept intervals Chris@16: //============================================================================== Chris@16: template Chris@16: struct interval_traits< icl::right_open_interval > Chris@16: { Chris@16: typedef DomainT domain_type; Chris@16: typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare; Chris@16: typedef icl::right_open_interval interval_type; Chris@16: Chris@16: static interval_type construct(const domain_type& lo, const domain_type& up) Chris@16: { Chris@16: return interval_type(lo, up); Chris@16: } Chris@16: Chris@16: static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); }; Chris@16: static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); }; Chris@16: }; Chris@16: Chris@16: Chris@16: //============================================================================== Chris@16: //= Type traits Chris@16: //============================================================================== Chris@16: template Chris@16: struct interval_bound_type< right_open_interval > Chris@16: { Chris@16: typedef interval_bound_type type; Chris@16: BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_right_open); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct type_to_string > Chris@16: { Chris@16: static std::string apply() Chris@16: { return "[I)<"+ type_to_string::apply() +">"; } Chris@16: }; Chris@16: Chris@16: template Chris@16: struct value_size > Chris@16: { Chris@16: static std::size_t apply(const icl::right_open_interval&) Chris@16: { return 2; } Chris@16: }; Chris@16: Chris@16: }} // namespace icl boost Chris@16: Chris@16: #endif Chris@16: