I have some code like this
forAllIter(PtrDictionary<phaseModel>, fluid.phases(), iter)
{
PtrDictionary<phaseModel>& PtrDict = fluid.phases();
int IteratorPosition = std::distance(PtrDict.begin(), iter);
}
where 'forAllIter' is a macro with the general structure
#define forAllIter(Container,container,iter) \
441 for \
442 ( \
443 Container::iterator iter = (container).begin(); \
444 iter != (container).end(); \
445 ++iter \
446 )
Unfortunately, when compiling my code I get the error
error: no matching function for call to ‘distance(Foam::DLListBase::const_iterator, Foam::LPtrList<Foam::DLListBase, Foam::phaseModel>::iterator&)’
I guess the problem is that the iterators are of different types? Has someone a solution or an idea to fix this problem?
Edit: Code of Class PtrDictionary :
namespace Foam
48 {
49
50 /*---------------------------------------------------------------------------*\
51 Class PtrDictionary Declaration
52 \*---------------------------------------------------------------------------*/
53
54 template<class T>
55 class PtrDictionary
56 :
57 public DictionaryBase<DLPtrList<T>, T>
58 {
59
60 public:
61
62 // Constructors
63
64 //- Construct given initial table size
65 PtrDictionary(const label size = 128);
66
67 //- Copy construct
68 PtrDictionary(const PtrDictionary&);
69
70 //- Construct from Istream using given Istream constructor class
71 template<class INew>
72 PtrDictionary(Istream&, const INew&);
73
74 //- Construct from Istream
75 PtrDictionary(Istream&);
76 };
77
78
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80
81 } // End namespace Foam
82
83 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
84
85 #ifdef NoRepository
86 # include "PtrDictionary.C"
87 #endif
88
89 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
90
91 #endif
Edit2:
method begin():
template<class T>
363 inline typename Foam::PtrList<T>::iterator Foam::PtrList<T>::begin()
364 {
365 return ptrs_.begin();
366 }
iterator constructor (hope this is the right one):
iterator(LListBase_iterator baseIter)
192 :
193 LList<LListBase, T*>::iterator(baseIter)
194 {}
greetings streight