*** empty log message ***

[SVN r24384]
This commit is contained in:
Thorsten Jørgen Ottosen
2004-08-10 16:05:53 +00:00
parent e245cc6a7e
commit 0dbf587323
9 changed files with 119 additions and 151 deletions

View File

@ -30,7 +30,7 @@ namespace range
{ {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// default // primary template
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
template< typename C > template< typename C >
@ -106,7 +106,28 @@ namespace range
} // namespace 'range' } // namespace 'range'
template< class T >
inline BOOST_DEDUCED_TYPENAME iterator_of<T>::type begin( T& r )
{
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
using range::begin; using range::begin;
return begin( r );
#else
return range::begin( r );
#endif
}
template< class T >
inline BOOST_DEDUCED_TYPENAME const_iterator_of<T>::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 } // namespace boost

View File

@ -27,8 +27,9 @@ namespace boost
{ {
namespace range namespace range
{ {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// default // primary template
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
template< typename C > template< typename C >
@ -53,7 +54,16 @@ namespace range
} // namespace 'range' } // namespace 'range'
template< class T >
inline bool empty( const T& r )
{
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
using range::empty; using range::empty;
return empty( r );
#else
return range::empty( r );
#endif
}
} // namepace 'boost' } // namepace 'boost'

View File

@ -31,7 +31,7 @@ namespace range
{ {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// default // primary template
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
template< typename C > template< typename C >
@ -106,7 +106,27 @@ namespace range
} // namespace 'range' } // namespace 'range'
template< class T >
inline BOOST_DEDUCED_TYPENAME iterator_of<T>::type end( T& r )
{
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
using range::end; using range::end;
return end( r );
#else
return range::end( r );
#endif
}
template< class T >
inline BOOST_DEDUCED_TYPENAME const_iterator_of<T>::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' } // namespace 'boost'

View File

@ -92,16 +92,16 @@ namespace boost {
iterator_range( Range& r ) : iterator_range( Range& r ) :
m_Begin( begin_impl( r ) ), m_End( end_impl( r ) ) {} m_Begin( begin_impl( r ) ), m_End( end_impl( r ) ) {}
template< class XRange > template< class ForwardRange >
iterator_range& operator=( XRange& r ) iterator_range& operator=( ForwardRange& r )
{ {
m_Begin = begin_impl( r ); m_Begin = begin_impl( r );
m_End = end_impl( r ); m_End = end_impl( r );
return *this; return *this;
} }
template< class XRange > template< class ForwardRange >
iterator_range& operator=( const XRange& r ) iterator_range& operator=( const ForwardRange& r )
{ {
m_Begin = begin_impl( r ); m_Begin = begin_impl( r );
m_End = end_impl( r ); m_End = end_impl( r );
@ -140,16 +140,6 @@ namespace boost {
return m_Begin == m_End; 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 //! Safe bool conversion
/*! /*!
Check whenever the range is empty. Check whenever the range is empty.
@ -168,30 +158,32 @@ namespace boost {
return empty() ? 0: &iterator_range::end; return empty() ? 0: &iterator_range::end;
} }
/*
inline operator t_type() const
{
return make_tuple( m_Begin, m_End );
}*/
private: private:
// begin and end iterators // begin and end iterators
IteratorT m_Begin; IteratorT m_Begin;
IteratorT m_End; IteratorT m_End;
private: private:
template< class XRange > template< class ForwardRange >
iterator end_impl( XRange& r ) const iterator end_impl( ForwardRange& r ) const
{ {
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
using boost::end; using boost::end;
return end( r ); return end( r );
#else
return boost::end( r );
#endif
} }
template< class XRange > template< class ForwardRange >
iterator begin_impl( XRange& r ) const iterator begin_impl( ForwardRange& r ) const
{ {
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
using boost::begin; using boost::begin;
return begin( r ); 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 Construct an \c iterator_range from a \c Range containing the begin
and end iterators. and end iterators.
*/ */
template< class XRange > template< class ForwardRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME iterator_of<XRange>::type > inline iterator_range< BOOST_DEDUCED_TYPENAME iterator_of<ForwardRange>::type >
make_iterator_range( XRange& r ) make_iterator_range( ForwardRange& r )
{ {
return iterator_range< BOOST_DEDUCED_TYPENAME iterator_of<XRange>::type > return iterator_range< BOOST_DEDUCED_TYPENAME iterator_of<ForwardRange>::type >
( r ); ( r );
} }
template< class XRange > template< class ForwardRange >
inline iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of<XRange>::type > inline iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of<ForwardRange>::type >
make_iterator_range( const XRange& r ) make_iterator_range( const ForwardRange& r )
{ {
return iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of<XRange>::type > return iterator_range< BOOST_DEDUCED_TYPENAME const_iterator_of<ForwardRange>::type >
( r ); ( r );
} }
#endif #endif

View File

@ -1,88 +1,6 @@
1. ok. I should add something about extending the lib + how to rely on ADL. 16. change header types.hpp to metafunctions.hpp
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."
5. new intro: 17. post-review question: should Range mean lowest common denominator? or
"When writing generic code that works with Standard Library perhaps Forward Range? problem with not being explicit.
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 18) change use of types.hpp -> metefunctions.hpp
> | 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 <A
href="http://www.boost.org/more/generic_programming.html#type_generator">type
generators</A> 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<class container> struct widget {
typedef result_iterator_of<container> 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!

View File

@ -16,7 +16,7 @@
#endif #endif
#include <boost/range/functions.hpp > #include <boost/range/functions.hpp >
#include <boost/range/types.hpp> #include <boost/range/metafunctions.hpp>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
@ -24,16 +24,20 @@
namespace namespace
{ {
template< typename ExternalRange, typename T >
inline typename boost::iterator_of<ExternalRange>::type //
find( ExternalRange& c, const T& value ) // example: extrating bounds in a generic algorithm
//
template< typename Range, typename T >
inline typename boost::iterator_of<Range>::type
find( Range& c, const T& value )
{ {
return std::find( boost::begin( c ), boost::end( c ), value ); return std::find( boost::begin( c ), boost::end( c ), value );
} }
template< typename ExternalRange, typename T > template< typename Range, typename T >
inline typename boost::const_iterator_of<ExternalRange>::type inline typename boost::const_iterator_of<Range>::type
find( const ExternalRange& c, const T& value ) find( const Range& c, const T& value )
{ {
return std::find( boost::begin( c ), boost::end( c ), value ); return std::find( boost::begin( c ), boost::end( c ), value );
} }
@ -41,11 +45,11 @@ namespace
// //
// replace first value and return its index // replace first value and return its index
// //
template< class XRange, class T > template< class Range, class T >
inline typename boost::size_type_of< XRange >::type inline typename boost::size_type_of< Range >::type
my_generic_replace( XRange& c, const T& value, const T& replacement ) my_generic_replace( Range& c, const T& value, const T& replacement )
{ {
typename boost::iterator_of<XRange>::type found = find( c, value ); typename boost::iterator_of<Range>::type found = find( c, value );
if( found != boost::end( c ) ) if( found != boost::end( c ) )
*found = replacement; *found = replacement;
@ -56,6 +60,9 @@ namespace
int main() int main()
{ {
//
// usage
//
const int N = 5; const int N = 5;
std::vector<int> my_vector; std::vector<int> my_vector;
int values[] = { 1,2,3,4,5,6,7,8,9 }; int values[] = { 1,2,3,4,5,6,7,8,9 };

View File

@ -16,7 +16,7 @@
#endif #endif
#include <boost/range/functions.hpp> #include <boost/range/functions.hpp>
#include <boost/range/types.hpp> #include <boost/range/metafunctions.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>

View File

@ -17,7 +17,7 @@
#endif #endif
#include <boost/range/functions.hpp> #include <boost/range/functions.hpp>
#include <boost/range/types.hpp> #include <boost/range/metafunctions.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>

View File

@ -17,7 +17,7 @@
#endif #endif
#include <boost/range/functions.hpp> #include <boost/range/functions.hpp>
#include <boost/range/types.hpp> #include <boost/range/metafunctions.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits.hpp> #include <boost/type_traits.hpp>
#include <boost/test/test_tools.hpp> #include <boost/test/test_tools.hpp>