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_LEFT_OPEN_INTERVAL_HPP_JOFA_100930
9 #define BOOST_ICL_LEFT_OPEN_INTERVAL_HPP_JOFA_100930
12 #include <boost/concept/assert.hpp>
13 #include <boost/icl/concept/interval.hpp>
14 #include <boost/icl/type_traits/value_size.hpp>
15 #include <boost/icl/type_traits/type_to_string.hpp>
17 namespace boost{namespace icl
20 template <class DomainT,
21 ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)>
22 class left_open_interval
25 typedef left_open_interval<DomainT,Compare> type;
26 typedef DomainT domain_type;
27 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
30 //==========================================================================
31 //= Construct, copy, destruct
32 //==========================================================================
33 /** Default constructor; yields an empty interval <tt>(0,0]</tt>. */
35 : _lwb(identity_element<DomainT>::value()), _upb(identity_element<DomainT>::value())
37 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
38 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
41 //NOTE: Compiler generated copy constructor is used
43 /** Constructor for a left-open singleton interval <tt>(val-1,val]</tt> */
44 explicit left_open_interval(const DomainT& val)
45 : _lwb(predecessor<DomainT,domain_compare>::apply(val)), _upb(val)
47 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
48 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
49 // Only for discrete types this ctor creates an interval containing
50 // a single element only.
51 BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));
52 BOOST_ASSERT((numeric_minimum<DomainT, domain_compare, is_numeric<DomainT>::value >
53 ::is_less_than(val) ));
56 /** Interval from <tt>low</tt> to <tt>up</tt> with bounds <tt>bounds</tt> */
57 left_open_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; }
72 //==============================================================================
73 //=T left_open_interval -> concept intervals
74 //==============================================================================
75 template<class DomainT, ICL_COMPARE Compare>
76 struct interval_traits< icl::left_open_interval<DomainT, Compare> >
78 typedef DomainT domain_type;
79 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
80 typedef icl::left_open_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(); };
92 //==============================================================================
94 //==============================================================================
95 template <class DomainT, ICL_COMPARE Compare>
96 struct interval_bound_type< left_open_interval<DomainT,Compare> >
98 typedef interval_bound_type type;
99 BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_left_open);
102 template <class DomainT, ICL_COMPARE Compare>
103 struct type_to_string<icl::left_open_interval<DomainT,Compare> >
105 static std::string apply()
106 { return "(I]<"+ type_to_string<DomainT>::apply() +">"; }
109 template<class DomainT, ICL_COMPARE Compare>
110 struct value_size<icl::left_open_interval<DomainT,Compare> >
112 static std::size_t apply(const icl::left_open_interval<DomainT>&)
116 }} // namespace icl boost