![]() |
|
Five types of objects are currently supported by the library:
std::pair<iterator,iterator>
char[]
,wchar_t[]
,
char*
, and wchar_t*
)
boost::array<>
anyway). Also note
that arrays and pointers of char
or whar_t
are
treated special because of their use in string algorithms.
The concept is defined by the metafunction and the functions below. Even
though these functions are defined in namespace boost
, there is no
such general requirement, that is, if one wants to extend the list of supported
types, it can be done in any namespace.
namespace boost { // // Range metafunctions // template< class T > struct value_type_of { typedef ... type; // type of stored objTts }; template< class T > struct iterator_of { typedef ... type; // iterator over stored objects }; template< class T > struct const_iterator_of { typedef ... type; // iterator over immutable stored objects }; template< class T > struct difference_type_of { typedef ... type; BOOST_STATIC_ASSERT( boost::is_signed< type >::value ); // // remark: if std::iterator_traits<> works for the type, this assertion must hold // BOOST_STATIC_ASSERT( boost::is_same< type, std::iterator_traits< typename iterator_of< T >::type >::difference_type>::value ); }; template< class T > struct size_type_of { typedef ... type; BOOST_STATIC_ASSERT( boost::is_unsigned< type >::value ); BOOST_STATIC_ASSERT( sizeof( type ) >= sizeof( difference_type_of< T >::type ) ); }; template< class T > struct result_iterator_of { typedef ... type; // iterator_of< T >::type if T is non-const, const_iterator_of< T >::type otherwise }; // // funtions // template< class T > inline typename iterator_of::type begin( T& c ); template< class T > inline typename const_iterator_of< T >::type begin( const T& c ); template< class T > inline typename iterator_of< T >::type end( T& c ); template< class T > inline typename const_iterator_of< T >::type end( const T& c ); template< class T > inline bool empty( const T& c ); template< class T > inline typename size_type_of< T >::type size( const T& c ); } // namespace 'boost'
In the table C
is a type that conforms to the
ExternalCollectionConcept and c
is an object of that type.
SC
will denote a standard container, T[sz]
will denote an array of
type T
of size sz
, P
will denote
std::pair<>
,
I
means an iterator which default construction denotes the end of
the range and sc,t,p,i
are objects of these types, respectively.
Special cases for char*
and wchar_t*
are described
explicitly.
Please note that char*
,whar_t*
,char[]
,
and wchar_t[]
behaves differently from normal arrays only for
size()
and end()
. Note that the null pointer is allowed as an argument
in these cases.
Some examples are given in the accompanying test files:
iterator.cpp
std::copy()
that
works with std::ifstream_iterator<>.
string.cpp
std::find()
that
works with char[],wchar_t[],char*,wchar_t*.
algorithm_example.cpp
(C) Copyright Thorsten Ottosen 2003-2004