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
11 #include <boost/icl/detail/concept_check.hpp>
12 #include <boost/icl/concept/interval.hpp>
13 #include <boost/icl/type_traits/value_size.hpp>
14 #include <boost/icl/type_traits/type_to_string.hpp>
16 namespace boost{namespace icl
19 template <class DomainT,
20 ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)>
24 typedef closed_interval<DomainT,Compare> type;
25 typedef DomainT domain_type;
26 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
29 //==========================================================================
30 //= Construct, copy, destruct
31 //==========================================================================
32 /** Default constructor; yields an empty interval <tt>[0,0)</tt>. */
34 : _lwb(unit_element<DomainT>::value()), _upb(identity_element<DomainT>::value())
36 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
37 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
38 BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));
41 //NOTE: Compiler generated copy constructor is used
43 /** Constructor for a closed singleton interval <tt>[val,val]</tt> */
44 explicit closed_interval(const DomainT& val)
45 : _lwb(val), _upb(val)
47 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
48 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
49 BOOST_STATIC_ASSERT((!icl::is_continuous<DomainT>::value));
52 /** Interval from <tt>low</tt> to <tt>up</tt> with bounds <tt>bounds</tt> */
53 closed_interval(const DomainT& low, const DomainT& up) :
56 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
57 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
60 DomainT lower()const{ return _lwb; }
61 DomainT upper()const{ return _upb; }
63 DomainT first()const{ return _lwb; }
64 DomainT last() const{ return _upb; }
72 //==============================================================================
73 //=T closed_interval -> concept intervals
74 //==============================================================================
75 template<class DomainT, ICL_COMPARE Compare>
76 struct interval_traits< icl::closed_interval<DomainT, Compare> >
78 typedef DomainT domain_type;
79 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
80 typedef icl::closed_interval<DomainT, Compare> interval_type;
82 static interval_type construct(const domain_type& lo, const domain_type& up)
84 return interval_type(lo, up);
87 static domain_type lower(const interval_type& inter_val){ return inter_val.lower(); };
88 static domain_type upper(const interval_type& inter_val){ return inter_val.upper(); };
91 //==============================================================================
93 //==============================================================================
94 template <class DomainT, ICL_COMPARE Compare>
95 struct interval_bound_type< closed_interval<DomainT,Compare> >
97 typedef interval_bound_type type;
98 BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_closed);
101 template <class DomainT, ICL_COMPARE Compare>
102 struct type_to_string<icl::closed_interval<DomainT,Compare> >
104 static std::string apply()
105 { return "[I]<"+ type_to_string<DomainT>::apply() +">"; }
108 template<class DomainT>
109 struct value_size<icl::closed_interval<DomainT> >
111 static std::size_t apply(const icl::closed_interval<DomainT>&)
115 }} // namespace icl boost