![]() |
|
Five types of objects are currently supported by the library:
char[]
,wchar_t[]
,
char*
, and wchar_t*
)
std::pair<iterator,iterator>
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 type-generators 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 { // // type generators // template< typename EC > struct value_type_of { typedef ... type; // type of stored objects }; template< typename EC > struct iterator_of { typedef ... type; // iterator over stored objects }; template< typename EC > struct const_iterator_of { typedef ... type; // iterator over immutable stored objects }; template< typename EC > 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< EC >::type >::difference_type>::value ); }; template< typename EC > struct size_type_of { typedef ... type; BOOST_STATIC_ASSERT( boost::is_unsigned< type >::value ); BOOST_STATIC_ASSERT( sizeof( type ) >= sizeof( difference_type_of< EC >::type ) ); }; template< typename EC > struct result_iterator_of { typedef ... type; // iterator_of< EC >::type if EC is non-const, const_iterator_of< EC >::type otherwise }; // // funtions // template< typename EC > inline typename iterator_of::type begin( EC& c ); template< typename EC > inline typename const_iterator_of< EC >::type begin( const EC& c ); template< typename EC > inline typename iterator_of< EC >::type end( EC& c ); template< typename EC > inline typename const_iterator_of< EC >::type end( const EC& c ); template< typename EC > inline bool empty( const EC& c ); template< typename EC > inline typename size_type_of< EC >::type size( const EC& 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