/*-----------------------------------------------------------------------------+ Copyright (c) 2010-2010: 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_RIGHT_OPEN_INTERVAL_HPP_JOFA_100323 #define BOOST_ICL_RIGHT_OPEN_INTERVAL_HPP_JOFA_100323 #include #include #include #include #include #include namespace boost{namespace icl { template class right_open_interval { public: typedef right_open_interval type; typedef DomainT domain_type; typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare; public: //========================================================================== //= Construct, copy, destruct //========================================================================== /** Default constructor; yields an empty interval [0,0). */ right_open_interval() : _lwb(identity_element::value()), _upb(identity_element::value()) { BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept)); BOOST_CONCEPT_ASSERT((LessThanComparableConcept)); } //NOTE: Compiler generated copy constructor is used /** Constructor for a singleton interval [val,val+1) */ explicit right_open_interval(const DomainT& val) : _lwb(val), _upb(icl::successor::apply(val)) { BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept)); BOOST_CONCEPT_ASSERT((LessThanComparableConcept)); // Only for discrete types this ctor creates an interval containing // a single element only. BOOST_STATIC_ASSERT((icl::is_discrete::value)); } /** Interval from low to up with bounds bounds */ right_open_interval(const DomainT& low, const DomainT& up) : _lwb(low), _upb(up) { BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept)); BOOST_CONCEPT_ASSERT((LessThanComparableConcept)); } domain_type lower()const{ return _lwb; } domain_type upper()const{ return _upb; } private: domain_type _lwb; domain_type _upb; }; //============================================================================== //=T right_open_interval -> concept intervals //============================================================================== template struct interval_traits< icl::right_open_interval > { typedef DomainT domain_type; typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare; typedef icl::right_open_interval interval_type; static interval_type construct(const domain_type& lo, const domain_type& up) { return interval_type(lo, up); } static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); } static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); } }; //============================================================================== //= Type traits //============================================================================== template struct interval_bound_type< right_open_interval > { typedef interval_bound_type type; BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_right_open); }; template struct type_to_string > { static std::string apply() { return "[I)<"+ type_to_string::apply() +">"; } }; template struct value_size > { static std::size_t apply(const icl::right_open_interval&) { return 2; } }; }} // namespace icl boost #endif