indirect_iterator_generator and std::distance ambiguity
I'm having problems compiling the code below with boost_1_30_2 and VC71 complaining about: ...\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(489) : error C2665: 'std::_Distance2' : none of the 4 overloads can convert parameter 4 from type 'std::iterator_traits<_Iter>::iterator_category' with [ _Iter=CDictionary::tVarConstItr ] ... Replacing with std::distance( lBeg.base(), lItr.base() ) does compile and work properly. Am I missing something in the typedef of tVarConstItr that would allow direct usage? ---------------------------------------------------------- class CDictionary { ... class VarSpec { ... typedef boost::shared_ptr<VarSpec> tPtr; }; typedef VarSpec tVar; typedef tVar::tPtr tVarPtr; typedef std::vector<tVarPtr> tVars; typedef boost::indirect_iterator_generator < tVars::const_iterator , tVar , tVar& , tVar* , std::iterator_traits<tVars::const_iterator> ::iterator_category
::type tVarConstItr;
typedef boost::indirect_iterator_generator < tVars::iterator , tVar , tVar& , tVar* , std::iterator_traits<tVars::iterator> ::iterator_category
::type tVarItr;
tGroups Groups()const{ return mGroups; } tVarItr VarBegin() { return tVarItr ( mVars.begin() ); } tVarItr VarEnd () { return tVarItr ( mVars.end () ); } tVarConstItr VarBegin()const{ return tVarConstItr( mVars.begin() ); } tVarConstItr VarEnd ()const{ return tVarConstItr( mVars.end () ); } }; usage: ------ int CDictionaryEditorView::Idx( const TCHAR* aChrPtr, bool aExact )const { boost::function1<bool,const CDictionary::VarSpec&> lFindFnc; if( aExact ) { lFindFnc = boost::bind( std::equal_to<std::string>() , std::string(aChrPtr) , boost::bind( &CDictionary::VarSpec::Name, _1 ) ); } else { //... } CDictionary::tVarConstItr lBeg = mDctPtr->VarBegin(); CDictionary::tVarConstItr lEnd = mDctPtr->VarEnd (); CDictionary::tVarConstItr lItr = std::find_if( lBeg, lEnd, lFindFnc ); return (lItr!=lEnd)? std::distance( lBeg, lItr ) : -1; } -- Jeff Flinn Applied Dynamics, International
"Jeff Flinn" <TriumphSprint2000@hotmail.com> writes:
I'm having problems compiling the code below with boost_1_30_2 and VC71 complaining about:
...\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(489) : error C2665: 'std::_Distance2' : none of the 4 overloads can convert parameter 4 from type 'std::iterator_traits<_Iter>::iterator_category' with [ _Iter=CDictionary::tVarConstItr ] ...
Replacing with std::distance( lBeg.base(), lItr.base() ) does compile and work properly. Am I missing something in the typedef of tVarConstItr that would allow direct usage?
No, you've got the order of the parameters to indirect_iterator_generator wrong. I suggest you let the library defaults take effect instead. typedef boost::indirect_iterator_generator < tVars::const_iterator , tVar const
::type tVarConstItr;
typedef boost::indirect_iterator_generator < tVars::const_iterator , tVar ::iterator_category
::type tVarItr;
But you'll have a bigger problem. IIRC the version of iterator adaptors in 1.30.2 doesn't support indirect iterators over shared_ptr. Go ahead and try it, but if you have trouble you may want to switch to the (much easier-to-use) version of the library in the CVS, which explicitly *does* support that usage.
----------------------------------------------------------
class CDictionary { ...
class VarSpec { ... typedef boost::shared_ptr<VarSpec> tPtr; };
typedef VarSpec tVar; typedef tVar::tPtr tVarPtr; typedef std::vector<tVarPtr> tVars;
typedef boost::indirect_iterator_generator < tVars::const_iterator , tVar , tVar& , tVar* , std::iterator_traits<tVars::const_iterator> ::iterator_category
::type tVarConstItr;
typedef boost::indirect_iterator_generator < tVars::iterator , tVar , tVar& , tVar* , std::iterator_traits<tVars::iterator> ::iterator_category
::type tVarItr;
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Dave, "David Abrahams" <dave@boost-consulting.com> wrote in message > "Jeff Flinn" <TriumphSprint2000@hotmail.com> writes:
I'm having problems compiling the code below with boost_1_30_2 and VC71 complaining about:
...\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(489) : error C2665: 'std::_Distance2' : none of the 4 overloads can convert parameter 4 from type 'std::iterator_traits<_Iter>::iterator_category' with [ _Iter=CDictionary::tVarConstItr ] ...
Replacing with std::distance( lBeg.base(), lItr.base() ) does compile
work properly. Am I missing something in the typedef of tVarConstItr
and that
would allow direct usage?
No, you've got the order of the parameters to indirect_iterator_generator wrong.
Thanks for spotting that. I entered them in the order listed in the Template Parameters table rather than in the order specified in the Synopsis in the documentation.
I suggest you let the library defaults take effect instead.
typedef boost::indirect_iterator_generator < tVars::const_iterator , tVar const
::type tVarConstItr;
typedef boost::indirect_iterator_generator < tVars::const_iterator , tVar ::iterator_category
::type tVarItr;
But you'll have a bigger problem. IIRC the version of iterator adaptors in 1.30.2 doesn't support indirect iterators over shared_ptr. Go ahead and try it, but if you have trouble you may want to switch to the (much easier-to-use) version of the library in the CVS, which explicitly *does* support that usage.
Explicitly specifying all template parameters is what allows 1.30.2 to work with shared_ptr's. I'm far from smart enough to figure this out on my own, and took this tack based on one of your responses that I found doing a search on relevant topics. I gather that the new iterator adaptors will not have these issues. Will they be in 1.31.0 recently brought up by Beman? Thanks again, -- Jeff Flinn Applied Dynamics, International
"Jeff Flinn" <TriumphSprint2000@hotmail.com> writes:
Dave,
"David Abrahams" <dave@boost-consulting.com> wrote in message > "Jeff Flinn" <TriumphSprint2000@hotmail.com> writes:
I'm having problems compiling the code below with boost_1_30_2 and VC71 complaining about:
...\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(489) : error C2665: 'std::_Distance2' : none of the 4 overloads can convert parameter 4 from type 'std::iterator_traits<_Iter>::iterator_category' with [ _Iter=CDictionary::tVarConstItr ] ...
Replacing with std::distance( lBeg.base(), lItr.base() ) does compile
work properly. Am I missing something in the typedef of tVarConstItr
and that
would allow direct usage?
No, you've got the order of the parameters to indirect_iterator_generator wrong.
Thanks for spotting that. I entered them in the order listed in the Template Parameters table rather than in the order specified in the Synopsis in the documentation.
I suggest you let the library defaults take effect instead.
typedef boost::indirect_iterator_generator < tVars::const_iterator , tVar const
::type tVarConstItr;
typedef boost::indirect_iterator_generator < tVars::const_iterator , tVar ::iterator_category
::type tVarItr;
But you'll have a bigger problem. IIRC the version of iterator adaptors in 1.30.2 doesn't support indirect iterators over shared_ptr. Go ahead and try it, but if you have trouble you may want to switch to the (much easier-to-use) version of the library in the CVS, which explicitly *does* support that usage.
Explicitly specifying all template parameters is what allows 1.30.2 to work with shared_ptr's. I'm far from smart enough to figure this out on my own, and took this tack based on one of your responses that I found doing a search on relevant topics.
I gather that the new iterator adaptors will not have these issues. Will they be in 1.31.0 recently brought up by Beman?
Absolutely. You can preview them at http://www.boost-consulting.com/boost/libs/iterator/doc -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Jeff Flinn