diff --git a/include/boost/range/concepts.hpp b/include/boost/range/concepts.hpp index 5faf2de..d9c122f 100755 --- a/include/boost/range/concepts.hpp +++ b/include/boost/range/concepts.hpp @@ -13,8 +13,8 @@ #include #include -#include -#include +#include +#include /*! * \file @@ -57,10 +57,10 @@ namespace boost { //! Check if a type T models the SinglePassRange range concept. template - struct SinglePassRangeConcept { - typedef typename range_value::type range_value; - typedef typename range_iterator::type range_iterator; - //typedef typename range_iterator::type range_const_iterator; + struct SinglePassRangeConcept + { + typedef typename range_iterator::type range_const_iterator; + typedef typename range_iterator::type range_iterator; void constraints() { @@ -71,23 +71,24 @@ namespace boost { >(); i = boost::begin(a); i = boost::end(a); - b = boost::empty(a); const_constraints(a); } + void const_constraints(const T& a) { - //ci = boost::begin(a); - //ci = boost::end(a); + ci = boost::begin(a); + ci = boost::end(a); } T a; range_iterator i; + range_const_iterator ci; bool b; }; //! Check if a type T models the ForwardRange range concept. template - struct ForwardRangeConcept { - typedef typename range_difference::type range_difference; + struct ForwardRangeConcept + { void constraints() { function_requires< @@ -103,8 +104,8 @@ namespace boost { //! Check if a type T models the BidirectionalRange range concept. template - struct BidirectionalRangeConcept { - typedef typename range_reverse_iterator::type range_reverse_iterator; + struct BidirectionalRangeConcept + { void constraints() { function_requires< @@ -115,24 +116,13 @@ namespace boost { typename range_iterator::type > >(); - i = boost::rbegin(a); - i = boost::rend(a); - const_constraints(a); - } - void const_constraints(const T& a) - { - //ci = boost::rbegin(a); - //ci = boost::rend(a); } - T a; - range_reverse_iterator i; }; //! Check if a type T models the RandomAccessRange range concept. template - struct RandomAccessRangeConcept { - typedef typename range_size::type range_size; - + struct RandomAccessRangeConcept + { void constraints() { function_requires< @@ -143,12 +133,7 @@ namespace boost { typename range_iterator::type > >(); - - s = boost::size(a); } - - T a; - range_size s; }; } // namespace boost diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index bcead14..9df24c0 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -73,7 +73,7 @@ namespace boost template< class Left, class Right > inline bool equal( const Left& l, const Right& r ) { - typedef BOOST_DEDUCED_TYPENAME boost::range_size::type sz_type; + typedef BOOST_DEDUCED_TYPENAME boost::range_difference::type sz_type; sz_type l_size = boost::size( l ), r_size = boost::size( r ); @@ -166,20 +166,7 @@ namespace boost , singular( true ) #endif { } -/* -#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) - iterator_range( this_type r ) : - : m_Begin(r.begin()), m_End(r.end()) - { } - - this_type& operator=( this_type r ) - { - m_Begin = r.begin(); - m_End = r.end(); - return *this; - } -#endif -*/ + //! Constructor from a pair of iterators template< class Iterator > iterator_range( Iterator Begin, Iterator End ) : @@ -283,7 +270,7 @@ namespace boost return m_End; } - size_type size() const + difference_type size() const { BOOST_ASSERT( !is_singular() ); return m_End - m_Begin; @@ -351,9 +338,9 @@ namespace boost return *--last; } - reference operator[]( size_type at ) const + reference operator[]( difference_type at ) const { - BOOST_ASSERT( at < size() ); + BOOST_ASSERT( at >= 0 && at < size() ); return m_Begin[at]; } @@ -362,9 +349,9 @@ namespace boost // fails because it returns by reference. Therefore // operator()() is provided for these cases. // - value_type operator()( size_type at ) const + value_type operator()( difference_type at ) const { - BOOST_ASSERT( at < size() ); + BOOST_ASSERT( at >= 0 && at < size() ); return m_Begin[at]; } diff --git a/include/boost/range/size.hpp b/include/boost/range/size.hpp index eb021a5..311a692 100755 --- a/include/boost/range/size.hpp +++ b/include/boost/range/size.hpp @@ -17,14 +17,17 @@ #include #include -#include +#include +#include namespace boost { template< class T > - inline BOOST_DEDUCED_TYPENAME range_size::type size( const T& r ) + inline BOOST_DEDUCED_TYPENAME range_difference::type size( const T& r ) { + BOOST_ASSERT( (boost::end( r ) - boost::begin( r )) >= 0 && + "reachability invariant broken!" ); return boost::end( r ) - boost::begin( r ); } diff --git a/include/boost/range/sub_range.hpp b/include/boost/range/sub_range.hpp index 30daaea..802454b 100755 --- a/include/boost/range/sub_range.hpp +++ b/include/boost/range/sub_range.hpp @@ -38,6 +38,7 @@ namespace boost typedef BOOST_DEDUCED_TYPENAME range_iterator::type const_iterator; typedef BOOST_DEDUCED_TYPENAME range_difference::type difference_type; typedef BOOST_DEDUCED_TYPENAME range_size::type size_type; + typedef BOOST_DEDUCED_TYPENAME base::reference reference; public: sub_range() : base() @@ -100,11 +101,11 @@ namespace boost const_iterator begin() const { return base::begin(); } iterator end() { return base::end(); } const_iterator end() const { return base::end(); } - size_type size() const { return base::size(); } + difference_type size() const { return base::size(); } public: // convenience - value_type& front() + reference front() { return base::front(); } @@ -114,7 +115,7 @@ namespace boost return base::front(); } - value_type& back() + reference back() { return base::back(); } @@ -124,12 +125,12 @@ namespace boost return base::back(); } - value_type& operator[]( size_type sz ) + reference operator[]( difference_type sz ) { return base::operator[](sz); } - const value_type& operator[]( size_type sz ) const + const value_type& operator[]( difference_type sz ) const { return base::operator[](sz); }