comparison DEPENDENCIES/generic/include/boost/icl/open_interval.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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_OPEN_INTERVAL_HPP_JOFA_100930
9 #define BOOST_ICL_OPEN_INTERVAL_HPP_JOFA_100930
10
11 #include <functional>
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>
16
17 namespace boost{namespace icl
18 {
19
20 template <class DomainT,
21 ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)>
22 class open_interval
23 {
24 public:
25 typedef open_interval<DomainT,Compare> type;
26 typedef DomainT domain_type;
27 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
28
29 public:
30 //==========================================================================
31 //= Construct, copy, destruct
32 //==========================================================================
33 /** Default constructor; yields an empty interval <tt>(0,0)</tt>. */
34 open_interval()
35 : _lwb(identity_element<DomainT>::value()), _upb(identity_element<DomainT>::value())
36 {
37 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
38 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
39 }
40
41 //NOTE: Compiler generated copy constructor is used
42
43 /** Constructor for an open singleton interval <tt>(val-1,val+1)</tt> */
44 explicit open_interval(const DomainT& val)
45 : _lwb(pred(val)), _upb(succ(val))
46 {
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) ));
54 }
55
56 /** Interval from <tt>low</tt> to <tt>up</tt> with bounds <tt>bounds</tt> */
57 open_interval(const DomainT& low, const DomainT& up) :
58 _lwb(low), _upb(up)
59 {
60 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
61 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
62 }
63
64 DomainT lower()const{ return _lwb; }
65 DomainT upper()const{ return _upb; }
66
67 private:
68 DomainT _lwb;
69 DomainT _upb;
70 };
71
72 //==============================================================================
73 //=T open_interval -> concept intervals
74 //==============================================================================
75 template<class DomainT, ICL_COMPARE Compare>
76 struct interval_traits< icl::open_interval<DomainT, Compare> >
77 {
78 typedef DomainT domain_type;
79 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
80 typedef icl::open_interval<DomainT, Compare> interval_type;
81
82 static interval_type construct(const domain_type& lo, const domain_type& up)
83 {
84 return interval_type(lo, up);
85 }
86
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(); };
89 };
90
91
92 //==============================================================================
93 //= Type traits
94 //==============================================================================
95 template <class DomainT, ICL_COMPARE Compare>
96 struct interval_bound_type< open_interval<DomainT,Compare> >
97 {
98 typedef interval_bound_type type;
99 BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_open);
100 };
101
102 template <class DomainT, ICL_COMPARE Compare>
103 struct type_to_string<icl::open_interval<DomainT,Compare> >
104 {
105 static std::string apply()
106 { return "(I)<"+ type_to_string<DomainT>::apply() +">"; }
107 };
108
109 template<class DomainT, ICL_COMPARE Compare>
110 struct value_size<icl::open_interval<DomainT,Compare> >
111 {
112 static std::size_t apply(const icl::open_interval<DomainT>&)
113 { return 2; }
114 };
115
116 }} // namespace icl boost
117
118 #endif
119