1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2010-2010: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENCE.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #ifndef BOOST_ICL_CLOSED_INTERVAL_HPP_JOFA_100324
9 #define BOOST_ICL_CLOSED_INTERVAL_HPP_JOFA_100324
12 #include <boost/static_assert.hpp>
13 #include <boost/concept/assert.hpp>
14 #include <boost/icl/detail/concept_check.hpp>
15 #include <boost/icl/concept/interval.hpp>
16 #include <boost/icl/type_traits/succ_pred.hpp>
17 #include <boost/icl/type_traits/value_size.hpp>
18 #include <boost/icl/type_traits/type_to_string.hpp>
20 namespace boost{namespace icl
23 template <class DomainT,
24 ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)>
28 typedef closed_interval<DomainT,Compare> type;
29 typedef DomainT domain_type;
30 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
33 //==========================================================================
34 //= Construct, copy, destruct
35 //==========================================================================
36 /** Default constructor; yields an empty interval <tt>[0,0)</tt>. */
38 : _lwb(unit_element<DomainT>::value()), _upb(identity_element<DomainT>::value())
40 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
41 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
42 BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));
45 //NOTE: Compiler generated copy constructor is used
47 /** Constructor for a closed singleton interval <tt>[val,val]</tt> */
48 explicit closed_interval(const DomainT& val)
49 : _lwb(val), _upb(val)
51 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
52 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
53 BOOST_STATIC_ASSERT((!icl::is_continuous<DomainT>::value));
56 /** Interval from <tt>low</tt> to <tt>up</tt> with bounds <tt>bounds</tt> */
57 closed_interval(const DomainT& low, const DomainT& up) :
60 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
61 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
64 DomainT lower()const{ return _lwb; }
65 DomainT upper()const{ return _upb; }
67 DomainT first()const{ return _lwb; }
68 DomainT last() const{ return _upb; }
76 //==============================================================================
77 //=T closed_interval -> concept intervals
78 //==============================================================================
79 template<class DomainT, ICL_COMPARE Compare>
80 struct interval_traits< icl::closed_interval<DomainT, Compare> >
82 typedef DomainT domain_type;
83 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
84 typedef icl::closed_interval<DomainT, Compare> interval_type;
86 static interval_type construct(const domain_type& lo, const domain_type& up)
88 return interval_type(lo, up);
91 static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); }
92 static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); }
95 //==============================================================================
97 //==============================================================================
98 template <class DomainT, ICL_COMPARE Compare>
99 struct interval_bound_type< closed_interval<DomainT,Compare> >
101 typedef interval_bound_type type;
102 BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_closed);
105 template <class DomainT, ICL_COMPARE Compare>
106 struct type_to_string<icl::closed_interval<DomainT,Compare> >
108 static std::string apply()
109 { return "[I]<"+ type_to_string<DomainT>::apply() +">"; }
112 template<class DomainT>
113 struct value_size<icl::closed_interval<DomainT> >
115 static std::size_t apply(const icl::closed_interval<DomainT>&)
119 }} // namespace icl boost