]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/icl/closed_interval.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / icl / closed_interval.hpp
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
10
11 #include <functional>
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>
19
20 namespace boost{namespace icl
21 {
22
23 template <class DomainT,
24 ICL_COMPARE Compare = ICL_COMPARE_INSTANCE(ICL_COMPARE_DEFAULT, DomainT)>
25 class closed_interval
26 {
27 public:
28 typedef closed_interval<DomainT,Compare> type;
29 typedef DomainT domain_type;
30 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
31
32 public:
33 //==========================================================================
34 //= Construct, copy, destruct
35 //==========================================================================
36 /** Default constructor; yields an empty interval <tt>[0,0)</tt>. */
37 closed_interval()
38 : _lwb(unit_element<DomainT>::value()), _upb(identity_element<DomainT>::value())
39 {
40 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
41 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
42 BOOST_STATIC_ASSERT((icl::is_discrete<DomainT>::value));
43 }
44
45 //NOTE: Compiler generated copy constructor is used
46
47 /** Constructor for a closed singleton interval <tt>[val,val]</tt> */
48 explicit closed_interval(const DomainT& val)
49 : _lwb(val), _upb(val)
50 {
51 BOOST_CONCEPT_ASSERT((DefaultConstructibleConcept<DomainT>));
52 BOOST_CONCEPT_ASSERT((LessThanComparableConcept<DomainT>));
53 BOOST_STATIC_ASSERT((!icl::is_continuous<DomainT>::value));
54 }
55
56 /** Interval from <tt>low</tt> to <tt>up</tt> with bounds <tt>bounds</tt> */
57 closed_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 DomainT first()const{ return _lwb; }
68 DomainT last() const{ return _upb; }
69
70 private:
71 DomainT _lwb;
72 DomainT _upb;
73 };
74
75
76 //==============================================================================
77 //=T closed_interval -> concept intervals
78 //==============================================================================
79 template<class DomainT, ICL_COMPARE Compare>
80 struct interval_traits< icl::closed_interval<DomainT, Compare> >
81 {
82 typedef DomainT domain_type;
83 typedef ICL_COMPARE_DOMAIN(Compare,DomainT) domain_compare;
84 typedef icl::closed_interval<DomainT, Compare> interval_type;
85
86 static interval_type construct(const domain_type& lo, const domain_type& up)
87 {
88 return interval_type(lo, up);
89 }
90
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(); }
93 };
94
95 //==============================================================================
96 //= Type traits
97 //==============================================================================
98 template <class DomainT, ICL_COMPARE Compare>
99 struct interval_bound_type< closed_interval<DomainT,Compare> >
100 {
101 typedef interval_bound_type type;
102 BOOST_STATIC_CONSTANT(bound_type, value = interval_bounds::static_closed);
103 };
104
105 template <class DomainT, ICL_COMPARE Compare>
106 struct type_to_string<icl::closed_interval<DomainT,Compare> >
107 {
108 static std::string apply()
109 { return "[I]<"+ type_to_string<DomainT>::apply() +">"; }
110 };
111
112 template<class DomainT>
113 struct value_size<icl::closed_interval<DomainT> >
114 {
115 static std::size_t apply(const icl::closed_interval<DomainT>&)
116 { return 2; }
117 };
118
119 }} // namespace icl boost
120
121 #endif