diff --git a/include/boost/range/begin.hpp b/include/boost/range/begin.hpp index dce7052..a4e1398 100755 --- a/include/boost/range/begin.hpp +++ b/include/boost/range/begin.hpp @@ -30,7 +30,7 @@ namespace range { ////////////////////////////////////////////////////////////////////// - // default + // primary template ////////////////////////////////////////////////////////////////////// template< typename C > @@ -106,7 +106,28 @@ namespace range } // namespace 'range' -using range::begin; + +template< class T > +inline BOOST_DEDUCED_TYPENAME iterator_of::type begin( T& r ) +{ +#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + using range::begin; + return begin( r ); +#else + return range::begin( r ); +#endif +} + +template< class T > +inline BOOST_DEDUCED_TYPENAME const_iterator_of::type begin( const T& r ) +{ +#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + using range::begin; + return begin( r ); +#else + return range::begin( r ); +#endif +} } // namespace boost diff --git a/include/boost/range/empty.hpp b/include/boost/range/empty.hpp index b48ecda..3be81b2 100755 --- a/include/boost/range/empty.hpp +++ b/include/boost/range/empty.hpp @@ -25,10 +25,11 @@ namespace boost { -namespace range +namespace range { + ////////////////////////////////////////////////////////////////////// - // default + // primary template ////////////////////////////////////////////////////////////////////// template< typename C > @@ -53,7 +54,16 @@ namespace range } // namespace 'range' -using range::empty; +template< class T > +inline bool empty( const T& r ) +{ +#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + using range::empty; + return empty( r ); +#else + return range::empty( r ); +#endif +} } // namepace 'boost' diff --git a/include/boost/range/end.hpp b/include/boost/range/end.hpp index f4244a6..d9d9fb3 100755 --- a/include/boost/range/end.hpp +++ b/include/boost/range/end.hpp @@ -31,7 +31,7 @@ namespace range { ////////////////////////////////////////////////////////////////////// - // default + // primary template ////////////////////////////////////////////////////////////////////// template< typename C > @@ -106,7 +106,27 @@ namespace range } // namespace 'range' -using range::end; +template< class T > +inline BOOST_DEDUCED_TYPENAME iterator_of::type end( T& r ) +{ +#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + using range::end; + return end( r ); +#else + return range::end( r ); +#endif +} + +template< class T > +inline BOOST_DEDUCED_TYPENAME const_iterator_of::type end( const T& r ) +{ +#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + using range::end; + return end( r ); +#else + return range::end( r ); +#endif +} } // namespace 'boost' diff --git a/include/boost/range/iterator_range.hpp b/include/boost/range/iterator_range.hpp index b701bd1..3e53f15 100755 --- a/include/boost/range/iterator_range.hpp +++ b/include/boost/range/iterator_range.hpp @@ -92,16 +92,16 @@ namespace boost { iterator_range( Range& r ) : m_Begin( begin_impl( r ) ), m_End( end_impl( r ) ) {} - template< class XRange > - iterator_range& operator=( XRange& r ) + template< class ForwardRange > + iterator_range& operator=( ForwardRange& r ) { m_Begin = begin_impl( r ); m_End = end_impl( r ); return *this; } - template< class XRange > - iterator_range& operator=( const XRange& r ) + template< class ForwardRange > + iterator_range& operator=( const ForwardRange& r ) { m_Begin = begin_impl( r ); m_End = end_impl( r ); @@ -140,16 +140,6 @@ namespace boost { return m_Begin == m_End; } - //! Swap - /*! - Swap two ranges - */ - void swap( iterator_range& Other ) - { - std::swap( m_Begin, Other.m_Begin ); - std::swap( m_End, Other.m_End ); - } - //! Safe bool conversion /*! Check whenever the range is empty. @@ -168,30 +158,32 @@ namespace boost { return empty() ? 0: &iterator_range::end; } - /* - inline operator t_type() const - { - return make_tuple( m_Begin, m_End ); - }*/ - private: // begin and end iterators IteratorT m_Begin; IteratorT m_End; private: - template< class XRange > - iterator end_impl( XRange& r ) const + template< class ForwardRange > + iterator end_impl( ForwardRange& r ) const { + #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) using boost::end; return end( r ); + #else + return boost::end( r ); + #endif } - template< class XRange > - iterator begin_impl( XRange& r ) const + template< class ForwardRange > + iterator begin_impl( ForwardRange& r ) const { + #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) using boost::begin; return begin( r ); + #else + return boost::begin( r ); + #endif } }; @@ -267,19 +259,19 @@ namespace boost { Construct an \c iterator_range from a \c Range containing the begin and end iterators. */ - template< class XRange > - inline iterator_range< BOOST_DEDUCED_TYPENAME iterator_of::type > - make_iterator_range( XRange& r ) + template< class ForwardRange > + inline iterator_range< BOOST_DEDUCED_TYPENAME iterator_of::type > + make_iterator_range( ForwardRange& r ) { - return iterator_range< BOOST_DEDUCED_TYPENAME iterator_of::type > + return iterator_range< BOOST_DEDUCED_TYPENAME iterator_of::type > ( r ); } - template< class XRange > - inline iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of::type > - make_iterator_range( const XRange& r ) + template< class ForwardRange > + inline iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of::type > + make_iterator_range( const ForwardRange& r ) { - return iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of::type > + return iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of::type > ( r ); } #endif diff --git a/test/TODO b/test/TODO index c3e46d2..58aba11 100644 --- a/test/TODO +++ b/test/TODO @@ -1,88 +1,6 @@ -1. ok. I should add something about extending the lib + how to rely on ADL. -2. | I'd prefer "primary specialization" to "default" in the comments. - ok. Is that the correct term? -3. A "specialization" of a template is the result of instantiating -it, so the more accurate term, as given in Vandevoorde and -Josuttis, is "primary template." +16. change header types.hpp to metafunctions.hpp -5. new intro: -"When writing generic code that works with Standard Library -containers, one often finds it desirable to extend that code to -work with other types that offer enough functionality to satisfy -the needs of the generic code, but in an altered form. For -example, raw arrays are often suitable for use with generic code -that works with containers, provided a suitable adapter is used. -Likewise, null terminated strings can be treated as containers of -characters, if suitably adapted. This library provides the means -to adapt Standard Library containers, null terminated strings, -std::pairs of iterators, and raw arrays, such that the same -generic code can work with them all." - -6. > | The Introduction is missing discussion of the use of namespace -> | scope functions to do what heretofore would be done via member -> | functions. Instead, the example and the sentence immediately -> | following it imply this change of syntax. -> -> Wouldn't it only duplicate stuff in the two links to CollectionCocept and ExternalConcepts? - -In a sense, yes, but what I'm proposing is a much abbreviated -form: - -"To allow generic code to work with objects that conform to the -ExternalCollectionConcept, this library provides a set of -namespace scope functions and type -generators that provide a standard interface for the required -functionality. Whereas one might write, "c.end()," to get the end -iterator from a Standard Library container, c, using this -library, it would be written, "boost::end(c)." This change in -syntax is necessary to make the same interface possible with the -other supported types such as null terminated strings." - -7. [boost-book-style]I like colors, so perhaps use the boost-book stylesheets? - -9. New range explanation: - -I'd say "Iterable" if we have to use an "-able" term. 24.1/7 -suggests to me that "Range" might be OK: - - Most of the library's algorithmic templates that operate on data - structures have interfaces that use ranges. A range is a pair of - iterators that designate the beginning and end of the computation. A - range [i, i) is an empty range; in general, a range [i, j) refers to - the elements in the data structure starting with the one pointed to - by i and up to but not including the one pointed to by j. Range [i, - j) is valid if and only if j is reachable from i. The result of the - application of functions in the library to invalid ranges is - undefined. - -10. Don't make empty part of the Range concept, but have a default - implementation begin() == end() + spccial treatment of char*, - -11. documentation: table with entities before other tables - -12. Example of how result_iterator is used, necessary: -when designing templated classes - -template struct widget { - typedef result_iterator_of iterator; -}; - -13. better external concepts: Thorsten Ottosen wrote: ->> The documentation that's provided I found ->> sufficient, it's just of a different style than other concept ->> documentation. -> -> ok. I don't think the definition of concepts are that much more -> elaborate. What could be -> much better is the example which could follow normal concept -> standards. Is that what you had in mind? - -Yes. - -14. Change example code for my_generic_replace. - -15. More concepts: random-access range: which have constant -time size(); Cpm matthews latest article. - -16. use typetraits for broken compilers...will probably make array work for buitins! +17. post-review question: should Range mean lowest common denominator? or + perhaps Forward Range? problem with not being explicit. + +18) change use of types.hpp -> metefunctions.hpp diff --git a/test/algorithm_example.cpp b/test/algorithm_example.cpp index 9ec315d..2b552f8 100755 --- a/test/algorithm_example.cpp +++ b/test/algorithm_example.cpp @@ -15,8 +15,8 @@ # pragma warn -8057 // unused argument argc/argv in Boost.Test #endif -#include -#include +#include +#include #include #include #include @@ -24,38 +24,45 @@ namespace { - template< typename ExternalRange, typename T > - inline typename boost::iterator_of::type - find( ExternalRange& c, const T& value ) - { + + // + // example: extrating bounds in a generic algorithm + // + template< typename Range, typename T > + inline typename boost::iterator_of::type + find( Range& c, const T& value ) + { return std::find( boost::begin( c ), boost::end( c ), value ); - } - - template< typename ExternalRange, typename T > - inline typename boost::const_iterator_of::type - find( const ExternalRange& c, const T& value ) - { + } + + template< typename Range, typename T > + inline typename boost::const_iterator_of::type + find( const Range& c, const T& value ) + { return std::find( boost::begin( c ), boost::end( c ), value ); - } + } - // - // replace first value and return its index - // - template< class XRange, class T > - inline typename boost::size_type_of< XRange >::type - my_generic_replace( XRange& c, const T& value, const T& replacement ) - { - typename boost::iterator_of::type found = find( c, value ); + // + // replace first value and return its index + // + template< class Range, class T > + inline typename boost::size_type_of< Range >::type + my_generic_replace( Range& c, const T& value, const T& replacement ) + { + typename boost::iterator_of::type found = find( c, value ); if( found != boost::end( c ) ) *found = replacement; return std::distance( boost::begin( c ), found ); - } + } } int main() { + // + // usage + // const int N = 5; std::vector my_vector; int values[] = { 1,2,3,4,5,6,7,8,9 }; diff --git a/test/iterator_pair.cpp b/test/iterator_pair.cpp index 3d11dba..11928a2 100755 --- a/test/iterator_pair.cpp +++ b/test/iterator_pair.cpp @@ -16,7 +16,7 @@ #endif #include -#include +#include #include #include #include diff --git a/test/std_container.cpp b/test/std_container.cpp index fc37568..836fe02 100755 --- a/test/std_container.cpp +++ b/test/std_container.cpp @@ -17,7 +17,7 @@ #endif #include -#include +#include #include #include #include diff --git a/test/string.cpp b/test/string.cpp index 650bf57..7f4c3dc 100755 --- a/test/string.cpp +++ b/test/string.cpp @@ -17,7 +17,7 @@ #endif #include -#include +#include #include #include #include