www.digitalmars.com         C & C++   DMDScript  

c++.stlsoft - WINSTL basic_findfile_sequence has no iterator typedef

reply Gabor.Fischer systecs.com (Gabor Fischer) writes:
Hello!


The basic_findfile_sequence in winstl has no iterator type defined, only a  
const_iterator. I noticed that when I tried to use it with BOOST_FOREACH,  
which requires an iterator type.




So Long...

Gabor
Jul 13 2007
parent reply Matthew Wilson <no-one nowhere.no.com> writes:
Gabor Fischer Wrote:

 Hello!
 
 
 The basic_findfile_sequence in winstl has no iterator type defined, only a  
 const_iterator. I noticed that when I tried to use it with BOOST_FOREACH,  
 which requires an iterator type.
That's by design. A collection that represents a file-system cannot be mutating. The problem is with BOOST_FOREACH. I don't know how it's implemented, but it clearly makes an invalid assumption - namely, that an STL collection must be mutating. What it should be doing is to use IIA (Inferred Interface Adaptation) to deduce the mutability of the collection, and using the appropriate iterator member type. Cheers Matt
Jul 13 2007
parent Gabor.Fischer systecs.com (Gabor Fischer) writes:
Hello Matthew!

 Hello!


 The basic_findfile_sequence in winstl has no iterator type defined, only a
 const_iterator. I noticed that when I tried to use it with BOOST_FOREACH,
 which requires an iterator type.
 That's by design. A collection that represents a file-system cannot be
 mutating.
Makes sense.
 The problem is with BOOST_FOREACH. I don't know how it's implemented, but it
 clearly makes an invalid assumption - namely, that an STL collection must be
 mutating. What it should be doing is to use IIA (Inferred Interface
 Adaptation) to deduce the mutability of the collection, and using the
 appropriate iterator member type.
I have researched a bit more about BOOST_FOREACH and found out how to adapt it so that it can be used with findfile_sequence. One has to add following template specialisation: namespace boost { // specialize range_iterator in namespace boost template<typename C, typename T> struct range_iterator<winstl::basic_findfile_sequence<C, T> > { typedef typename winstl::basic_findfile_sequence<C, T>::const_iterator type; }; } That's all, and BOOST_FOREACH can be used to iterate over files. I have only tested it with VC++ 2005. So Long... Gabor
Jul 18 2007